ModuleGasInject.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <!-- 注气驱替 -->
  3. <component :is="getModuleComponent(showStyle)" :style="style" :title="moduleName" :visible="visible"
  4. :visibleDetail="visibleDetail" :class="{ 'cursor-pointer': !!moduleData.to }" @close="$emit('close')"
  5. @click="redirectTo" @handleClickDetail="handleClickDetail">
  6. <slot>
  7. <Header :deviceType="deviceType" :moduleData="moduleData" :data="data" @select="selectedData = $event" />
  8. <Content :style="{ height: header.show ? 'calc(100% - 30px)' : '100%' }" :moduleData="moduleData"
  9. :data="selectedData" />
  10. <DetailInfo v-if="showDetail" :deviceType="deviceType" @closeModal="closeModal"></DetailInfo>
  11. </slot>
  12. </component>
  13. </template>
  14. <script lang="ts" setup>
  15. import Header from './header.vue';
  16. import Content from './content.vue';
  17. import ModuleLeft from './gasInject/moduleLeft.vue';
  18. import ModuleRight from './gasInject/moduleRight.vue';
  19. import ModuleBottom from './gasInject/moduleBottom.vue';
  20. import DetailInfo from './gasInject/DetailInfo.vue'
  21. import { computed, ref } from 'vue';
  22. import { openWindow } from '/@/utils';
  23. import { getFormattedText } from '../hooks/helper';
  24. // import { ModuleProps } from '../types';
  25. const props = defineProps<{
  26. /** 配置的详细模块信息 */
  27. moduleData: any;
  28. /** 配置的详细样式信息 */
  29. showStyle: any;
  30. /** 该模块配置中的设备标识符 */
  31. deviceType: string;
  32. /** api返回的数据 */
  33. data: any;
  34. moduleName: string;
  35. visible: boolean;
  36. visibleDetail: boolean
  37. }>();
  38. defineEmits(['close', 'click']);
  39. const { header } = props.moduleData;
  40. const selectedData = ref();
  41. //是否显示详情信息
  42. const showDetail = ref(false)
  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. if (position.includes('bottom') || parseInt(width) > 800) {
  52. return ModuleBottom;
  53. }
  54. if (position.includes('left')) {
  55. return ModuleLeft;
  56. }
  57. if (position.includes('right')) {
  58. return ModuleRight;
  59. }
  60. return ModuleBottom;
  61. }
  62. function redirectTo() {
  63. const { to } = props.moduleData;
  64. if (!to) return;
  65. openWindow(getFormattedText(selectedData.value, to));
  66. }
  67. //详情点击
  68. function handleClickDetail() {
  69. showDetail.value = true
  70. }
  71. //关闭弹窗
  72. function closeModal(param) {
  73. showDetail.value = param
  74. }
  75. </script>