HistoryTable.vue 15 KB

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