CADViewer.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <!-- 更适用于文件共享中心的CAD viewer组件,支持两种使用方法,详见下文 -->
  3. <CADViewer class="w-100% h-100%" :height="height" />
  4. </template>
  5. <script lang="ts" setup>
  6. import { onMounted, 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 } = useCADViewer();
  19. function openFile(id: string, filename: string) {
  20. const loading = message.loading('正在下载文件', 0);
  21. downLoad({ id }).then((res: Blob) => {
  22. processFile(new File([res], filename))
  23. .then((path) => {
  24. postMessage('MKY_Open_Mxweb', path);
  25. })
  26. .finally(() => {
  27. loading();
  28. });
  29. });
  30. }
  31. watch(
  32. () => props.id,
  33. (v) => {
  34. if (!v) return;
  35. openFile(v, props.filename);
  36. }
  37. );
  38. onMounted(() => {
  39. postMessage('MKY_Open_Mxweb', window.location.origin + '/mxcad/test31.mxweb');
  40. const route = useRoute();
  41. if (route.query.id && route.query.filename) {
  42. // 通过 url query 指定文件 ID 的形式使用该组件
  43. openFile(route.query.id as string, route.query.filename as string);
  44. } else {
  45. // 通过 props 指定文件 ID 的形式使用该组件
  46. openFile(props.id, props.filename);
  47. }
  48. });
  49. </script>
  50. <style scoped lang="less">
  51. ::v-deep .suffix {
  52. height: 32px;
  53. line-height: 32px;
  54. margin-left: 5px;
  55. color: #fff;
  56. }
  57. </style>