ModuleOriginal-green.vue 2.3 KB

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