|
@@ -3,7 +3,7 @@
|
|
|
<CADViewer class="w-100% h-100%" :height="height" />
|
|
|
</template>
|
|
|
<script lang="ts" setup>
|
|
|
- import { onMounted, watch } from 'vue';
|
|
|
+ import { onMounted, onUnmounted, watch } from 'vue';
|
|
|
import { CADViewer, useCADViewer } from '/@/components/CADViewer';
|
|
|
import { downLoad } from '../fileDetail.api';
|
|
|
import { useRoute } from 'vue-router';
|
|
@@ -17,28 +17,32 @@
|
|
|
height: number;
|
|
|
}>();
|
|
|
|
|
|
- const { processFile, postMessage } = useCADViewer();
|
|
|
+ const { processFile, postMessage, registHook, unregistHook } = useCADViewer();
|
|
|
|
|
|
function openFile(id: string, filename: string) {
|
|
|
- const loading = message.loading('正在下载文件', 0);
|
|
|
- downLoad({ id }).then((res: Blob) => {
|
|
|
- processFile(new File([res], filename))
|
|
|
- .then((path) => {
|
|
|
- postMessage('MKY_Open_Mxweb', path);
|
|
|
- })
|
|
|
- .finally(() => {
|
|
|
- loading();
|
|
|
- });
|
|
|
+ // 只触发一次,因为MKY_Open_Mxweb之后会自动触发MKY_Open_File_Complete钩子,导致循环
|
|
|
+ registHook('MKY_Open_File_Complete', () => {
|
|
|
+ unregistHook('MKY_Open_File_Complete');
|
|
|
+ const loading = message.loading('正在下载文件', 0);
|
|
|
+ downLoad({ id }).then((res: Blob) => {
|
|
|
+ processFile(new File([res], filename))
|
|
|
+ .then((path) => {
|
|
|
+ postMessage('MKY_Open_Mxweb', path);
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ loading();
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- watch(
|
|
|
- () => props.id,
|
|
|
- (v) => {
|
|
|
- if (!v) return;
|
|
|
- openFile(v, props.filename);
|
|
|
- }
|
|
|
- );
|
|
|
+ // watch(
|
|
|
+ // () => props.id,
|
|
|
+ // (v) => {
|
|
|
+ // if (!v) return;
|
|
|
+ // openFile(v, props.filename);
|
|
|
+ // }
|
|
|
+ // );
|
|
|
|
|
|
onMounted(() => {
|
|
|
const route = useRoute();
|
|
@@ -50,6 +54,10 @@
|
|
|
openFile(props.id, props.filename);
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ onUnmounted(() => {
|
|
|
+ unregistHook('MKY_Open_File_Complete');
|
|
|
+ });
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="less">
|