ModuleMine.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. if (!selectedDeviceID.value) {
  99. selectedDeviceID.value = options.value[0]?.value;
  100. }
  101. },
  102. {
  103. immediate: true,
  104. }
  105. );
  106. </script>
  107. <style scoped lang="less">
  108. @font-face {
  109. font-family: 'douyuFont';
  110. src: url('../../../../assets/font/douyuFont.otf');
  111. }
  112. .module-mine {
  113. --image-common-border1: url('@/assets/images/home-container/configurable/minehome/common-border1.png');
  114. --image-common-border2: url('@/assets/images/home-container/configurable/minehome/common-border2.png');
  115. --image-common-border3: url('@/assets/images/home-container/configurable/minehome/common-border3.png');
  116. --image-select-border: url('@/assets/images/home-container/configurable/minehome/select-border.png');
  117. position: absolute;
  118. // width: 100%;
  119. // height: 100%;
  120. background: var(--image-common-border2) no-repeat center;
  121. background-size: 100% 100%;
  122. overflow: hidden;
  123. /* 标题栏样式 */
  124. .module-title {
  125. display: flex;
  126. justify-content: center;
  127. align-items: center;
  128. height: 40px;
  129. color: #fff;
  130. font-size: 14px;
  131. font-weight: bold;
  132. .title-content {
  133. font-family: 'douyuFont';
  134. margin-right: 10px;
  135. &.cursor-pointer {
  136. cursor: pointer;
  137. text-decoration: underline;
  138. }
  139. }
  140. }
  141. /* 下拉选择框单独一行样式 */
  142. .module-selector-row {
  143. display: flex;
  144. justify-content: flex-start;
  145. align-items: center;
  146. padding: 10px 35px 0 35px;
  147. width: 100%;
  148. min-height: 40px;
  149. .custom-select {
  150. flex: 1;
  151. width: 100% !important;
  152. min-width: 0;
  153. font-size: 18px;
  154. color: white !important;
  155. ::v-deep .zxm-select-selector {
  156. background: var(--image-select-border) no-repeat center/100% 100%;
  157. border: none !important;
  158. padding: 0 20px;
  159. }
  160. /* 隐藏默认的下拉箭头 */
  161. ::v-deep .zxm-select-arrow {
  162. display: none;
  163. }
  164. /* 添加自定义白色下拉三角形 */
  165. &::after {
  166. content: '';
  167. position: absolute;
  168. right: 16px;
  169. top: 50%;
  170. transform: translateY(-50%);
  171. width: 0;
  172. height: 0;
  173. border-left: 6px solid transparent;
  174. border-right: 6px solid transparent;
  175. border-top: 8px solid white;
  176. pointer-events: none;
  177. }
  178. /* 修复占位符颜色 */
  179. ::v-deep .zxm-select-selection-placeholder {
  180. color: white !important;
  181. font-size: 18px;
  182. }
  183. }
  184. }
  185. /* 内容区样式 */
  186. .module-content {
  187. padding: 10px 23px;
  188. background: transparent;
  189. }
  190. }
  191. </style>