HistoryTable.vue 17 KB

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