CADViewer.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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, watch } from 'vue';
  7. import { CADViewer, useCADViewer } from '/@/components/CADViewer';
  8. import { downLoad } from '../fileDetail.api';
  9. import { useRoute } from 'vue-router';
  10. import { message } from 'ant-design-vue';
  11. const props = defineProps<{
  12. // 文件共享中心中该文件的ID
  13. id: string;
  14. // 文件名
  15. filename: string;
  16. height: number;
  17. }>();
  18. const { processFile, postMessage, registHook, unregistHook } = useCADViewer();
  19. function openFile(id: string, filename: string) {
  20. // 只触发一次,因为MKY_Open_Mxweb之后会自动触发MKY_Open_File_Complete钩子,导致循环
  21. registHook('MKY_Open_File_Complete', () => {
  22. unregistHook('MKY_Open_File_Complete');
  23. const loading = message.loading('正在下载文件', 0);
  24. downLoad({ id }).then((res: Blob) => {
  25. processFile(new File([res], filename))
  26. .then((path) => {
  27. postMessage('MKY_Open_Mxweb', path);
  28. })
  29. .finally(() => {
  30. loading();
  31. });
  32. });
  33. });
  34. }
  35. // watch(
  36. // () => props.id,
  37. // (v) => {
  38. // if (!v) return;
  39. // openFile(v, props.filename);
  40. // }
  41. // );
  42. onMounted(() => {
  43. const route = useRoute();
  44. if (route.query.id && route.query.filename) {
  45. // 通过 url query 指定文件 ID 的形式使用该组件
  46. openFile(route.query.id as string, route.query.filename as string);
  47. } else {
  48. // 通过 props 指定文件 ID 的形式使用该组件
  49. openFile(props.id, props.filename);
  50. }
  51. });
  52. onUnmounted(() => {
  53. unregistHook('MKY_Open_File_Complete');
  54. });
  55. </script>
  56. <style scoped lang="less">
  57. ::v-deep .suffix {
  58. height: 32px;
  59. line-height: 32px;
  60. margin-left: 5px;
  61. color: #fff;
  62. }
  63. </style>