HistoryTable.vue 16 KB

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