ModuleOriginal.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 ModuleRight from './original/moduleRight.vue';
  23. import ModuleBottom from './original/moduleBottom.vue';
  24. import { computed, ref } from 'vue';
  25. import { openWindow } from '/@/utils';
  26. import { getFormattedText } from '../hooks/helper';
  27. // import { ModuleProps } from '../types';
  28. const props = defineProps<{
  29. /** 配置的详细模块信息 */
  30. moduleData: any;
  31. /** 配置的详细样式信息 */
  32. showStyle: any;
  33. /** 该模块配置中的设备标识符 */
  34. deviceType: string;
  35. /** api返回的数据 */
  36. data: any;
  37. moduleName: string;
  38. visible: boolean;
  39. }>();
  40. defineEmits(['close', 'click']);
  41. const { header } = props.moduleData;
  42. const selectedData = ref();
  43. const style = computed(() => {
  44. const size = props.showStyle.size;
  45. const position = props.showStyle.position;
  46. return size + position;
  47. });
  48. // 根据配置里的定位判断应该使用哪个module组件
  49. function getModuleComponent({ size, position }) {
  50. const [_, width] = size.match(/width:([0-9]+)px/) || [];
  51. if (position.includes('bottom') || parseInt(width) > 800) {
  52. return ModuleBottom;
  53. }
  54. if (position.includes('left')) {
  55. return ModuleLeft;
  56. }
  57. if (position.includes('right')) {
  58. return ModuleRight;
  59. }
  60. return ModuleBottom;
  61. }
  62. function redirectTo() {
  63. const { to } = props.moduleData;
  64. if (!to) return;
  65. openWindow(getFormattedText(selectedData.value, to));
  66. }
  67. </script>