Browse Source

[Wip 0000] 开发支持预览远程文件的CAD预览器

ruienger 3 months ago
parent
commit
9cfad93cea

+ 0 - 0
src/views/vent/performance/fileDetail/commen/CADViewer.vue → src/views/vent/cad/TestViewer.vue


+ 0 - 10
src/views/vent/cad/index.vue

@@ -1,10 +0,0 @@
-<!-- eslint-disable vue/multi-word-component-names -->
-<template>
-  <CADViewer class="w-100% h-100%" show-operations :height="820" />
-</template>
-
-<script setup lang="ts">
-  import { CADViewer } from '/@/components/CADViewer';
-</script>
-
-<style lang="less" scoped></style>

+ 1 - 1
src/views/vent/monitorManager/dedustMonitor/index.vue

@@ -147,7 +147,7 @@
   }
 
   async function getSysDataSource() {
-    const res = await getTableList({ strtype: 'sys_dedustfan_normal', pagetype: 'normal' });
+    const res = await getTableList({ strtype: 'dedustfan_normal', pagetype: 'normal' });
     if (!options.value && res) {
       // 初始时选择第一条数据
       options.value = res.records || [];

+ 1 - 1
src/views/vent/performance/comment/CADModal.vue

@@ -33,7 +33,7 @@
   import { ref } from 'vue';
   import { BasicModal, useModalInner } from '/@/components/Modal';
   import { onMounted } from 'vue';
-  import CADViewer from '/@/views/vent/performance/fileDetail/commen/CADViewer.vue';
+  import CADViewer from './CADViewer.vue';
   // import { useGlobSetting } from '/@/hooks/setting';
   // import { useAutoLogin } from '/@/hooks/vent/useAutoLogin';
   // import { MOCK_LOGIN_UESRNAME } from '/@/store/constant';

+ 64 - 0
src/views/vent/performance/comment/CADViewer.vue

@@ -0,0 +1,64 @@
+<template>
+  <!-- 更适用于文件共享中心的CAD viewer组件,支持两种使用方法,详见下文 -->
+  <CADViewer class="w-100% h-100%" :height="height" />
+</template>
+<script lang="ts" setup>
+  import { onMounted, onUnmounted } from 'vue';
+  import { CADViewer, useCADViewer } from '/@/components/CADViewer';
+  import { useRoute } from 'vue-router';
+
+  const props = defineProps<{
+    // 文件共享中心中该文件的ID
+    id: string;
+    // 文件名
+    filename?: string;
+    height: number;
+  }>();
+
+  const { processFile, postMessage, registHook, unregistHook } = useCADViewer();
+
+  function openFile(id: string) {
+    // 只触发一次,因为MKY_Open_Mxweb之后会自动触发MKY_Open_File_Complete钩子,导致循环
+    registHook('MKY_Open_File_Complete', () => {
+      unregistHook('MKY_Open_File_Complete');
+      processFile(id).then((path) => {
+        postMessage('MKY_Open_Mxweb', path);
+      });
+    });
+  }
+
+  // watch(
+  //   () => props.id,
+  //   (v) => {
+  //     if (!v) return;
+  //     openFile(v, props.filename);
+  //   }
+  // );
+
+  // let initByRoute = false;
+
+  onMounted(() => {
+    const route = useRoute();
+    if (route.query.id && route.query.filename) {
+      // initByRoute = true;
+      // 通过 url query 指定文件 ID 的形式使用该组件
+      openFile(route.query.id as string);
+    } else {
+      // 通过 props 指定文件 ID 的形式使用该组件
+      openFile(props.id);
+    }
+  });
+
+  onUnmounted(() => {
+    unregistHook('MKY_Open_File_Complete');
+  });
+</script>
+
+<style scoped lang="less">
+  ::v-deep .suffix {
+    height: 32px;
+    line-height: 32px;
+    margin-left: 5px;
+    color: #fff;
+  }
+</style>