HistoryTable.vue 16 KB

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