ModuleNew.vue 2.2 KB

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