HistoryTable.vue 18 KB

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