ModuleCommonBelt.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <!-- 常用模块 -->
  3. <Transition
  4. :enter-active-class="`animate__animated animate__fadeIn${capitalizedPosition}`"
  5. :leave-active-class="`animate__animated animate__fadeOut${capitalizedPosition}`"
  6. >
  7. <ventBox1 v-if="visible" :class="getModuleClass(showStyle)" :style="style" :pageType="pageType">
  8. <template v-if="moduleName" #title>
  9. <div :class="{ 'cursor-pointer': !!moduleData.to }" style="font-weight: bold; font-style: italic" @click="redirectTo">{{ moduleName }}</div>
  10. </template>
  11. <template #container>
  12. <slot>
  13. <Header :deviceType="deviceType" :moduleData="moduleData" :data="data" @select="selectedData = $event" />
  14. <Content
  15. :style="{ height: header.show ? 'calc(100% - 30px)' : '100%' }"
  16. :moduleData="moduleData"
  17. :data="selectedData"
  18. :chartData="chartData"
  19. />
  20. </slot>
  21. </template>
  22. </ventBox1>
  23. </Transition>
  24. </template>
  25. <script lang="ts" setup>
  26. import Header from './headerBelt.vue';
  27. // import Content from './contentBelt.vue';
  28. import Content from '../../components/content.vue';
  29. // import ModuleLeft from './original/moduleLeft.vue';
  30. // import ModuleBottom from './original/moduleBottom.vue';
  31. import { computed, ref, watch } from 'vue';
  32. import ventBox1 from './ventBoxBelt.vue';
  33. import { openWindow } from '/@/utils';
  34. import { getFormattedText } from '../../hooks/helper';
  35. import { useInitModule } from '../../hooks/useInit';
  36. // import { ModuleProps } from '../types';
  37. const props = defineProps<{
  38. pageType: string;
  39. /** 配置的详细模块信息 */
  40. moduleData: any;
  41. /** 配置的详细样式信息 */
  42. showStyle: any;
  43. /** 该模块配置中的设备标识符 */
  44. deviceType: string;
  45. /** api返回的数据 */
  46. data: any;
  47. moduleName: string;
  48. visible: boolean;
  49. chartData?: any;
  50. }>();
  51. defineEmits(['close', 'click']);
  52. const { header } = props.moduleData;
  53. const { selectedDeviceID, selectedDevice, options, init } = useInitModule(props.deviceType, props.moduleData);
  54. const selectedData = ref();
  55. const style = computed(() => {
  56. const size = props.showStyle.size;
  57. const position = props.showStyle.position;
  58. console.log(props.showStyle, '123123');
  59. return size + position + 'position: absolute; pointer-events: auto; z-index: 1';
  60. });
  61. const pageType = computed(() => {
  62. return props.pageType || '';
  63. });
  64. const capitalizedPosition = computed(() => {
  65. return props.showStyle.position.includes('left') ? 'Left' : 'Right';
  66. });
  67. // 根据配置里的定位判断应该使用哪个class
  68. function getModuleClass({ size, position }) {
  69. const [_, width] = size.match(/width:([0-9]+)px/) || [];
  70. if (position.includes('bottom') || parseInt(width) > 800) {
  71. return 'module-common module-common-longer';
  72. }
  73. return 'module-common';
  74. }
  75. function redirectTo() {
  76. const { to } = props.moduleData;
  77. if (!to) return;
  78. openWindow(getFormattedText(props.data, to));
  79. }
  80. watch(
  81. () => props.data,
  82. (d) => {
  83. init(d);
  84. if (!selectedDeviceID.value) {
  85. selectedDeviceID.value = options.value[0]?.value;
  86. }
  87. },
  88. {
  89. immediate: true,
  90. }
  91. );
  92. </script>
  93. <style lang="less" scoped>
  94. @import '/@/design/theme.less';
  95. .module-common .box1-center {
  96. height: calc(100% - 48px);
  97. }
  98. :deep(.box1-center) {
  99. height: calc(100% - 48px);
  100. }
  101. :deep(.box1-center > .box-container) {
  102. height: 100%;
  103. padding: 0 !important;
  104. width: 100% !important;
  105. }
  106. .module-common-longer {
  107. :deep(.box1-top) {
  108. --image-box1-top: url('/@/assets/images/beltFire/1-1.png');
  109. background-image: url('/@/assets/images/beltFire/1-1.png');
  110. }
  111. :deep(.box1-bottom) {
  112. --image-box1-bottom: url('/@/assets/images/beltFire/1-2.png');
  113. background-image: url('/@/assets/images/beltFire/1-2.png');
  114. }
  115. }
  116. </style>