|
@@ -8,56 +8,56 @@
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts">
|
|
|
-import { defineComponent, ref, watchEffect, computed, watch, nextTick } from 'vue'
|
|
|
-import { SceneType } from '@/store'
|
|
|
-import { params } from '@/env'
|
|
|
-import { fuseModel, modelProps } from './index'
|
|
|
-import { modelSDKFactory } from './platform'
|
|
|
+import { defineComponent, ref, watchEffect, computed, watch, nextTick } from "vue";
|
|
|
+import { SceneType } from "@/store";
|
|
|
+import { params } from "@/env";
|
|
|
+import { fuseModel, modelProps } from "./index";
|
|
|
+import { modelSDKFactory } from "./platform";
|
|
|
|
|
|
const typeChange = () => {
|
|
|
- const oldType = modelProps.type
|
|
|
- let stopWatch = null as unknown as () => void
|
|
|
+ const oldType = modelProps.type;
|
|
|
+ let stopWatch = (null as unknown) as () => void;
|
|
|
|
|
|
const typePromise = new Promise((_, reject) => {
|
|
|
stopWatch = watchEffect(() => {
|
|
|
if (modelProps.type !== oldType) {
|
|
|
- reject(new Error('当前模型未加载完已切换到下个'))
|
|
|
- stopWatch!()
|
|
|
+ reject(new Error("当前模型未加载完已切换到下个"));
|
|
|
+ stopWatch!();
|
|
|
}
|
|
|
- })
|
|
|
- })
|
|
|
- return { typePromise, typeCleanup: stopWatch }
|
|
|
-}
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return { typePromise, typeCleanup: stopWatch };
|
|
|
+};
|
|
|
|
|
|
export const Model = defineComponent({
|
|
|
- name: 'model',
|
|
|
+ name: "model",
|
|
|
setup() {
|
|
|
- const scene = computed(() => modelProps.type !== fuseModel && modelProps.type)
|
|
|
- const url = ref("")
|
|
|
+ const scene = computed(() => modelProps.type !== fuseModel && modelProps.type);
|
|
|
+ const url = ref("");
|
|
|
const setUrl = (newURL: string) => {
|
|
|
if (newURL !== url.value) {
|
|
|
setTimeout(() => {
|
|
|
- const hook = (iframeRef.value?.contentWindow as any)?.beforeDestroy
|
|
|
+ const hook = (iframeRef.value?.contentWindow as any)?.beforeDestroy;
|
|
|
if (hook) {
|
|
|
try {
|
|
|
- hook()
|
|
|
- } catch(e) {
|
|
|
- console.error(e)
|
|
|
+ hook();
|
|
|
+ } catch (e) {
|
|
|
+ console.error(e);
|
|
|
}
|
|
|
- url.value = ""
|
|
|
- setTimeout(() => url.value = newURL, 300)
|
|
|
+ url.value = "";
|
|
|
+ setTimeout(() => (url.value = newURL), 300);
|
|
|
} else {
|
|
|
- url.value = newURL
|
|
|
+ url.value = newURL;
|
|
|
}
|
|
|
- })
|
|
|
+ });
|
|
|
}
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
watchEffect(() => {
|
|
|
if (!scene.value) {
|
|
|
return setUrl("");
|
|
|
}
|
|
|
- const type = scene.value.type
|
|
|
+ const type = scene.value.type;
|
|
|
const urls = {
|
|
|
[SceneType.SWKK]: `/swkk/spg.html?m=${scene.value.num}`,
|
|
|
[SceneType.SWKJ]: `/swkk/spg.html?m=${scene.value.num}`,
|
|
@@ -66,14 +66,12 @@ export const Model = defineComponent({
|
|
|
[SceneType.SWMX]: `index.html?caseId=${params.caseId}&app=${params.app}&modelId=${scene.value.num}&share=1#sign-model`,
|
|
|
[SceneType.SWYDSS]: `/swss/index.html?m=${scene.value.num}`,
|
|
|
[SceneType.SWYDMX]: `/swkk/spg.html?m=${scene.value.num}`,
|
|
|
- }
|
|
|
- setUrl(urls[type])
|
|
|
- })
|
|
|
-
|
|
|
-
|
|
|
+ };
|
|
|
+ setUrl(urls[type]);
|
|
|
+ });
|
|
|
|
|
|
- const fuseRef = ref<HTMLDivElement>()
|
|
|
- const iframeRef = ref<HTMLIFrameElement>()
|
|
|
+ const fuseRef = ref<HTMLDivElement>();
|
|
|
+ const iframeRef = ref<HTMLIFrameElement>();
|
|
|
|
|
|
watch(
|
|
|
() => [modelProps.type, url.value],
|
|
@@ -81,47 +79,51 @@ export const Model = defineComponent({
|
|
|
if (type !== fuseModel && !url) {
|
|
|
return;
|
|
|
}
|
|
|
- const callback = modelProps.callback
|
|
|
-
|
|
|
- await nextTick()
|
|
|
- const { typePromise, typeCleanup } = typeChange()
|
|
|
- const modelPromise = modelSDKFactory(type as any, type === fuseModel ? fuseRef.value! : iframeRef.value!)
|
|
|
- let result: any = null, error = null
|
|
|
+ const callback = modelProps.callback;
|
|
|
+
|
|
|
+ await nextTick();
|
|
|
+ const { typePromise, typeCleanup } = typeChange();
|
|
|
+ const modelPromise = modelSDKFactory(
|
|
|
+ type as any,
|
|
|
+ type === fuseModel ? fuseRef.value! : iframeRef.value!
|
|
|
+ );
|
|
|
+ let result: any = null,
|
|
|
+ error = null;
|
|
|
try {
|
|
|
- result = await Promise.race([typePromise, modelPromise])
|
|
|
+ result = await Promise.race([typePromise, modelPromise]);
|
|
|
} catch (err: any) {
|
|
|
- error = err
|
|
|
+ error = err;
|
|
|
}
|
|
|
- typeCleanup()
|
|
|
- callback && callback(result, error)
|
|
|
- },
|
|
|
- { immediate: true, flush: 'post' }
|
|
|
- )
|
|
|
+ typeCleanup();
|
|
|
+ callback && callback(result, error);
|
|
|
+ },
|
|
|
+ { immediate: true, flush: "post" }
|
|
|
+ );
|
|
|
|
|
|
// 处理iframe 定制页面
|
|
|
watch(
|
|
|
- () => [scene.value && scene.value.type, url.value],
|
|
|
+ () => [scene.value && scene.value.type, url.value],
|
|
|
([type], oldType, onCleanup) => {
|
|
|
if (type === false) {
|
|
|
// 手动渲染融合场景
|
|
|
console.log("手动渲染!");
|
|
|
setTimeout(() => {
|
|
|
- (window as any).viewer.setDisplay(true)
|
|
|
- }, 100)
|
|
|
- };
|
|
|
+ (window as any).viewer.setDisplay(true);
|
|
|
+ }, 100);
|
|
|
+ }
|
|
|
|
|
|
const interval = setInterval(async () => {
|
|
|
- let doc: Document | undefined
|
|
|
+ let doc: Document | undefined;
|
|
|
try {
|
|
|
- doc = iframeRef.value?.contentWindow?.document!
|
|
|
+ doc = iframeRef.value?.contentWindow?.document!;
|
|
|
} catch {
|
|
|
clearInterval(interval);
|
|
|
}
|
|
|
if (!doc || !doc.querySelector("div")) return;
|
|
|
- console.error(doc, doc.head)
|
|
|
- const target = doc.head
|
|
|
+ console.error(doc, doc.head);
|
|
|
+ const target = doc.head;
|
|
|
clearInterval(interval);
|
|
|
- ;(window as any).iframeCreated && (window as any).iframeCreated(iframeRef.value);
|
|
|
+ (window as any).iframeCreated && (window as any).iframeCreated(iframeRef.value);
|
|
|
if (type === SceneType.SWSS) {
|
|
|
const $style = document.createElement("style");
|
|
|
$style.type = "text/css";
|
|
@@ -135,19 +137,19 @@ export const Model = defineComponent({
|
|
|
}
|
|
|
}, 16);
|
|
|
onCleanup(() => clearInterval(interval));
|
|
|
- },
|
|
|
- {flush: 'post', immediate: true}
|
|
|
- )
|
|
|
+ },
|
|
|
+ { flush: "post", immediate: true }
|
|
|
+ );
|
|
|
|
|
|
return {
|
|
|
iframeRef,
|
|
|
fuseRef,
|
|
|
- url
|
|
|
- }
|
|
|
- }
|
|
|
-})
|
|
|
+ url,
|
|
|
+ };
|
|
|
+ },
|
|
|
+});
|
|
|
|
|
|
-export default Model
|
|
|
+export default Model;
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="scss">
|
|
@@ -180,6 +182,6 @@ export default Model
|
|
|
right: calc(var(--editor-menu-right) + var(--editor-toolbox-width)) !important;
|
|
|
top: calc(var(--header-top) + var(--editor-head-height)) !important;
|
|
|
margin: 10px;
|
|
|
- transition: top .3s ease, right .3s ease;
|
|
|
+ transition: top 0.3s ease, right 0.3s ease;
|
|
|
}
|
|
|
</style>
|