app.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. <ui-dialog v-else>
  43. <template v-slot:header>
  44. <span>用户登录</span>
  45. </template>
  46. <div>
  47. <ui-input
  48. type="text"
  49. placeholder="请输入账号"
  50. v-model="username"
  51. style="width: 360px"
  52. />
  53. <br />
  54. <ui-input
  55. type="password"
  56. placeholder="请输入密码"
  57. v-model="password"
  58. style="width: 360px; margin-top: 20px"
  59. />
  60. <br />
  61. <ui-input
  62. type="checkbox"
  63. @click.stop
  64. label="记住密码"
  65. style="margin-top: 20px"
  66. :modelValue="mark"
  67. @update:modelValue="(select: any) => mark = select"
  68. />
  69. <!-- <ui-input
  70. type="checkbox"
  71. label="记住密码"
  72. v-model="mark"
  73. style="margin-top: 20px"
  74. /> -->
  75. </div>
  76. <template v-slot:footer>
  77. <ui-button type="submit" @click="login(username, password)">登录</ui-button>
  78. </template>
  79. </ui-dialog>
  80. </template>
  81. <script lang="ts" setup>
  82. import { custom, params } from "@/env";
  83. import { computed, ref, watch, watchEffect, nextTick } from "vue";
  84. import {
  85. isEdit,
  86. prefix,
  87. appEl,
  88. initialSetting,
  89. caseProject,
  90. refreshCase,
  91. fuseModels,
  92. scenes,
  93. } from "@/store";
  94. import router, { currentLayout, RoutesName } from "./router";
  95. import { asyncTimeout, encodePwd, loadPack, needMounts } from "@/utils";
  96. import { ConfigProvider } from "ant-design-vue";
  97. import PwdModel from "@/layout/pwd.vue";
  98. import { config } from "./config";
  99. import { sdk, sdkLoaded } from "./sdk";
  100. import GAxios from "axios";
  101. import { addReqErrorHandler, addResErrorHandler, ResCode, setToken } from "./api";
  102. const gotoLogin = () => {
  103. if (import.meta.env.DEV) {
  104. login("super-admin", "Aa123456");
  105. } else {
  106. showLogin.value = true;
  107. }
  108. };
  109. addResErrorHandler((data: any) => {
  110. data = data.data;
  111. if (data.code === ResCode.TOKEN_INVALID) {
  112. gotoLogin();
  113. } else if (data.code === ResCode.UN_AUTH) {
  114. gotoLogin();
  115. }
  116. });
  117. addReqErrorHandler(gotoLogin);
  118. // https://192.168.0.13:7173/index.html?caseId=509&sign=vGxCu4X5321fkWpZN6HnqYBiE6iI71DDWzdgjEaUKIh7vDWo3o5yhqHdHhGr4Z3W#/show
  119. const isStandard = ref(true);
  120. watchEffect(() => {
  121. if (sdkLoaded.value && !params.testMap) {
  122. // sdk.switchMapType(isStandard.value ? "satellite" : "standard");
  123. }
  124. });
  125. const loaded = ref(false);
  126. const inputPwd = ref(false);
  127. const stopWatch = watch(
  128. currentLayout,
  129. async (layout) => {
  130. if (!layout) {
  131. return;
  132. } else if (layout === RoutesName.signModel || layout === RoutesName.error) {
  133. loaded.value = true;
  134. return;
  135. }
  136. // 单页面 非自己查看需要密码校验
  137. // if (currentLayout.value === RoutesName.show && !params.share) {
  138. // inputPwd.value = true;
  139. // await new Promise<void>((resolve) => {
  140. // const stopInputWatch = watchEffect(() => {
  141. // if (!inputPwd.value) {
  142. // stopInputWatch();
  143. // resolve();
  144. // }
  145. // });
  146. // });
  147. // }
  148. params.share = true;
  149. await asyncTimeout(100);
  150. await refreshCase();
  151. if (caseProject.value) {
  152. await loadPack(initialSetting);
  153. } else {
  154. await router.replace({ name: RoutesName.error });
  155. }
  156. stopWatch();
  157. loaded.value = true;
  158. },
  159. { immediate: true }
  160. );
  161. watchEffect(() => {
  162. prefix.value = caseProject.value?.fusionTitle || "多元融合";
  163. });
  164. const layoutClassNames = computed(() => {
  165. return {
  166. [`sys-view-${custom.viewMode}`]: true,
  167. "edit-mode": isEdit.value || custom.showToolbar,
  168. "setting-mode": custom.showToolbar,
  169. "hide-right-box-mode": !custom.showRightPano,
  170. "hide-left-box-mode": !custom.showLeftPano,
  171. "show-bottom-box-mode": custom.showBottomBar,
  172. "hide-top-bar-mode": !custom.showHeadBar,
  173. };
  174. });
  175. const layoutStyles = computed(() => {
  176. const styles: { [key in string]: string } = {};
  177. if (custom.showBottomBar) {
  178. styles["--editor-menu-bottom"] = custom.bottomBarHeight;
  179. }
  180. return styles;
  181. });
  182. const showLogin = ref(false);
  183. const username = ref(localStorage.getItem("fuse-username") || "");
  184. const password = ref(localStorage.getItem("fuse-password") || "");
  185. const mark = ref(!!localStorage.getItem("fuse-mark"));
  186. const login = (username: string, password: string) => {
  187. GAxios.post("/service/manage/login", {
  188. password: encodePwd(password),
  189. userName: username,
  190. username: username,
  191. }).then((res) => {
  192. setToken(res.data.data.token);
  193. setTimeout(() => {
  194. const p = new URLSearchParams(location.search);
  195. p.delete("token");
  196. location.search = "?" + p.toString();
  197. }, 100);
  198. loaded.value = false;
  199. if (mark.value) {
  200. localStorage.setItem("fuse-username", username);
  201. localStorage.setItem("fuse-password", password);
  202. localStorage.setItem("fuse-mark", "1");
  203. } else {
  204. localStorage.removeItem("fuse-username");
  205. localStorage.removeItem("fuse-password");
  206. localStorage.removeItem("fuse-mark");
  207. }
  208. });
  209. };
  210. </script>
  211. <style scoped lang="scss">
  212. .editor-layout {
  213. --editor-menu-bottom: 0px;
  214. background: #000;
  215. --left-pano-left: calc(var(--editor-menu-left) + var(--editor-menu-width));
  216. }
  217. .sys-view-full {
  218. --header-top: var(--hide-header-top);
  219. --editor-menu-right: calc(-1 * var(--editor-toolbox-width)) !important;
  220. --editor-menu-left: calc(-1 * var(--editor-menu-width));
  221. --search-left: 52px;
  222. }
  223. .sys-view-auto {
  224. --header-top: var(--show-header-top);
  225. --search-left: 0px;
  226. }
  227. .hide-top-bar-mode {
  228. --header-top: var(--hide-header-top);
  229. }
  230. .hide-right-box-mode {
  231. --editor-menu-right: calc(-1 * var(--editor-toolbox-width)) !important;
  232. }
  233. .hide-left-box-mode {
  234. --left-pano-left: calc(
  235. var(--editor-menu-left) + var(--editor-menu-width) - var(--left-pano-width)
  236. ) !important;
  237. }
  238. .edit-mode {
  239. --editor-menu-left: calc(-1 * var(--editor-menu-width));
  240. }
  241. .laser-layer {
  242. position: absolute;
  243. z-index: 1;
  244. inset: 0;
  245. .scene {
  246. width: 100%;
  247. height: 100%;
  248. background-color: #ccc;
  249. }
  250. }
  251. .taggle {
  252. position: absolute;
  253. font-size: 16px;
  254. color: #fff;
  255. background: rgba(0, 0, 0, 0.2);
  256. z-index: 9999999;
  257. width: 30px;
  258. height: 30px;
  259. display: flex;
  260. align-items: center;
  261. overflow: hidden;
  262. justify-content: center;
  263. border-radius: 3px;
  264. cursor: pointer;
  265. &.map-type {
  266. transition: all 0.3s ease;
  267. top: calc(var(--header-top) + var(--editor-head-height) + 10px);
  268. right: calc(var(--editor-toolbox-width) + var(--editor-menu-right) + 30px);
  269. width: 42px;
  270. height: 42px;
  271. img {
  272. width: 100%;
  273. height: 100%;
  274. object-fit: cover;
  275. }
  276. }
  277. }
  278. </style>