ModuleOriginal.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <!-- 原版模块 -->
  3. <component
  4. :is="getModuleComponent(showStyle)"
  5. :style="style"
  6. :title="moduleName"
  7. :visible="visible"
  8. :class="{ 'cursor-pointer': !!moduleData.to }"
  9. @close="$emit('close')"
  10. @click="redirectTo"
  11. >
  12. <slot>
  13. <Header :deviceType="deviceType" :moduleData="moduleData" :data="data" @select="selectedData = $event" />
  14. <Content :style="{ height: header.show ? 'calc(100% - 30px)' : '100%' }" :moduleData="moduleData" :data="selectedData" />
  15. </slot>
  16. </component>
  17. </template>
  18. <script lang="ts" setup>
  19. import Header from './header.vue';
  20. import Content from './content.vue';
  21. import ModuleLeft from './original/moduleLeft.vue';
  22. import ModuleBottom from './original/moduleBottom.vue';
  23. import { computed, ref } from 'vue';
  24. import { openWindow } from '/@/utils';
  25. // import { ModuleProps } from '../types';
  26. const props = defineProps<{
  27. /** 配置的详细模块信息 */
  28. moduleData: any;
  29. /** 配置的详细样式信息 */
  30. showStyle: any;
  31. /** 该模块配置中的设备标识符 */
  32. deviceType: string;
  33. /** api返回的数据 */
  34. data: any;
  35. moduleName: string;
  36. visible: boolean;
  37. }>();
  38. defineEmits(['close', 'click']);
  39. const { header } = props.moduleData;
  40. const selectedData = ref();
  41. const style = computed(() => {
  42. const size = props.showStyle.size;
  43. const position = props.showStyle.position;
  44. return size + position;
  45. });
  46. // 根据配置里的定位判断应该使用哪个module组件
  47. function getModuleComponent({ size, position }) {
  48. const [_, width] = size.match(/width:([0-9]+)px/) || [];
  49. if (position.includes('bottom') || parseInt(width) > 800) {
  50. return ModuleBottom;
  51. }
  52. if (position.includes('left')) {
  53. return ModuleLeft;
  54. }
  55. if (position.includes('right')) {
  56. return ModuleLeft;
  57. }
  58. return ModuleBottom;
  59. }
  60. function redirectTo() {
  61. const { to } = props.moduleData;
  62. if (!to) return;
  63. openWindow(to);
  64. }
  65. </script>