index.vue 9.7 KB

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