HistoryTable.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <template>
  2. <div class="history-table" v-if="loading">
  3. <BasicTable ref="historyTable" @register="registerTable" :data-source="dataSource">
  4. <template #bodyCell="{ column, record }">
  5. <a-tag v-if="column.dataIndex === 'warnFlag'" :color="record.warnFlag == '0' ? 'green' : 'red'">{{
  6. record.warnFlag == '0' ? '正常' : '报警'
  7. }}</a-tag>
  8. <a-tag v-if="column.dataIndex === 'netStatus'" :color="record.netStatus == '0' ? '#f00' : 'green'">{{
  9. record.netStatus == '0' ? '断开' : '连接'
  10. }}</a-tag>
  11. <slot name="filterCell" v-bind="{ column, record }"></slot>
  12. </template>
  13. <template #form-submitBefore>
  14. <a-button type="primary" preIcon="ant-design:search-outlined" @click="getDataSource">查询</a-button>
  15. </template>
  16. </BasicTable>
  17. </div>
  18. </template>
  19. <script lang="ts" setup>
  20. //ts语法
  21. import { watchEffect, ref, watch, defineExpose, inject, nextTick } from 'vue';
  22. import { FormSchema } from '/@/components/Form/index';
  23. import { BasicTable } from '/@/components/Table';
  24. import { useListPage } from '/@/hooks/system/useListPage';
  25. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  26. import { defHttp } from '/@/utils/http/axios';
  27. import dayjs from 'dayjs';
  28. import { getAutoScrollContainer } from '/@/utils/common/compUtils';
  29. import { onMounted } from 'vue';
  30. import { safetyDeviceList } from './safety.api';
  31. const globalConfig = inject('globalConfig');
  32. const props = defineProps({
  33. columnsType: {
  34. type: String,
  35. },
  36. columns: {
  37. type: Array,
  38. // required: true,
  39. default: () => [],
  40. },
  41. deviceType: {
  42. type: String,
  43. required: true,
  44. },
  45. deviceListApi: {
  46. type: Function,
  47. },
  48. deviceArr: {
  49. type: Array,
  50. // required: true,
  51. default: () => [],
  52. },
  53. designScope: {
  54. type: String,
  55. },
  56. sysId: {
  57. type: String,
  58. },
  59. deviceId: {
  60. type: String,
  61. },
  62. scroll: {
  63. type: Object,
  64. default: { y: 0 },
  65. },
  66. formSchemas: {
  67. type: Array<FormSchema>,
  68. default: () => [],
  69. },
  70. });
  71. const getDeviceListApi = (params) => defHttp.post({ url: '/monitor/device', params });
  72. const historyTable = ref();
  73. const loading = ref(false);
  74. const stationType = ref('plc1');
  75. const dataSource = ref([]);
  76. const dataTypeName = ref('');
  77. const intervalMap = new Map([
  78. ['1', '1s'],
  79. ['2', '5s'],
  80. ['3', '10s'],
  81. ['4', '30s'],
  82. ['5', '1m'],
  83. ['6', '10m'],
  84. ['7', '30m'],
  85. ['8', '1h'],
  86. ]);
  87. const getExportXlsUrl = () => {
  88. if (stationType.value !== 'redis') {
  89. return '/safety/ventanalyMonitorData/exportXls';
  90. } else {
  91. return '/monitor/history/getHistoryData/exportXls';
  92. }
  93. };
  94. const emit = defineEmits(['change']);
  95. const historyType = ref('');
  96. const columns = ref([]);
  97. const tableScroll = props.scroll.y ? ref({ y: props.scroll.y - 100 }) : ref({});
  98. let deviceOptions = ref([]);
  99. const deviceTypeStr = ref('');
  100. loading.value = true;
  101. watch(
  102. () => {
  103. return props.columnsType;
  104. },
  105. async (newVal) => {
  106. if (!newVal) return;
  107. if (historyTable.value) getForm().resetFields();
  108. await getDeviceList();
  109. dataSource.value = [];
  110. const column = getTableHeaderColumns(newVal.includes('_history') ? newVal : newVal + '_history');
  111. if (column && column.length < 1) {
  112. const arr = newVal.split('_');
  113. console.log('历史记录列表表头------------>', arr[0] + '_monitor');
  114. columns.value = getTableHeaderColumns(arr[0] + '_history');
  115. } else {
  116. columns.value = column;
  117. }
  118. if (historyTable.value) reload();
  119. },
  120. {
  121. immediate: true,
  122. }
  123. );
  124. watch(historyType, (type) => {
  125. if (!type) return;
  126. // if (historyTable.value) getForm().resetFields()
  127. const column = getTableHeaderColumns(type.includes('_history') ? type : type + '_history');
  128. if (column && column.length < 1) {
  129. const arr = type.split('_');
  130. columns.value = getTableHeaderColumns(arr[0] + '_history');
  131. } else {
  132. columns.value = column;
  133. }
  134. setColumns(columns.value);
  135. });
  136. watch(
  137. () => props.scroll.y,
  138. (newVal) => {
  139. if (newVal) {
  140. tableScroll.value = { y: newVal - 100 };
  141. } else {
  142. tableScroll.value = {};
  143. }
  144. }
  145. );
  146. watch(
  147. () => props.deviceId,
  148. async () => {
  149. await getForm().setFieldsValue({});
  150. await getDeviceList();
  151. }
  152. );
  153. async function getDeviceList() {
  154. let result;
  155. const res = await getDeviceListApi({ devicetype: props.deviceType, filterParams: { dataTypeName: dataTypeName.value }, pageSize: 10000 });
  156. if (res['records'] && res['records'].length > 0) {
  157. result = res['records'];
  158. } else if (res['msgTxt'] && res['msgTxt'][0] && res['msgTxt'][0]['datalist']) {
  159. result = res['msgTxt'][0]['datalist'];
  160. }
  161. if (result && result.length > 0) {
  162. deviceOptions.value = [];
  163. deviceOptions.value = result.map((item, index) => {
  164. return {
  165. label: item['strinstallpos'],
  166. value: item['id'] || item['deviceID'],
  167. strtype: item['strtype'] || item['deviceType'],
  168. strinstallpos: item['strinstallpos'],
  169. devicekind: item['devicekind'],
  170. stationtype: item['stationtype'],
  171. };
  172. });
  173. stationType.value = deviceOptions.value[0]['stationtype'];
  174. } else {
  175. deviceOptions.value = [];
  176. stationType.value = '';
  177. }
  178. await getForm().setFieldsValue({ gdeviceid: props.deviceId ? props.deviceId : deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '' });
  179. }
  180. async function getDataSource() {
  181. dataSource.value = [];
  182. setLoading(true);
  183. const stationTypeStr = stationType.value;
  184. const formData = getForm().getFieldsValue();
  185. const pagination = getPaginationRef();
  186. formData['pageNo'] = pagination['current'];
  187. formData['pageSize'] = pagination['pageSize'];
  188. formData['column'] = 'createTime';
  189. if (stationTypeStr !== 'redis') {
  190. formData['strtype'] = deviceTypeStr.value
  191. ? deviceTypeStr.value
  192. : deviceOptions.value[0]['strtype']
  193. ? deviceOptions.value[0]['strtype']
  194. : props.deviceType + '*';
  195. if (props.sysId) {
  196. formData['sysId'] = props.sysId;
  197. }
  198. const result = await defHttp.get({ url: '/safety/ventanalyMonitorData/listdays', params: formData });
  199. setPagination({ total: Math.abs(result['datalist']['total']) || 0 });
  200. if (result['datalist']['records'].length > 0) {
  201. dataSource.value = result['datalist']['records'].map((item: any) => {
  202. return Object.assign(item, item['readData']);
  203. });
  204. } else {
  205. dataSource.value = [];
  206. }
  207. } else {
  208. const params = {
  209. pageNum: pagination['current'],
  210. pageSize: pagination['pageSize'],
  211. column: pagination['createTime'],
  212. startTime: formData['ttime_begin'],
  213. endTime: formData['ttime_end'],
  214. deviceId: formData['gdeviceid'],
  215. strtype: props.deviceType + '*',
  216. sysId: props.sysId,
  217. interval: intervalMap.get(formData['skip']) ? intervalMap.get(formData['skip']) : '1h',
  218. isEmployee: props.deviceType.startsWith('vehicle') ? false : true,
  219. };
  220. const result = await defHttp.post({ url: '/monitor/history/getHistoryData', params: params });
  221. setPagination({ total: Math.abs(result['total']) || 0 });
  222. dataSource.value = result['records'] || [];
  223. }
  224. setLoading(false);
  225. }
  226. // 列表页面公共参数、方法
  227. const { tableContext, onExportXls } = useListPage(
  228. props.columnsType == 'safetymonitor'
  229. ? {
  230. tableProps: {
  231. // api: list,
  232. columns: props.columnsType ? columns : (props.columns as any[]),
  233. canResize: true,
  234. showTableSetting: false,
  235. showActionColumn: false,
  236. bordered: false,
  237. size: 'small',
  238. scroll: tableScroll,
  239. showIndexColumn: true,
  240. tableLayout: 'auto',
  241. formConfig: {
  242. labelAlign: 'left',
  243. showAdvancedButton: false,
  244. showSubmitButton: false,
  245. showResetButton: false,
  246. baseColProps: {
  247. xs: 24,
  248. sm: 24,
  249. md: 24,
  250. lg: 9,
  251. xl: 7,
  252. xxl: 4,
  253. },
  254. schemas: [
  255. {
  256. field: 'ttime_begin',
  257. label: '开始时间',
  258. component: 'DatePicker',
  259. defaultValue: dayjs().startOf('date'),
  260. required: true,
  261. componentProps: {
  262. showTime: true,
  263. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  264. getPopupContainer: getAutoScrollContainer,
  265. },
  266. colProps: {
  267. span: 4,
  268. },
  269. },
  270. {
  271. field: 'ttime_end',
  272. label: '结束时间',
  273. component: 'DatePicker',
  274. defaultValue: dayjs(),
  275. required: true,
  276. componentProps: {
  277. showTime: true,
  278. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  279. getPopupContainer: getAutoScrollContainer,
  280. },
  281. colProps: {
  282. span: 4,
  283. },
  284. },
  285. {
  286. label: '设备类型',
  287. field: 'dataTypeName',
  288. component: 'ApiSelect',
  289. componentProps: {
  290. api: safetyDeviceList.bind(null, { devicetype: 'safetymonitor', code: 'dataTypeName' }),
  291. labelField: 'name',
  292. valueField: 'code',
  293. onChange: async (e, option) => {
  294. console.log('1111', e, option);
  295. dataTypeName.value = e;
  296. await getDeviceList();
  297. },
  298. },
  299. colProps: {
  300. span: 4,
  301. },
  302. },
  303. {
  304. label: '查询设备',
  305. field: 'gdeviceid',
  306. component: 'Select',
  307. defaultValue: deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
  308. required: true,
  309. componentProps: {
  310. showSearch: true,
  311. filterOption: (input: string, option: any) => {
  312. return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
  313. },
  314. options: deviceOptions,
  315. onChange: (e, option) => {
  316. if (option && (option['strinstallpos'] || option['strtype'] || option['devicekind']))
  317. historyType.value = option['strtype'] || option['devicekind'];
  318. if (option['strtype']) deviceTypeStr.value = option['strtype'];
  319. stationType.value = option['stationtype'];
  320. nextTick(async () => {
  321. await getDataSource();
  322. });
  323. },
  324. },
  325. colProps: {
  326. span: 4,
  327. },
  328. },
  329. {
  330. label: '间隔时间',
  331. field: 'skip',
  332. component: 'Select',
  333. defaultValue: '8',
  334. componentProps: {
  335. options: [
  336. {
  337. label: '1秒',
  338. value: '1',
  339. },
  340. {
  341. label: '5秒',
  342. value: '2',
  343. },
  344. {
  345. label: '10秒',
  346. value: '3',
  347. },
  348. {
  349. label: '30秒',
  350. value: '4',
  351. },
  352. {
  353. label: '1分钟',
  354. value: '5',
  355. },
  356. {
  357. label: '10分钟',
  358. value: '6',
  359. },
  360. {
  361. label: '30分钟',
  362. value: '7',
  363. },
  364. {
  365. label: '1小时',
  366. value: '8',
  367. },
  368. ],
  369. },
  370. colProps: {
  371. span: 4,
  372. },
  373. },
  374. ],
  375. },
  376. pagination: {
  377. current: 1,
  378. pageSize: 10,
  379. pageSizeOptions: ['10', '30', '50', '100'],
  380. showQuickJumper: false,
  381. },
  382. },
  383. exportConfig: {
  384. name: '历史列表',
  385. url: getExportXlsUrl(),
  386. },
  387. }
  388. : {
  389. tableProps: {
  390. // api: list,
  391. columns: props.columnsType ? columns : (props.columns as any[]),
  392. canResize: true,
  393. showTableSetting: false,
  394. showActionColumn: false,
  395. bordered: false,
  396. size: 'small',
  397. scroll: tableScroll,
  398. showIndexColumn: true,
  399. tableLayout: 'auto',
  400. formConfig: {
  401. labelAlign: 'left',
  402. showAdvancedButton: false,
  403. showSubmitButton: false,
  404. showResetButton: false,
  405. baseColProps: {
  406. xs: 24,
  407. sm: 24,
  408. md: 24,
  409. lg: 9,
  410. xl: 7,
  411. xxl: 4,
  412. },
  413. schemas: [
  414. {
  415. field: 'ttime_begin',
  416. label: '开始时间',
  417. component: 'DatePicker',
  418. defaultValue: dayjs().startOf('date'),
  419. required: true,
  420. componentProps: {
  421. showTime: true,
  422. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  423. getPopupContainer: getAutoScrollContainer,
  424. },
  425. colProps: {
  426. span: 4,
  427. },
  428. },
  429. {
  430. field: 'ttime_end',
  431. label: '结束时间',
  432. component: 'DatePicker',
  433. defaultValue: dayjs(),
  434. required: true,
  435. componentProps: {
  436. showTime: true,
  437. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  438. getPopupContainer: getAutoScrollContainer,
  439. },
  440. colProps: {
  441. span: 4,
  442. },
  443. },
  444. {
  445. label: '查询设备',
  446. field: 'gdeviceid',
  447. component: 'Select',
  448. defaultValue: deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
  449. required: true,
  450. componentProps: {
  451. showSearch: true,
  452. filterOption: (input: string, option: any) => {
  453. return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
  454. },
  455. options: deviceOptions,
  456. onChange: (e, option) => {
  457. if (option && (option['strinstallpos'] || option['strtype'] || option['devicekind']))
  458. historyType.value = option['strtype'] || option['devicekind'];
  459. if (option['strtype']) deviceTypeStr.value = option['strtype'];
  460. stationType.value = option['stationtype'];
  461. nextTick(async () => {
  462. await getDataSource();
  463. });
  464. },
  465. },
  466. colProps: {
  467. span: 4,
  468. },
  469. },
  470. {
  471. label: '间隔时间',
  472. field: 'skip',
  473. component: 'Select',
  474. defaultValue: '8',
  475. componentProps: {
  476. options: [
  477. {
  478. label: '1秒',
  479. value: '1',
  480. },
  481. {
  482. label: '5秒',
  483. value: '2',
  484. },
  485. {
  486. label: '10秒',
  487. value: '3',
  488. },
  489. {
  490. label: '30秒',
  491. value: '4',
  492. },
  493. {
  494. label: '1分钟',
  495. value: '5',
  496. },
  497. {
  498. label: '10分钟',
  499. value: '6',
  500. },
  501. {
  502. label: '30分钟',
  503. value: '7',
  504. },
  505. {
  506. label: '1小时',
  507. value: '8',
  508. },
  509. ],
  510. },
  511. colProps: {
  512. span: 4,
  513. },
  514. },
  515. ],
  516. },
  517. pagination: {
  518. current: 1,
  519. pageSize: 10,
  520. pageSizeOptions: ['10', '30', '50', '100'],
  521. showQuickJumper: false,
  522. },
  523. },
  524. exportConfig: {
  525. name: '历史列表',
  526. url: getExportXlsUrl(),
  527. },
  528. }
  529. );
  530. //注册table数据
  531. const [registerTable, { reload, setLoading, getForm, setColumns, getPaginationRef, setPagination }] = tableContext;
  532. watchEffect(() => {
  533. if (historyTable.value && dataSource) {
  534. const data = dataSource.value || [];
  535. emit('change', data);
  536. }
  537. });
  538. onMounted(async () => {
  539. await getDeviceList();
  540. if (deviceOptions.value[0]) {
  541. stationType.value = deviceOptions.value[0]['stationtype'];
  542. historyType.value = deviceOptions.value[0]['strtype'] || deviceOptions.value[0]['devicekind'];
  543. nextTick(async () => {
  544. await getDataSource();
  545. });
  546. }
  547. watch([() => getPaginationRef()['current'], () => getPaginationRef()['pageSize']], async () => {
  548. if (deviceOptions.value[0]) {
  549. if (deviceOptions.value[0]) {
  550. await getDataSource();
  551. }
  552. }
  553. });
  554. });
  555. defineExpose({ setLoading });
  556. </script>
  557. <style scoped lang="less">
  558. @import '/@/design/theme.less';
  559. :deep(.@{ventSpace}-table-body) {
  560. height: auto !important;
  561. }
  562. :deep(.zxm-picker) {
  563. height: 30px !important;
  564. }
  565. .history-table {
  566. width: 100%;
  567. :deep(.jeecg-basic-table-form-container) {
  568. .@{ventSpace}-form {
  569. padding: 0 !important;
  570. border: none !important;
  571. margin-bottom: 0 !important;
  572. .@{ventSpace}-picker,
  573. .@{ventSpace}-select-selector {
  574. width: 100% !important;
  575. height: 100%;
  576. background: #00000017;
  577. border: 1px solid #b7b7b7;
  578. input,
  579. .@{ventSpace}-select-selection-item,
  580. .@{ventSpace}-picker-suffix {
  581. color: #fff;
  582. }
  583. .@{ventSpace}-select-selection-placeholder {
  584. color: #ffffffaa;
  585. }
  586. }
  587. }
  588. .@{ventSpace}-table-title {
  589. min-height: 0 !important;
  590. }
  591. }
  592. .pagination-box {
  593. display: flex;
  594. justify-content: flex-end;
  595. align-items: center;
  596. .page-num {
  597. border: 1px solid #0090d8;
  598. padding: 4px 8px;
  599. margin-right: 5px;
  600. color: #0090d8;
  601. }
  602. .btn {
  603. margin-right: 10px;
  604. }
  605. }
  606. }
  607. // :deep(.zxm-select-selector){
  608. // height: 42px !important;
  609. // }
  610. </style>