HistoryTable.vue 14 KB

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