index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <!-- eslint-disable vue/multi-word-component-names -->
  2. <template>
  3. <!-- 新增Tabs组件区分实时/历史数据 -->
  4. <Tabs v-model:activeKey="activeTab" type="line" class="common-page-tabs">
  5. <TabPane tab="实时监测" key="realtime">
  6. <div class="board-info">
  7. <MiniBoard
  8. :key="index"
  9. v-for="(item, index) in boardData"
  10. type="A"
  11. :label="item.label"
  12. :value="item.value"
  13. layout="label-top"
  14. class="board-item"
  15. />
  16. </div>
  17. <!-- 实时数据表格 -->
  18. <BasicTable @register="registerTable" :scroll="{ x: 'max-content' }" :style="{ padding: 0 }">
  19. <!-- 核心:判断record是否有有效数据,无则显示- -->
  20. <template #action="{ record }">
  21. <button @click="openModal(record, 'resolved')" class="resolved-btn" title="已解决">
  22. <span class="action-text">已解决</span>
  23. </button>
  24. </template>
  25. <template #empty>
  26. <!-- 无数据时显示-,样式居中对齐 -->
  27. <span class="empty-placeholder">-</span>
  28. </template>
  29. </BasicTable>
  30. </TabPane>
  31. <TabPane tab="历史数据" key="history">
  32. <!-- 历史数据表格 -->
  33. <BasicTable @register="registerHistoryTable" :scroll="{ x: 'max-content' }" :style="{ padding: 0 }">
  34. <template #action="{ record }">
  35. <div class="action-buttons">
  36. <button @click="openModal(record, 'history')" class="action-btn">
  37. <SvgIcon name="details" />
  38. </button>
  39. </div>
  40. </template>
  41. </BasicTable>
  42. </TabPane>
  43. </Tabs>
  44. <!-- 弹窗组件 -->
  45. <a-modal
  46. style="top: 30%; left: 170px"
  47. v-model:visible="visibleModal"
  48. :width="450"
  49. title="实时监测数据"
  50. @ok="handleOkEdit"
  51. @cancel="handleCancelEdit"
  52. >
  53. <a-table></a-table>
  54. </a-modal>
  55. </template>
  56. <script setup lang="ts">
  57. import { ref, onMounted, onUnmounted } from 'vue';
  58. import { BasicTable, useTable } from '/@/components/Table';
  59. import { Tabs, TabPane } from 'ant-design-vue';
  60. import MiniBoard from '/@/components/Configurable/detail/MiniBoard.vue';
  61. import { SvgIcon } from '/@/components/Icon';
  62. // 引入模拟数据
  63. import { boardData, columns, searchFormSchema, historicalMinesData } from './sealRiskJudgeAnalysis.data';
  64. import { getMineData, getProvinceAlarm, getGoafData, getProvinceAlarmHistory, getProvinceAlarmNum } from './sealRiskJudge.api';
  65. import dayjs from 'dayjs';
  66. // 激活的Tab页签
  67. const activeTab = ref('realtime');
  68. const visibleModal = ref(false);
  69. //煤矿列表数据
  70. const deviceOptions = ref([]);
  71. const goafOptions = ref([]);
  72. const mineCode = ref('');
  73. const goafId = ref('');
  74. const visibleresolveModal = ref(false);
  75. const resolveValue = ref('');
  76. const boardData = ref([
  77. {
  78. label: '采空区数量',
  79. value: '',
  80. },
  81. {
  82. label: '增减风安全区',
  83. value: '',
  84. },
  85. {
  86. label: '减风危险区',
  87. value: '',
  88. },
  89. {
  90. label: '增风危险区',
  91. value: '',
  92. },
  93. {
  94. label: '爆炸危险区',
  95. value: '',
  96. },
  97. ]);
  98. const minesData = ref([]);
  99. // 注册实时数据表格
  100. const [registerTable, { reload }] = useTable({
  101. dataSource: minesData,
  102. columns,
  103. api: getProvinceAlarm,
  104. formConfig: {
  105. labelWidth: 120,
  106. schemas: [
  107. {
  108. label: '煤矿名称',
  109. field: 'mineCodeList', // 对应组件的value.mineCode(最终传给Table的查询参数)
  110. component: 'MineCascader', // 自定义组件名
  111. colProps: { span: 6 },
  112. rules: [],
  113. },
  114. ],
  115. showAdvancedButton: false,
  116. schemaGroupNames: ['常规查询'],
  117. },
  118. pagination: true,
  119. striped: true,
  120. useSearchForm: true,
  121. bordered: true,
  122. showIndexColumn: false,
  123. actionColumn: {
  124. width: 80,
  125. title: '操作',
  126. dataIndex: 'action',
  127. slots: { customRender: 'action' },
  128. fixed: undefined,
  129. },
  130. });
  131. // 注册历史数据表格
  132. const [registerHistoryTable] = useTable({
  133. dataSource: historicalMinesData,
  134. columns,
  135. api: getProvinceAlarmHistory,
  136. formConfig: {
  137. labelWidth: 120,
  138. schemas: [
  139. {
  140. label: '开始时间',
  141. field: 'startTime',
  142. component: 'DatePicker',
  143. defaultValue: dayjs().add(-30, 'day').format('YYYY-MM-DD HH:mm:ss'),
  144. componentProps: {
  145. showTime: true,
  146. placeholder: '请选择开始时间',
  147. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  148. },
  149. colProps: { span: 6 },
  150. rules: [{ required: true, message: '请选择开始时间' }],
  151. },
  152. {
  153. label: '结束时间',
  154. field: 'endTime',
  155. component: 'DatePicker',
  156. defaultValue: dayjs(),
  157. componentProps: {
  158. showTime: true,
  159. placeholder: '请选择结束时间',
  160. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  161. },
  162. colProps: { span: 6 },
  163. rules: [{ required: true, message: '请选择结束时间' }],
  164. },
  165. {
  166. label: '煤矿名称',
  167. field: 'mineCode', // 对应组件的value.mineCode(最终传给Table的查询参数)
  168. defaultValue: deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
  169. component: 'MineCascader', // 自定义组件名
  170. componentProps: {
  171. onChange: async (e, option) => {
  172. mineCode.value = e;
  173. await getGoafDataList(e);
  174. },
  175. },
  176. colProps: { span: 6 },
  177. rules: [],
  178. },
  179. {
  180. label: '采空区查询',
  181. field: 'goafId',
  182. component: 'Select',
  183. defaultValue: goafOptions.value[0] ? goafOptions.value[0]['value'] : '',
  184. componentProps: {
  185. options: goafOptions,
  186. onChange: async (e, option) => {
  187. goafId.value = e;
  188. },
  189. },
  190. colProps: {
  191. span: 6,
  192. },
  193. },
  194. {
  195. field: 'alarmFiled',
  196. label: '预警字段',
  197. component: 'Select',
  198. componentProps: {
  199. options: [
  200. { label: '甲烷', value: 'ch4Val' },
  201. { label: '氧气', value: 'o2Val' },
  202. { label: '一氧化碳', value: 'coVal' },
  203. { label: '二氧化碳', value: 'co2Val' },
  204. { label: '乙烯', value: 'c2h4Val' },
  205. { label: '乙炔', value: 'c2h2Val' },
  206. { label: '压差', value: 'sourcePressure' },
  207. { label: '温度', value: 'temperature' },
  208. ],
  209. },
  210. colProps: { span: 6 },
  211. },
  212. ],
  213. showAdvancedButton: false,
  214. schemaGroupNames: ['常规查询'],
  215. },
  216. pagination: true,
  217. striped: true,
  218. useSearchForm: true,
  219. bordered: true,
  220. showIndexColumn: false,
  221. // actionColumn: {
  222. // width: 60,
  223. // title: '操作',
  224. // dataIndex: 'action',
  225. // slots: { customRender: 'action' },
  226. // fixed: undefined,
  227. // },
  228. });
  229. // 弹窗引用
  230. const realtimeModalRef = ref(null);
  231. const historyModalRef = ref(null);
  232. // 定时器
  233. let timer: IntervalHandle;
  234. const fetchTableData = async () => {
  235. await reload();
  236. };
  237. // 打开弹窗方法(区分实时/历史)
  238. const openModal = (record, type) => {
  239. if (type === 'realtime') {
  240. // 可向实时弹窗传递当前记录数据
  241. realtimeModalRef.value?.showModal(record);
  242. } else if (type === 'resolved') {
  243. visibleresolveModal.value = true;
  244. record.isResolved = resolveValue.value || '';
  245. } else if (type === 'detail') {
  246. visibleModal.value = true;
  247. } else {
  248. // 可向历史弹窗传递当前记录数据
  249. historyModalRef.value?.showModal(record);
  250. }
  251. };
  252. const handleOkEdit = () => {
  253. visibleresolveModal.value = false;
  254. };
  255. const handleCancelEdit = () => {
  256. visibleresolveModal.value = false;
  257. };
  258. async function fetchAlarmData(id) {
  259. const params = {
  260. // 填写所需参数
  261. alarmType: 'leakageAlarm',
  262. mineId: id,
  263. pageNo: 1,
  264. pageSize: 50,
  265. };
  266. const result = await getProvinceAlarm(params);
  267. minesData.value = result.records;
  268. }
  269. const getMineDataList = async () => {
  270. const params = {
  271. pageNo: 1,
  272. pageSize: 50,
  273. };
  274. const response = await getMineData(params);
  275. deviceOptions.value = response.records.map((item, index) => {
  276. return {
  277. label: item['mineName'],
  278. value: item['mineCode'],
  279. };
  280. });
  281. };
  282. const getGoafDataList = async (mineId) => {
  283. const params = {
  284. mineCode: mineId,
  285. };
  286. const response = await getGoafData(params);
  287. goafOptions.value = response.map((item, index) => {
  288. return {
  289. label: item['devicePos'],
  290. value: item['deviceCode'],
  291. };
  292. });
  293. };
  294. async function getAlarmTotalData() {
  295. const params = {
  296. alarmType: 'explosionAlarm',
  297. };
  298. const result = await getProvinceAlarmNum(params);
  299. boardData.value[1].value = result.alarmLevel1;
  300. boardData.value[2].value = result.alarmLevel2;
  301. boardData.value[3].value = result.alarmLevel3;
  302. boardData.value[4].value = result.alarmLevel4;
  303. boardData.value[0].value = result.alarmLevel1 + result.alarmLevel2 + result.alarmLevel3 + result.alarmLevel4;
  304. }
  305. onMounted(() => {
  306. // 页面挂载时的逻辑
  307. getMineDataList();
  308. getAlarmTotalData();
  309. timer = setInterval(() => {
  310. fetchTableData();
  311. }, 5000);
  312. });
  313. onUnmounted(() => {
  314. if (timer) {
  315. clearInterval(timer);
  316. }
  317. });
  318. </script>
  319. <style lang="less" scoped>
  320. .board-info {
  321. display: grid;
  322. grid-template-columns: repeat(5, auto); /* 3列:改5则为5列 */
  323. gap: auto;
  324. justify-content: start;
  325. flex-wrap: wrap;
  326. box-sizing: border-box;
  327. background-color: @white;
  328. padding: 10px;
  329. gap: 100px;
  330. // margin: 0 10px;
  331. margin-bottom: 5px;
  332. }
  333. .board-item {
  334. box-sizing: border-box;
  335. }
  336. </style>