CADViewer.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <!-- 更适用于文件共享中心的CAD viewer组件,支持两种使用方法,详见下文 -->
  3. <CADViewer class="w-100% h-100%" :height="height" />
  4. </template>
  5. <script lang="ts" setup>
  6. import { onMounted, onUnmounted } from 'vue';
  7. import { CADViewer, useCADViewer } from '/@/components/CADViewer';
  8. import { useRoute } from 'vue-router';
  9. const props = defineProps<{
  10. // 文件共享中心中该文件的ID
  11. id: string;
  12. // 文件名
  13. filename?: string;
  14. height: number;
  15. }>();
  16. const { processFile, postMessage, registHook, unregistHook } = useCADViewer();
  17. function openFile(id: string) {
  18. // 只触发一次,因为MKY_Open_Mxweb之后会自动触发MKY_Open_File_Complete钩子,导致循环
  19. registHook('MKY_Open_File_Complete', () => {
  20. unregistHook('MKY_Open_File_Complete');
  21. processFile(id).then((path) => {
  22. postMessage('MKY_Open_Mxweb', path);
  23. });
  24. });
  25. }
  26. // watch(
  27. // () => props.id,
  28. // (v) => {
  29. // if (!v) return;
  30. // openFile(v, props.filename);
  31. // }
  32. // );
  33. // let initByRoute = false;
  34. onMounted(() => {
  35. const route = useRoute();
  36. if (route.query.id && route.query.filename) {
  37. // initByRoute = true;
  38. // 通过 url query 指定文件 ID 的形式使用该组件
  39. openFile(route.query.id as string);
  40. } else {
  41. // 通过 props 指定文件 ID 的形式使用该组件
  42. openFile(props.id);
  43. }
  44. });
  45. onUnmounted(() => {
  46. unregistHook('MKY_Open_File_Complete');
  47. });
  48. </script>
  49. <style scoped lang="less">
  50. ::v-deep .suffix {
  51. height: 32px;
  52. line-height: 32px;
  53. margin-left: 5px;
  54. color: #fff;
  55. }
  56. </style>