HistoryTable.vue 16 KB

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