RealtimeDetailsModal.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. title="密闭监测详情"
  5. width="1400px"
  6. :bodyStyle="{ padding: `0 20px 0 20px` }"
  7. @register="register"
  8. @close="okHandler"
  9. @ok="okHandler"
  10. >
  11. <!-- 基础信息栏(修改布局:每行4列,共两行) -->
  12. <div class="base-info">
  13. <div v-for="(item, index) in modalDetailsData.basicInfo" :key="index" class="info-item">
  14. <span class="label">{{ item.label }}:</span>
  15. <component :is="contextRender(item)"></component>
  16. </div>
  17. </div>
  18. <!-- 监测数据卡片 -->
  19. <div class="data-cards">
  20. <MiniBoard
  21. v-for="(item, index) in modalDetailsData.board"
  22. :key="index"
  23. type="D"
  24. :label="item.label"
  25. :value="dataRef[item.value] || '-'"
  26. layout="val-top"
  27. />
  28. </div>
  29. <!-- 图表区域 -->
  30. <div class="chart-area">
  31. <div class="chart-item">
  32. <div class="chart-title pl-20px">爆炸三角形</div>
  33. <div class="chart-placeholder">
  34. <BlastDelta
  35. :posMonitor="dataRef"
  36. :canvas-size="{ width: 225, height: 149 }"
  37. :legendStyle="{ left: '50%', top: '10px' }"
  38. text-color="#000"
  39. />
  40. </div>
  41. </div>
  42. <div class="chart-item">
  43. <div class="chart-title pl-20px">气体浓度曲线</div>
  44. <div class="chart-placeholder">
  45. <CustomChart
  46. :chart-data="{ chartData: dataArray }"
  47. :chart-config="modalDetailsData.gasConcentrationConfig"
  48. :chart-option="{
  49. textStyle: {
  50. color: '#000',
  51. },
  52. }"
  53. style="height: 100%; width: 100%"
  54. />
  55. </div>
  56. </div>
  57. <div class="chart-item">
  58. <div class="chart-title pl-20px">内外压力及压差曲线</div>
  59. <div class="chart-placeholder">
  60. <CustomChart
  61. :chart-data="{ chartData: dataArray }"
  62. :chart-config="modalDetailsData.pressureConfig"
  63. :chart-option="{
  64. textStyle: {
  65. color: '#000',
  66. },
  67. }"
  68. style="height: 100%; width: 100%"
  69. />
  70. </div>
  71. </div>
  72. </div>
  73. </BasicModal>
  74. </template>
  75. <script lang="ts">
  76. import { defineComponent } from 'vue';
  77. import { BasicModal, useModalInner } from '/@/components/Modal';
  78. import { ref } from 'vue';
  79. import MiniBoard from '/@/components/Configurable/detail/MiniBoard.vue';
  80. import BlastDelta from '/@/components/Configurable/preset/BlastDelta.vue';
  81. import CustomChart from '/@/components/Configurable/detail/CustomChart.vue';
  82. import { modalDetailsData } from '../monitor.data';
  83. import { concat, get, isFunction, last, takeRight } from 'lodash-es';
  84. import { h } from 'vue';
  85. import { getGoafData } from '../monitor.api';
  86. import { useIntervalFn } from '@vueuse/core';
  87. import dayjs from 'dayjs';
  88. import { propTypes } from '/@/utils/propTypes';
  89. export default defineComponent({
  90. components: { BasicModal, MiniBoard, BlastDelta, CustomChart },
  91. props: {
  92. identifyField: propTypes.string.def('goafId'),
  93. },
  94. emits: ['close', 'register'],
  95. setup(props, { emit }) {
  96. const dataRef = ref<any>({});
  97. const dataArray = ref<any[]>([]);
  98. // 添加元素,数组最多15项,按队列排布
  99. const push = (item) => {
  100. item.readTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
  101. dataArray.value = takeRight(concat(dataArray.value, item), 15);
  102. };
  103. const [register] = useModalInner((d) => {
  104. if (!d) return;
  105. // 没数据或者新传入的数据id不同,说明是首次/点击别的数据列进入的该组件
  106. if (!dataRef.value || d[props.identifyField] !== dataRef.value[props.identifyField]) {
  107. dataArray.value = [];
  108. }
  109. dataRef.value = d;
  110. push(d);
  111. resume();
  112. });
  113. function contextRender({ value, customRender }: any) {
  114. if (isFunction(customRender)) return customRender({ record: dataRef.value });
  115. return h('span', get(dataRef.value, value));
  116. }
  117. function fetchDetailData() {
  118. const { deptId, goafId } = dataRef.value;
  119. getGoafData({ deptId, goafId }).then(({ records }) => {
  120. dataRef.value = last(records);
  121. push(dataRef.value);
  122. });
  123. }
  124. const { pause, resume } = useIntervalFn(
  125. () => {
  126. fetchDetailData();
  127. },
  128. 2000,
  129. {
  130. immediate: false,
  131. }
  132. );
  133. function okHandler() {
  134. pause();
  135. emit('close');
  136. }
  137. return {
  138. dataRef,
  139. modalDetailsData,
  140. dataArray,
  141. get,
  142. register,
  143. contextRender,
  144. okHandler,
  145. };
  146. },
  147. });
  148. </script>
  149. <style lang="less" scoped>
  150. .base-info {
  151. display: grid;
  152. grid-template-columns: repeat(3, 1fr); /* 强制每行4列 */
  153. grid-template-rows: auto auto; /* 两行自动高度 */
  154. gap: 16px 12px; /* 行列间距(行间距16px,列间距12px) */
  155. margin-bottom: 20px;
  156. padding: 20px;
  157. border: 1px solid @border-color-base;
  158. border-radius: 10px;
  159. background: @card-bg-color;
  160. }
  161. .info-item {
  162. display: flex;
  163. align-items: center;
  164. /* 适配文字过长的情况 */
  165. white-space: nowrap;
  166. overflow: hidden;
  167. text-overflow: ellipsis;
  168. }
  169. .label {
  170. color: #666;
  171. margin-right: 8px;
  172. min-width: 90px;
  173. flex-shrink: 0; /* 标签宽度不收缩 */
  174. }
  175. .value {
  176. color: #333;
  177. flex: 1;
  178. overflow: hidden;
  179. text-overflow: ellipsis;
  180. }
  181. .data-cards {
  182. display: flex;
  183. // grid-template-columns: repeat(8, 1fr);
  184. // gap: 16px;
  185. justify-content: space-evenly;
  186. margin-bottom: 20px;
  187. padding: 20px;
  188. border: 1px solid @border-color-base;
  189. border-radius: 10px;
  190. background: @card-bg-color;
  191. }
  192. .data-card {
  193. background: #fafafa;
  194. border-radius: 8px;
  195. padding: 12px;
  196. text-align: center;
  197. }
  198. .card-value {
  199. font-size: 20px;
  200. font-weight: bold;
  201. color: #1890ff;
  202. margin-bottom: 4px;
  203. }
  204. .card-label {
  205. font-size: 14px;
  206. color: #666;
  207. }
  208. .chart-area {
  209. display: flex;
  210. flex-wrap: wrap;
  211. gap: 20px;
  212. padding: 20px;
  213. border: 1px solid @border-color-base;
  214. border-radius: 10px;
  215. /* background: black; */
  216. background: @card-bg-color;
  217. }
  218. .chart-item {
  219. flex: 1;
  220. // flex-basis: 6;
  221. // flex-shrink: 1;
  222. // min-width: 200px;
  223. &:first-child {
  224. // flex-basis: 380px;
  225. flex: 0 0 380px;
  226. // flex-shrink: 0;
  227. // flex-grow: 1;
  228. }
  229. }
  230. .chart-title {
  231. font-size: 14px;
  232. font-weight: 500;
  233. margin-bottom: 8px;
  234. font-weight: bold;
  235. color: @text-color-call-out;
  236. }
  237. .chart-placeholder {
  238. width: 100%;
  239. height: 200px;
  240. border-radius: 4px;
  241. overflow: hidden;
  242. }
  243. .chart-placeholder img {
  244. width: 100%;
  245. height: 100%;
  246. object-fit: cover;
  247. }
  248. </style>