import { SDK } from "@/sdk"; import { watchEffect, watch, ref } from "vue"; import { Router } from "vue-router"; import { useCustom, useDisabled } from "./hook"; import { disabledMap, hotDisabledStack, mapDisabledStack, cloundDisabledStack, fullViewStack, spiltViewModeStack, magnifierModeStack, DisabledCom, CustomCom, customMap, CustomMapStack, } from "./preset"; // 全屏切换设置 const fullScreenSetting = (sdk: SDK) => { const disableSceneView = ref(false); const disableMiniView = ref(false); // 全屏切换 watch( () => fullViewStack.current.value.value, (newFull) => { if (newFull === "scene") { mapDisabledStack.current.value === disableMiniView && mapDisabledStack.pop(); cloundDisabledStack.push(disableSceneView); sdk.sceneFullShow(); } else { cloundDisabledStack.current.value === disableSceneView && cloundDisabledStack.pop(); mapDisabledStack.push(disableMiniView); sdk.mapFullShow(); } }, { flush: "sync" } ); }; // 分屏设置 const spliceSetting = (sdk: SDK) => { watch( () => spiltViewModeStack.current.value.value, (newSplice, oldSplice) => { if (newSplice !== null) { cloundDisabledStack.push(ref(false)); mapDisabledStack.push(ref(true)); hotDisabledStack.push(ref(true)); fullViewStack.push(ref("scene")); sdk.openSplitScreen(); sdk.setSplitScreenSize(newSplice); } else if (oldSplice) { cloundDisabledStack.pop(); mapDisabledStack.pop(); hotDisabledStack.pop(); fullViewStack.pop(); sdk.setSplitScreenSize(0.5); sdk.closeSplitScreen(); } } ); }; // 放大镜模式 const magnifierSetting = (sdk: SDK) => { watch( () => magnifierModeStack.current.value.value, (magnifierMode, oldVal) => { if (magnifierMode) { fullViewStack.push(ref("scene")); sdk.scene.openMagnifier(); } else if (oldVal) { sdk.scene.closeMagnifier(); fullViewStack.pop(); } } ); }; export const setupSDK = (sdk: SDK) => { // 基础设置 watchEffect(() => { sdk.changeScene(!disabledMap[DisabledCom.Clound]); }); watchEffect(() => sdk.scene.changeMode(customMap[CustomCom.LaserMode])); watchEffect(() => sdk.carry.setShowHots(!disabledMap[DisabledCom.Hot])); watchEffect(() => sdk.carry.setShowMeasures(!disabledMap[DisabledCom.Measure]) ); fullScreenSetting(sdk); spliceSetting(sdk); magnifierSetting(sdk); }; export type RouteCustomConfig = { [key in any]: { disabled?: DisabledCom[]; enabled?: DisabledCom[]; custom?: { [key in CustomCom]?: CustomMapStack[key]["current"]["value"]; }; }; }; export const setupRouteCustom = (router: Router, config: RouteCustomConfig) => { const pops = []; const setting = (name) => { const atom = config[name]; if (!atom) return; if (atom.custom) { Object.keys(atom.custom).forEach((key: CustomCom) => { pops.push(useCustom(key, atom.custom[key])); }); } if (atom.disabled) { pops.push(useDisabled(atom.disabled, ref(true))); } if (atom.enabled) { pops.push(useDisabled(atom.enabled, ref(false))); } }; router.beforeEach((to, _, next) => { while (pops.length) { pops.pop()(); } setting(to.name); next(); }); setting(router.currentRoute.value.name); };