ModuleDustNew.vue 2.1 KB

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