index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <template>
  2. <header v-if="props.showAdjust">
  3. <div v-if="project">{{ project.projectName }}</div>
  4. <div class="sync">
  5. <button @click="onCancel">取消</button>
  6. <button type="submit" @click="onSubmit" :class="{ active: points.p1 && points.p2 }">同步</button>
  7. </div>
  8. </header>
  9. <header v-else>
  10. <div v-if="project">{{ project.projectName }}</div>
  11. <div class="user">
  12. <ul>
  13. <li>
  14. <i @click="showLink=true;showCopyDone=false" class="iconfont icon-share"></i>
  15. </li>
  16. <li><em></em></li>
  17. <li v-if="user" class="uinfo" @click="showDrop = true">
  18. <img :src="user.head + '&x-oss-process=image/resize,m_fill,w_64,h_64/quality,q_70'" alt="" />
  19. <div class="menu">
  20. <ul>
  21. <li><a href="/smarts">个人信息</a></li>
  22. <li class="split"></li>
  23. <li><a href="javascript:;" @click="onLogout">退出登录</a></li>
  24. </ul>
  25. </div>
  26. </li>
  27. <li v-else class="login" @click="showLogin = true"><span>登录</span></li>
  28. </ul>
  29. </div>
  30. </header>
  31. <footer v-if="props.showAdjust">
  32. <h4>为场景设置关联位置</h4>
  33. <div>请选择位置,确认左右视图中的场景在同一位置后,单击右侧按钮将其设为关联位置。</div>
  34. <div class="points">
  35. <button @click="onSetP1" :class="{ active: points.p1 }">设为P1</button>
  36. <button @click="onSetP2" :class="{ active: points.p2 }">设为P2</button>
  37. </div>
  38. </footer>
  39. <Toast v-if="showCopyDone" content="复制成功" />
  40. <Login v-if="showLogin" @close="showLogin = false" @user="info => (user = info)" />
  41. <CopyLink v-if="showLink" @close="showLink=false" @done="showCopyDone=true;showLink=false" />
  42. </template>
  43. <script setup>
  44. import { ref, defineProps, onMounted, watchEffect } from 'vue'
  45. import { http } from '@/utils/request'
  46. import browser from '@/utils/browser'
  47. import Toast from '@/components/dialog/Toast'
  48. import Login from './Login'
  49. import CopyLink from './CopyLink'
  50. import sync from '@/utils/sync'
  51. const props = defineProps({
  52. project: Object,
  53. showAdjust: Boolean,
  54. })
  55. const emits = defineEmits(['update'])
  56. const user = ref(null)
  57. const points = ref({ p1: null, p2: null })
  58. const showLink = ref(false)
  59. const showLogin = ref(false)
  60. const showCopyDone = ref(false)
  61. const getCurPosInfo = () => {
  62. let app = sync.sourceInst
  63. let id
  64. if (app.sceneType == 'laser') {
  65. id = app.viewer.images360.currentPano.id
  66. } else {
  67. id = app.app.core.get('Player').currentPano.id
  68. }
  69. let info = sync.targetInst.viewer.getCameraStatus()
  70. let position = info.position
  71. return { id, position }
  72. }
  73. const onSetP1 = () => {
  74. points.value.p1 = getCurPosInfo()
  75. console.log(points.value.p1)
  76. emits('update', 'p1',points.value.p1)
  77. }
  78. const onSetP2 = () => {
  79. points.value.p2 = getCurPosInfo()
  80. console.log(points.value.p2)
  81. emits('update', 'p2',points.value.p2)
  82. }
  83. const getUserInfo = () => {
  84. http.post(`smart-site/getUserInfo`)
  85. .then(response => {
  86. if (response.success) {
  87. user.value = {
  88. head: response.data.head,
  89. nickName: response.data.nickName,
  90. }
  91. } else {
  92. if (response.code == 4008) {
  93. // 未登录
  94. }
  95. }
  96. })
  97. .catch(() => {})
  98. }
  99. const onLogout = () => [
  100. http
  101. .post(`smart-site/fdLogout`)
  102. .then(response => {
  103. if (response.success) {
  104. localStorage.removeItem('token')
  105. localStorage.removeItem('remember')
  106. localStorage.removeItem('username')
  107. localStorage.removeItem('password')
  108. user.value = null
  109. }
  110. })
  111. .catch(() => {}),
  112. ]
  113. const onCancel = () => {
  114. window.location.href = window.location.href.replace('&adjust', '')
  115. }
  116. const onSubmit = () => {
  117. http.post(`smart-site/project/updatePanos`, {
  118. projectId: props.project.projectId,
  119. panos: JSON.stringify(points.value),
  120. })
  121. .then(response => {
  122. if (response.success) {
  123. window.location.href = window.location.href.replace('&adjust', '&split')
  124. } else if(response.code == 4008) {
  125. showLogin.value = true
  126. } else {
  127. alert(response.message)
  128. }
  129. })
  130. .catch(() => {
  131. alert('链接服务器失败')
  132. })
  133. }
  134. watchEffect(() => {
  135. if (props.showAdjust) {
  136. if (props.project && props.project.panos) {
  137. points.value.p1 = props.project.panos.p1
  138. points.value.p2 = props.project.panos.p2
  139. }
  140. }
  141. })
  142. onMounted(() => {
  143. if (localStorage.getItem('token')) {
  144. getUserInfo()
  145. }
  146. })
  147. </script>
  148. <style lang="scss" scoped>
  149. ul,
  150. li {
  151. margin: 0;
  152. padding: 0;
  153. list-style: none;
  154. }
  155. header {
  156. position: relative;
  157. height: 60px;
  158. background-color: #1a1b1d;
  159. display: flex;
  160. justify-content: center;
  161. align-items: center;
  162. font-size: 16px;
  163. }
  164. footer {
  165. position: absolute;
  166. left: 0;
  167. bottom: 0;
  168. width: 100%;
  169. height: 92px;
  170. color: rgba(255, 255, 255, 0.8);
  171. backdrop-filter: blur(4px);
  172. background: rgba(27, 27, 28, 0.8);
  173. z-index: 99999;
  174. padding: 20px 24px;
  175. h4 {
  176. font-size: 20px;
  177. margin: 0;
  178. padding: 0;
  179. color: #fff;
  180. margin-bottom: 14px;
  181. }
  182. .points {
  183. position: absolute;
  184. top: 20px;
  185. right: 0;
  186. bottom: 20px;
  187. display: flex;
  188. align-items: center;
  189. button {
  190. cursor: pointer;
  191. outline: none;
  192. color: #0076f6;
  193. margin-right: 24px;
  194. width: 160px;
  195. height: 36px;
  196. background: transparent;
  197. border: 1px solid #0076f6;
  198. border-radius: 4px;
  199. &.active {
  200. background: #0076f6;
  201. color: #fff;
  202. }
  203. }
  204. }
  205. }
  206. .user {
  207. position: absolute;
  208. top: 0;
  209. right: 20px;
  210. bottom: 0;
  211. display: flex;
  212. align-items: center;
  213. justify-content: center;
  214. font-size: 14px;
  215. ul {
  216. display: flex;
  217. align-items: center;
  218. justify-content: center;
  219. }
  220. i {
  221. font-size: 18px;
  222. cursor:pointer;
  223. }
  224. em {
  225. margin: 0 20px;
  226. display: inline-block;
  227. width: 1px;
  228. height: 16px;
  229. vertical-align: -2px;
  230. background-color: rgba(255, 255, 255, 0.16);
  231. }
  232. .login {
  233. cursor: pointer;
  234. color: rgba(0, 118, 246, 1);
  235. }
  236. .uinfo {
  237. position: relative;
  238. display: flex;
  239. align-items: center;
  240. justify-content: center;
  241. width: 40px;
  242. height: 40px;
  243. font-size: 14px;
  244. &::after {
  245. content: '';
  246. position: absolute;
  247. right: 3px;
  248. bottom: 4px;
  249. width: 0;
  250. height: 0;
  251. border-color: rgba(255, 255, 255, 0.6) transparent;
  252. border-width: 0 0 5px 5px;
  253. border-style: solid;
  254. }
  255. &:hover {
  256. .menu {
  257. display: block;
  258. }
  259. }
  260. img {
  261. width: 32px;
  262. height: 32px;
  263. border-radius: 50%;
  264. background-size: cover;
  265. border: none;
  266. outline: none;
  267. overflow: hidden;
  268. cursor: pointer;
  269. }
  270. .menu {
  271. display: none;
  272. position: absolute;
  273. top: 40px;
  274. right: 0;
  275. z-index: 2000;
  276. a {
  277. color: #fff;
  278. text-decoration: none;
  279. }
  280. ul {
  281. background-color: #343535;
  282. width: 128px;
  283. flex-direction: column;
  284. border-radius: 4px;
  285. box-shadow: 0 0 4px #333;
  286. padding: 0 15px;
  287. margin-top: 15px;
  288. }
  289. li {
  290. height: 45px;
  291. line-height: 45px;
  292. text-align: center;
  293. &.split {
  294. width: 100%;
  295. height: 1px;
  296. background-color: rgba(255, 255, 255, 0.16);
  297. }
  298. }
  299. }
  300. }
  301. }
  302. .sync {
  303. position: absolute;
  304. right: 0;
  305. top: 0;
  306. height: 100%;
  307. display: flex;
  308. align-items: center;
  309. button {
  310. cursor: pointer;
  311. width: 90px;
  312. height: 35px;
  313. background: #313131;
  314. color: #fff;
  315. border: none;
  316. outline: none;
  317. border-radius: 4px;
  318. margin-right: 10px;
  319. &[type='submit'] {
  320. background: #0076f6;
  321. opacity: 0.5;
  322. pointer-events: none;
  323. }
  324. &[type='submit'].active {
  325. opacity: 1;
  326. pointer-events: all;
  327. }
  328. }
  329. }
  330. </style>