ModuleCommon.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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">
  8. <template v-if="moduleName" #title>
  9. <div :class="{ 'cursor-pointer': !!moduleData.to }" @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 './header.vue';
  27. import Content from './content.vue';
  28. // import ModuleLeft from './original/moduleLeft.vue';
  29. // import ModuleBottom from './original/moduleBottom.vue';
  30. import { computed, ref } from 'vue';
  31. import ventBox1 from '/@/components/vent/ventBox1.vue';
  32. import { openWindow } from '/@/utils';
  33. import { getFormattedText } from '../hooks/helper';
  34. // import { ModuleProps } from '../types';
  35. const props = defineProps<{
  36. /** 配置的详细模块信息 */
  37. moduleData: any;
  38. /** 配置的详细样式信息 */
  39. showStyle: any;
  40. /** 该模块配置中的设备标识符 */
  41. deviceType: string;
  42. /** api返回的数据 */
  43. data: any;
  44. moduleName: string;
  45. visible: boolean;
  46. chartData: any;
  47. }>();
  48. defineEmits(['close', 'click']);
  49. const { header } = props.moduleData;
  50. const selectedData = ref();
  51. const style = computed(() => {
  52. const size = props.showStyle.size;
  53. const position = props.showStyle.position;
  54. return size + position + 'position: absolute; pointer-events: auto; z-index: 1';
  55. });
  56. const capitalizedPosition = computed(() => {
  57. return props.showStyle.position.includes('left') ? 'Left' : 'Right';
  58. });
  59. // 根据配置里的定位判断应该使用哪个class
  60. function getModuleClass({ size, position }) {
  61. const [_, width] = size.match(/width:([0-9]+)px/) || [];
  62. if (position.includes('bottom') || parseInt(width) > 800) {
  63. return 'module-common module-common-longer';
  64. }
  65. return 'module-common';
  66. }
  67. function redirectTo() {
  68. const { to } = props.moduleData;
  69. if (!to) return;
  70. openWindow(getFormattedText(selectedData.value, to));
  71. }
  72. </script>
  73. <style lang="less" scoped>
  74. @import '/@/design/theme.less';
  75. .module-common .box1-center {
  76. height: calc(100% - 48px);
  77. }
  78. :deep(.box1-center) {
  79. height: calc(100% - 48px);
  80. }
  81. :deep(.box1-center > .box-container) {
  82. height: 100%;
  83. padding: 0 !important;
  84. width: 100% !important;
  85. }
  86. @{theme-green} {
  87. .module-common-longer {
  88. :deep(.box1-top) {
  89. --image-box1-top: url('/@/assets/images/themify/green/vent/border/box-top.png');
  90. }
  91. :deep(.box1-bottom) {
  92. --image-box1-bottom: url('/@/assets/images/themify/green/vent/border/box-bottom.png');
  93. }
  94. }
  95. }
  96. @{theme-deepblue} {
  97. .module-common-longer {
  98. :deep(.box1-top) {
  99. --image-box1-top: url('/@/assets/images/themify/deepblue/vent/border/box2-top-long.png');
  100. }
  101. :deep(.box1-bottom) {
  102. --image-box1-bottom: none;
  103. }
  104. }
  105. }
  106. .module-common-longer {
  107. :deep(.box1-top) {
  108. --image-box1-top: url('/@/assets/images/vent/box-top-bg.png');
  109. background-image: var(--image-box1-top);
  110. }
  111. :deep(.box1-bottom) {
  112. --image-box1-bottom: url('/@/assets/images/vent/box-bottom-bg.png');
  113. background-image: var(--image-box1-bottom);
  114. }
  115. }
  116. </style>