HistoryTable.vue 18 KB

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