ModuleCommon.vue 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <!-- 常用模块 -->
  3. <ventBox1 :class="getModuleClass(showStyle)" :style="style">
  4. <template v-if="moduleName" #title>
  5. <div :class="{ 'cursor-pointer': !!moduleData.to }" @click="redirectTo">{{ moduleName }}</div>
  6. </template>
  7. <template #container>
  8. <slot>
  9. <Header :deviceType="deviceType" :moduleData="moduleData" :data="data" @select="selectedData = $event" />
  10. <Content :style="{ height: header.show ? 'calc(100% - 30px)' : '100%' }" :moduleData="moduleData" :data="selectedData" />
  11. </slot>
  12. </template>
  13. </ventBox1>
  14. </template>
  15. <script lang="ts" setup>
  16. import Header from './header.vue';
  17. import Content from './content.vue';
  18. // import ModuleLeft from './original/moduleLeft.vue';
  19. // import ModuleBottom from './original/moduleBottom.vue';
  20. import { computed, ref } from 'vue';
  21. import ventBox1 from '/@/components/vent/ventBox1.vue';
  22. import { openWindow } from '/@/utils';
  23. // import { ModuleProps } from '../types';
  24. const props = defineProps<{
  25. /** 配置的详细模块信息 */
  26. moduleData: any;
  27. /** 配置的详细样式信息 */
  28. showStyle: any;
  29. /** 该模块配置中的设备标识符 */
  30. deviceType: string;
  31. /** api返回的数据 */
  32. data: any;
  33. moduleName: string;
  34. visible: boolean;
  35. }>();
  36. defineEmits(['close', 'click']);
  37. const { header } = props.moduleData;
  38. const selectedData = ref();
  39. const style = computed(() => {
  40. const size = props.showStyle.size;
  41. const position = props.showStyle.position;
  42. return size + position + 'position: absolute;';
  43. });
  44. // 根据配置里的定位判断应该使用哪个class
  45. function getModuleClass({ size, position }) {
  46. const [_, width] = size.match(/width:([0-9]+)px/) || [];
  47. if (position.includes('bottom') || parseInt(width) > 800) {
  48. return 'module-common module-common-longer';
  49. }
  50. return 'module-common';
  51. }
  52. function redirectTo() {
  53. const { to } = props.moduleData;
  54. if (!to) return;
  55. openWindow(to);
  56. }
  57. </script>
  58. <style lang="less" scoped>
  59. @import '/@/design/theme.less';
  60. .module-common .box1-center {
  61. height: calc(100% - 48px);
  62. }
  63. :deep(.box1-center) {
  64. height: calc(100% - 48px);
  65. }
  66. :deep(.box1-center > .box-container) {
  67. height: 100%;
  68. padding: 0 !important;
  69. width: 100% !important;
  70. }
  71. @{theme-deepblue} {
  72. .module-common-longer {
  73. :deep(.box1-top) {
  74. --image-box1-top: url('/@/assets/images/themify/deepblue/vent/border/box2-top-long.png');
  75. }
  76. :deep(.box1-bottom) {
  77. --image-box1-bottom: none;
  78. }
  79. }
  80. }
  81. .module-common-longer {
  82. :deep(.box1-top) {
  83. --image-box1-top: url('/@/assets/images/vent/box-top-bg.png');
  84. background-image: var(--image-box1-top);
  85. }
  86. :deep(.box1-bottom) {
  87. --image-box1-bottom: url('/@/assets/images/vent/box-bottom-bg.png');
  88. background-image: var(--image-box1-bottom);
  89. }
  90. }
  91. </style>