CADViewer.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. const props = defineProps<{
  11. // 文件共享中心中该文件的ID
  12. id: string;
  13. // 文件名
  14. filename: string;
  15. height: number;
  16. }>();
  17. const { processFile, postMessage } = useCADViewer();
  18. function openFile(id: string, filename: string) {
  19. downLoad({ id }).then((res: Blob) => {
  20. processFile(new File([res], filename)).then((path) => {
  21. postMessage('MKY_Open_Mxweb', path);
  22. });
  23. });
  24. }
  25. // 通过 props 指定文件 ID 的形式使用该组件
  26. watch(
  27. () => props.id,
  28. (v) => {
  29. if (!v) return;
  30. openFile(v, props.filename);
  31. }
  32. );
  33. // 通过 url query 指定文件 ID 的形式使用该组件
  34. onMounted(() => {
  35. const route = useRoute();
  36. if (route.query.id && route.query.filename) {
  37. openFile(route.query.id as string, route.query.filename as string);
  38. }
  39. });
  40. </script>
  41. <style scoped lang="less">
  42. ::v-deep .suffix {
  43. height: 32px;
  44. line-height: 32px;
  45. margin-left: 5px;
  46. color: #fff;
  47. }
  48. </style>