ModuleOriginal.vue 2.1 KB

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