1
0

HistoryTable.vue 15 KB

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