ModuleFireNewTop.vue 2.5 KB

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