HistoryTable.vue 16 KB

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