ModuleWarnMonitor.vue 2.1 KB

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