HistoryTable.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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 getDeviceListApi = (params) => defHttp.post({ url: '/ventanaly-device/monitor/device', 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 getDeviceListApi({ devicetype: 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. const res = await getDeviceListApi({
  186. sysId: props.sysId,
  187. devicetype: props.deviceType.startsWith('vehicle') ? 'location_normal' : props.deviceType,
  188. pageSize: 10000,
  189. });
  190. if (res['records'] && res['records'].length > 0) {
  191. result = res['records'];
  192. } else if (res['msgTxt'] && res['msgTxt'][0] && res['msgTxt'][0]['datalist']) {
  193. result = res['msgTxt'][0]['datalist'];
  194. }
  195. }
  196. if (result) {
  197. deviceOptions.value = [];
  198. deviceOptions.value = result.map((item, index) => {
  199. return {
  200. label: item['strinstallpos'],
  201. value: item['id'] || item['deviceID'],
  202. strtype: item['strtype'] || item['deviceType'],
  203. strinstallpos: item['strinstallpos'],
  204. devicekind: item['devicekind'],
  205. stationtype: item['stationtype'],
  206. };
  207. });
  208. }
  209. await getForm().setFieldsValue({ gdeviceid: props.deviceId ? props.deviceId : deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '' });
  210. nextTick(async () => {
  211. await getDataSource();
  212. });
  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. 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. startTime: formData['ttime_begin'],
  244. endTime: formData['ttime_end'],
  245. deviceId: formData['gdeviceid'],
  246. strtype: props.deviceType + '*',
  247. sysId: props.sysId,
  248. interval: intervalMap.get(formData['skip']) ? intervalMap.get(formData['skip']) : '1h',
  249. isEmployee: props.deviceType.startsWith('vehicle') ? false : true,
  250. };
  251. const result = await defHttp.post({ url: '/ventanaly-device/history/getHistoryData', params: params });
  252. setPagination({ total: Math.abs(result['total']) || 0 });
  253. dataSource.value = result['records'] || [];
  254. }
  255. setLoading(false);
  256. }
  257. // 列表页面公共参数、方法
  258. const { tableContext, onExportXls } = useListPage({
  259. tableProps: {
  260. // api: list,
  261. columns: props.columnsType ? columns : (props.columns as any[]),
  262. canResize: true,
  263. showTableSetting: false,
  264. showActionColumn: false,
  265. bordered: false,
  266. size: 'small',
  267. scroll: tableScroll,
  268. showIndexColumn: true,
  269. formConfig: {
  270. labelAlign: 'left',
  271. showAdvancedButton: false,
  272. showSubmitButton: false,
  273. showResetButton: false,
  274. baseColProps: {
  275. xs: 24,
  276. sm: 24,
  277. md: 24,
  278. lg: 9,
  279. xl: 7,
  280. xxl: 4,
  281. },
  282. schemas:
  283. props.formSchemas.length > 0
  284. ? props.formSchemas
  285. : [
  286. {
  287. field: 'ttime_begin',
  288. label: '开始时间',
  289. component: 'DatePicker',
  290. defaultValue: dayjs().startOf('date'),
  291. required: true,
  292. componentProps: {
  293. showTime: true,
  294. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  295. getPopupContainer: getAutoScrollContainer,
  296. },
  297. colProps: {
  298. span: 4,
  299. },
  300. },
  301. {
  302. field: 'ttime_end',
  303. label: '结束时间',
  304. component: 'DatePicker',
  305. defaultValue: dayjs(),
  306. required: true,
  307. componentProps: {
  308. showTime: true,
  309. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  310. getPopupContainer: getAutoScrollContainer,
  311. },
  312. colProps: {
  313. span: 4,
  314. },
  315. },
  316. {
  317. label: '查询设备',
  318. field: 'gdeviceid',
  319. component: 'Select',
  320. defaultValue: deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
  321. required: true,
  322. componentProps: {
  323. options: deviceOptions,
  324. onChange: (e, option) => {
  325. if (option && (option['strinstallpos'] || option['strtype'] || option['devicekind']))
  326. historyType.value = option['strtype'] || option['devicekind'];
  327. if (option['strtype']) deviceTypeStr.value = option['strtype'];
  328. stationType.value = option['stationtype'];
  329. },
  330. },
  331. colProps: {
  332. span: 4,
  333. },
  334. },
  335. {
  336. label: '间隔时间',
  337. field: 'skip',
  338. component: 'Select',
  339. defaultValue: '8',
  340. componentProps: {
  341. options: [
  342. {
  343. label: '1秒',
  344. value: '1',
  345. },
  346. {
  347. label: '5秒',
  348. value: '2',
  349. },
  350. {
  351. label: '10秒',
  352. value: '3',
  353. },
  354. {
  355. label: '30秒',
  356. value: '4',
  357. },
  358. {
  359. label: '1分钟',
  360. value: '5',
  361. },
  362. {
  363. label: '10分钟',
  364. value: '6',
  365. },
  366. {
  367. label: '30分钟',
  368. value: '7',
  369. },
  370. {
  371. label: '1小时',
  372. value: '8',
  373. },
  374. ],
  375. },
  376. colProps: {
  377. span: 4,
  378. },
  379. },
  380. ],
  381. // fieldMapToTime: [['tickectDate', ['ttime_begin', 'ttime_end'], '']],
  382. },
  383. // fetchSetting: {
  384. // listField: 'datalist',
  385. // totalField: 'datalist.total',
  386. // },
  387. pagination: {
  388. current: 1,
  389. pageSize: 10,
  390. pageSizeOptions: ['10', '30', '50', '100'],
  391. showQuickJumper: false,
  392. },
  393. // beforeFetch(params) {
  394. // params.strtype = deviceTypeStr.value
  395. // ? deviceTypeStr.value
  396. // : deviceOptions.value[0]['strtype']
  397. // ? deviceOptions.value[0]['strtype']
  398. // : props.deviceType + '*';
  399. // if (props.sysId) {
  400. // params.sysId = props.sysId;
  401. // }
  402. // return params;
  403. // },
  404. // afterFetch(result) {
  405. // const resultItems = result['records'];
  406. // resultItems.map((item) => {
  407. // Object.assign(item, item['readData']);
  408. // });
  409. // console.log('result---------------->', result);
  410. // return resultItems;
  411. // },
  412. },
  413. exportConfig: {
  414. name: '历史列表',
  415. url: getExportXlsUrl(),
  416. },
  417. });
  418. //注册table数据
  419. const [registerTable, { reload, setLoading, getForm, setColumns, getPaginationRef, setPagination }] = tableContext;
  420. watchEffect(() => {
  421. if (historyTable.value && dataSource) {
  422. const data = dataSource.value || [];
  423. emit('change', data);
  424. }
  425. });
  426. onMounted(async () => {
  427. await getDeviceList();
  428. if (deviceOptions.value[0]) {
  429. stationType.value = deviceOptions.value[0]['stationtype'];
  430. historyType.value = deviceOptions.value[0]['strtype'] || deviceOptions.value[0]['devicekind'];
  431. nextTick(() => {
  432. getDataSource();
  433. });
  434. }
  435. watch([() => getPaginationRef()['current'], () => getPaginationRef()['pageSize']], () => {
  436. getDataSource();
  437. });
  438. });
  439. defineExpose({ setLoading });
  440. </script>
  441. <style scoped lang="less">
  442. @import '/@/design/vent/color.less';
  443. :deep(.@{ventSpace}-table-body) {
  444. height: auto !important;
  445. }
  446. :deep(.zxm-picker) {
  447. height: 30px !important;
  448. }
  449. .history-table {
  450. width: 100%;
  451. :deep(.jeecg-basic-table-form-container) {
  452. .@{ventSpace}-form {
  453. padding: 0 !important;
  454. border: none !important;
  455. margin-bottom: 0 !important;
  456. .@{ventSpace}-picker,
  457. .@{ventSpace}-select-selector {
  458. width: 100% !important;
  459. height: 100%;
  460. background: #00000017;
  461. border: 1px solid #b7b7b7;
  462. input,
  463. .@{ventSpace}-select-selection-item,
  464. .@{ventSpace}-picker-suffix {
  465. color: #fff;
  466. }
  467. .@{ventSpace}-select-selection-placeholder {
  468. color: #ffffffaa;
  469. }
  470. }
  471. }
  472. .@{ventSpace}-table-title {
  473. min-height: 0 !important;
  474. }
  475. }
  476. .pagination-box {
  477. display: flex;
  478. justify-content: flex-end;
  479. align-items: center;
  480. .page-num {
  481. border: 1px solid #0090d8;
  482. padding: 4px 8px;
  483. margin-right: 5px;
  484. color: #0090d8;
  485. }
  486. .btn {
  487. margin-right: 10px;
  488. }
  489. }
  490. }
  491. </style>