ModuleMine.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <div class="module-mine" :style="style" :class="moduleClass">
  3. <!-- 标题栏 -->
  4. <div v-if="moduleName" class="module-title">
  5. <div class="title-content" :class="{ 'cursor-pointer': !!moduleData.to }" @click="redirectTo">
  6. {{ moduleName }}
  7. </div>
  8. <!-- 右侧插槽内容(如有) -->
  9. <div class="title-right" v-if="header.show && header.slot.show">
  10. {{ getFormattedText(selectedDevice, header.slot.value) }}
  11. </div>
  12. </div>
  13. <!-- 下拉选择框,单独一行放在标题栏下方 -->
  14. <div class="module-selector-row" v-if="header.show && header.selector.show">
  15. <a-select
  16. size="middle"
  17. placeholder="请选择"
  18. v-model:value="selectedDeviceID"
  19. :options="options"
  20. @change="selectHandler"
  21. class="custom-select"
  22. />
  23. </div>
  24. <!-- 内容区 -->
  25. <div class="module-content" :style="contentStyle">
  26. <slot>
  27. <Content style="height: 100%" :moduleData="moduleData" :data="selectedDevice" />
  28. </slot>
  29. </div>
  30. </div>
  31. </template>
  32. <script setup lang="ts">
  33. // 引入内容组件
  34. import Content from './content.vue';
  35. import { defineProps, defineEmits, computed, watch } from 'vue';
  36. import { useInitModule } from '../hooks/useInit';
  37. import { getFormattedText } from '../hooks/helper';
  38. import { openWindow } from '/@/utils';
  39. // 定义组件接收的属性
  40. const props = defineProps<{
  41. moduleData: any;
  42. showStyle: any;
  43. deviceType: string;
  44. data: any;
  45. moduleName: string;
  46. visible: boolean;
  47. }>();
  48. const emit = defineEmits(['close', 'select']);
  49. // 取出头部配置
  50. const { header } = props.moduleData;
  51. // 初始化模块相关的下拉、选中项等
  52. const { selectedDeviceID, selectedDevice, options, init } = useInitModule(props.deviceType, props.moduleData);
  53. // 计算样式(宽高+定位)
  54. const style = computed(() => {
  55. const size = props.showStyle.size;
  56. const position = props.showStyle.position;
  57. return size + position;
  58. });
  59. // 计算不同布局下的class
  60. const moduleClass = computed(() => {
  61. const position = props.showStyle.position;
  62. const size = props.showStyle.size;
  63. const [_, width] = size.match(/width:([0-9]+)px/) || [];
  64. if (position.includes('bottom') || parseInt(width) > 800) {
  65. return 'module-wide';
  66. }
  67. if (position.includes('left')) {
  68. return 'module-medium';
  69. }
  70. if (position.includes('right')) {
  71. return 'module-medium';
  72. }
  73. return 'module-medium';
  74. });
  75. // 计算内容区高度样式
  76. const contentStyle = computed(() => {
  77. if (header.show && header.selector.show) {
  78. return 'height: calc(100% - 48px - 40px);'; // 有下拉框的情况
  79. }
  80. return 'height: calc(100% - 40px);'; // 没有下拉框的情况
  81. });
  82. // 下拉选择事件
  83. function selectHandler(id) {
  84. selectedDeviceID.value = id;
  85. emit('select', selectedDevice);
  86. }
  87. // 跳转事件
  88. function redirectTo() {
  89. const { to } = props.moduleData;
  90. if (!to) return;
  91. openWindow(to);
  92. }
  93. // 监听数据变化,初始化
  94. watch(
  95. () => props.data,
  96. (d) => {
  97. init(d);
  98. selectedDeviceID.value = options.value[0]?.value;
  99. },
  100. {
  101. immediate: true,
  102. }
  103. );
  104. </script>
  105. <style scoped lang="less">
  106. @font-face {
  107. font-family: 'douyuFont';
  108. src: url('../../../../assets/font/douyuFont.otf');
  109. }
  110. .module-mine {
  111. --image-common-border1: url('@/assets/images/home-container/configurable/minehome/common-border1.png');
  112. --image-common-border2: url('@/assets/images/home-container/configurable/minehome/common-border2.png');
  113. --image-common-border3: url('@/assets/images/home-container/configurable/minehome/common-border3.png');
  114. --image-select-border: url('@/assets/images/home-container/configurable/minehome/select-border.png');
  115. position: absolute;
  116. // width: 100%;
  117. // height: 100%;
  118. background: var(--image-common-border2) no-repeat center;
  119. background-size: 100% 100%;
  120. overflow: hidden;
  121. /* 标题栏样式 */
  122. .module-title {
  123. display: flex;
  124. justify-content: center;
  125. align-items: center;
  126. height: 40px;
  127. color: #fff;
  128. font-size: 14px;
  129. font-weight: bold;
  130. .title-content {
  131. font-family: 'douyuFont';
  132. margin-right: 10px;
  133. &.cursor-pointer {
  134. cursor: pointer;
  135. text-decoration: underline;
  136. }
  137. }
  138. }
  139. /* 下拉选择框单独一行样式 */
  140. .module-selector-row {
  141. display: flex;
  142. justify-content: flex-start;
  143. align-items: center;
  144. padding: 10px 35px 0 35px;
  145. width: 100%;
  146. min-height: 40px;
  147. .custom-select {
  148. flex: 1;
  149. width: 100% !important;
  150. min-width: 0;
  151. font-size: 18px;
  152. color: white !important;
  153. ::v-deep .zxm-select-selector {
  154. background: var(--image-select-border) no-repeat center/100% 100%;
  155. border: none !important;
  156. padding: 0 20px;
  157. }
  158. /* 隐藏默认的下拉箭头 */
  159. ::v-deep .zxm-select-arrow {
  160. display: none;
  161. }
  162. /* 添加自定义白色下拉三角形 */
  163. &::after {
  164. content: '';
  165. position: absolute;
  166. right: 16px;
  167. top: 50%;
  168. transform: translateY(-50%);
  169. width: 0;
  170. height: 0;
  171. border-left: 6px solid transparent;
  172. border-right: 6px solid transparent;
  173. border-top: 8px solid white;
  174. pointer-events: none;
  175. }
  176. /* 修复占位符颜色 */
  177. ::v-deep .zxm-select-selection-placeholder {
  178. color: white !important;
  179. font-size: 18px;
  180. }
  181. }
  182. }
  183. /* 内容区样式 */
  184. .module-content {
  185. padding: 10px 23px;
  186. background: transparent;
  187. }
  188. }
  189. </style>