CADViewer.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. console.log('debug watch');
  31. openFile(v, props.filename);
  32. }
  33. );
  34. // 通过 url query 指定文件 ID 的形式使用该组件
  35. onMounted(() => {
  36. const route = useRoute();
  37. if (route.query.id && route.query.filename) {
  38. openFile(route.query.id as string, route.query.filename as string);
  39. }
  40. });
  41. </script>
  42. <style scoped lang="less">
  43. ::v-deep .suffix {
  44. height: 32px;
  45. line-height: 32px;
  46. margin-left: 5px;
  47. color: #fff;
  48. }
  49. </style>