app.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <ConfigProvider v-bind="config" v-if="!showLogin">
  3. <template v-for="needMount in needMounts">
  4. <Teleport :to="needMount[0]">
  5. <component
  6. :is="needMount[1]"
  7. v-bind="needMount[2]"
  8. :ref="(v: any) => needMount[3] && needMount[3](v)"
  9. />
  10. </Teleport>
  11. </template>
  12. <ui-editor-layout
  13. @click.stop
  14. @contextmenu.prevent
  15. id="layout-app"
  16. class="editor-layout"
  17. :style="layoutStyles"
  18. :class="layoutClassNames"
  19. >
  20. <div
  21. :ref="(el: any) => appEl = (el as HTMLDivElement)"
  22. v-if="loaded"
  23. class="app-con"
  24. >
  25. <router-view v-slot="{ Component }">
  26. <!-- <keep-alive> -->
  27. <component :is="Component" />
  28. <!-- </keep-alive> -->
  29. </router-view>
  30. </div>
  31. <!-- <span
  32. v-if="fuseModels.length > 0 || scenes.length === 0"
  33. class="taggle map-type"
  34. @click="isStandard = !isStandard"
  35. @touchend="isStandard = !isStandard"
  36. >
  37. <img :src="isStandard ? 'images/satellite.jpg' : 'images/standard.jpg'" />
  38. </span> -->
  39. </ui-editor-layout>
  40. <PwdModel v-if="inputPwd" @close="inputPwd = false" />
  41. </ConfigProvider>
  42. <Login v-else />
  43. </template>
  44. <script lang="ts" setup>
  45. import {
  46. custom,
  47. params,
  48. showLeftPanoStack,
  49. showRightCtrlPanoStack,
  50. showRightPanoStack,
  51. } from "@/env";
  52. import { computed, ref, watch, watchEffect, nextTick } from "vue";
  53. import {
  54. isEdit,
  55. prefix,
  56. appEl,
  57. initialSetting,
  58. caseProject,
  59. refreshCase,
  60. fuseModels,
  61. scenes,
  62. } from "@/store";
  63. import router, { currentLayout, RoutesName } from "./router";
  64. import { asyncTimeout, encodePwd, loadPack, needMounts } from "@/utils";
  65. import { ConfigProvider } from "ant-design-vue";
  66. import PwdModel from "@/layout/pwd.vue";
  67. import { config } from "./config";
  68. import { sdk, sdkLoaded } from "./sdk";
  69. import GAxios from "axios";
  70. import { addReqErrorHandler, addResErrorHandler, ResCode, setToken } from "./api";
  71. import { mergeFuns } from "./components/drawing/hook";
  72. import Login from "./views/login.vue";
  73. import { ui18n } from "./lang";
  74. const gotoLogin = () => {
  75. showLogin.value = true;
  76. };
  77. addResErrorHandler((data: any) => {
  78. data = data.data;
  79. if (data.code === ResCode.TOKEN_INVALID) {
  80. gotoLogin();
  81. } else if (data.code === ResCode.UN_AUTH) {
  82. // console.log("--->");
  83. gotoLogin();
  84. } else if (data.code === ResCode.UN_EDIT_AUTH) {
  85. router.replace(RoutesName.show);
  86. }
  87. });
  88. addReqErrorHandler(gotoLogin);
  89. // https://192.168.0.13:7173/index.html?caseId=509&sign=vGxCu4X5321fkWpZN6HnqYBiE6iI71DDWzdgjEaUKIh7vDWo3o5yhqHdHhGr4Z3W#/show
  90. const isStandard = ref(true);
  91. watchEffect(() => {
  92. if (sdkLoaded.value) {
  93. const checkUrl = `https://www.google.com/maps/vt/pb=!1m5!1m4!1i11!2i3339!3i1787!4i128!2m2!1e1!3i998!3m9!2szh-CN!3s!5e1105!12m1!1e4!12m1!1e47!12m1!1e3!4e0!5m1!1e0!23i1368782!23i1368785!23i4861626!23i10211310!23i4897086!23i47054629!23i72385654!23i72458815!23i10211069!23i94243289!23i94255677!23i10210500!23i94222679!23i72860224!23i10211515!23i94260020`;
  94. // Promise.race([
  95. // new Promise((_, reject) => {
  96. // if (params.ga === "true") {
  97. // reject("ga版本");
  98. // }
  99. // }),
  100. // fetch(checkUrl).then((res) => {
  101. // if (res.status !== 200) {
  102. // throw "谷歌访问不了";
  103. // } else {
  104. // return res.status;
  105. // }
  106. // }),
  107. // new Promise((r, j) => setTimeout(j, 3000)),
  108. // ])
  109. // .then(() => {
  110. // console.error("使用gmap");
  111. // sdk.switchMapType(isStandard.value ? "satellite" : "standard", "gmap");
  112. // })
  113. // .catch(() => {
  114. // console.error("使用amap");
  115. // sdk.switchMapType(isStandard.value ? "satellite" : "standard", "amap");
  116. // });
  117. }
  118. });
  119. const loaded = ref(false);
  120. const inputPwd = ref(false);
  121. const stopWatch = watch(
  122. currentLayout,
  123. async (layout) => {
  124. if (!layout) {
  125. return;
  126. } else if (layout === RoutesName.signModel || layout === RoutesName.error) {
  127. loaded.value = true;
  128. return;
  129. }
  130. // 单页面 非自己查看需要密码校验
  131. // if (currentLayout.value === RoutesName.show && !params.share) {
  132. // inputPwd.value = true;
  133. // await new Promise<void>((resolve) => {
  134. // const stopInputWatch = watchEffect(() => {
  135. // if (!inputPwd.value) {
  136. // stopInputWatch();
  137. // resolve();
  138. // }
  139. // });
  140. // });
  141. // }
  142. params.share = true;
  143. await asyncTimeout(100);
  144. await refreshCase();
  145. if (caseProject.value) {
  146. await loadPack(initialSetting);
  147. } else {
  148. await router.replace({ name: RoutesName.error });
  149. }
  150. stopWatch();
  151. loaded.value = true;
  152. },
  153. { immediate: true }
  154. );
  155. watchEffect(() => {
  156. prefix.value = caseProject.value?.fusionTitle || ui18n.t('fuse.name');
  157. });
  158. const layoutClassNames = computed(() => {
  159. return {
  160. [`sys-view-${custom.viewMode}`]: true,
  161. "edit-mode": isEdit.value || custom.showToolbar,
  162. "setting-mode": custom.showToolbar,
  163. "hide-right-box-mode": !custom.showRightPano,
  164. "hide-left-box-mode": !custom.showLeftPano,
  165. "full-view": custom.full,
  166. "show-bottom-box-mode": custom.showBottomBar,
  167. "hide-top-bar-mode": !custom.showHeadBar,
  168. };
  169. });
  170. const layoutStyles = computed(() => {
  171. const styles: { [key in string]: string } = {};
  172. if (custom.showBottomBar) {
  173. styles["--editor-menu-bottom"] = custom.bottomBarHeight;
  174. }
  175. return styles;
  176. });
  177. const showLogin = ref(false);
  178. watch(
  179. () => custom.full,
  180. (full, _, onCleanup) => {
  181. if (full) {
  182. onCleanup(
  183. mergeFuns(
  184. showRightPanoStack.push(ref(false)),
  185. showLeftPanoStack.push(ref(false)),
  186. showRightCtrlPanoStack.push(ref(false)),
  187. showRightCtrlPanoStack.push(ref(false))
  188. )
  189. );
  190. }
  191. }
  192. );
  193. </script>
  194. <style scoped lang="scss">
  195. .editor-layout {
  196. --editor-menu-bottom: 0px;
  197. background: #000;
  198. --left-pano-left: calc(var(--editor-menu-left) + var(--editor-menu-width));
  199. }
  200. .sys-view-full {
  201. --header-top: var(--hide-header-top);
  202. --editor-menu-right: calc(-1 * var(--editor-toolbox-width)) !important;
  203. --editor-menu-left: calc(-1 * var(--editor-menu-width));
  204. --search-left: 52px;
  205. }
  206. .sys-view-auto {
  207. --header-top: var(--show-header-top);
  208. --search-left: 0px;
  209. }
  210. .hide-top-bar-mode {
  211. --header-top: var(--hide-header-top);
  212. }
  213. .hide-right-box-mode {
  214. --editor-menu-right: calc(-1 * var(--editor-toolbox-width)) !important;
  215. }
  216. .hide-left-box-mode {
  217. --left-pano-left: calc(
  218. var(--editor-menu-left) + var(--editor-menu-width) - var(--left-pano-width)
  219. ) !important;
  220. }
  221. .edit-mode {
  222. --editor-menu-left: calc(-1 * var(--editor-menu-width));
  223. }
  224. .laser-layer {
  225. position: absolute;
  226. z-index: 1;
  227. inset: 0;
  228. .scene {
  229. width: 100%;
  230. height: 100%;
  231. background-color: #ccc;
  232. }
  233. }
  234. .taggle {
  235. position: absolute;
  236. font-size: 16px;
  237. color: #fff;
  238. background: rgba(0, 0, 0, 0.2);
  239. z-index: 9999999;
  240. width: 30px;
  241. height: 30px;
  242. display: flex;
  243. align-items: center;
  244. overflow: hidden;
  245. justify-content: center;
  246. border-radius: 3px;
  247. cursor: pointer;
  248. &.map-type {
  249. transition: all 0.3s ease;
  250. top: calc(var(--header-top) + var(--editor-head-height) + 10px);
  251. right: calc(var(--editor-toolbox-width) + var(--editor-menu-right) + 30px);
  252. width: 42px;
  253. height: 42px;
  254. img {
  255. width: 100%;
  256. height: 100%;
  257. object-fit: cover;
  258. }
  259. }
  260. }
  261. </style>
  262. <style lang="scss">
  263. .full-view #global-search {
  264. left: 20px !important;
  265. }
  266. </style>