HistoryTable.vue 16 KB

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