HistoryTable.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. debugger
  92. if (!type) return
  93. // if (historyTable.value) getForm().resetFields()
  94. const column = getTableHeaderColumns(type.includes('_history') ? type : type + '_history')
  95. if (column && column.length < 1) {
  96. const arr = type.split('_')
  97. columns.value = getTableHeaderColumns(arr[0] + '_history');
  98. } else {
  99. columns.value = column
  100. }
  101. setColumns(columns.value)
  102. })
  103. watch(() => props.scroll.y, (newVal) => {
  104. if(newVal){
  105. tableScroll.value = {y: newVal - 100 }
  106. }else{
  107. tableScroll.value = {}
  108. }
  109. })
  110. async function getDeviceList() {
  111. let result;
  112. if(globalConfig.History_Type == 'vent'){
  113. result = await defHttp.get({ url: '/safety/ventanalyManageSystem/linkdevicelist', params: { sysId: props.sysId, deviceType: props.deviceType } })
  114. }else {
  115. result = await defHttp.get({ url: '/safety/ventanalyManageSystem/linkdevicelist', params: { sysId: props.sysId, deviceType: props.deviceType.startsWith('vehicle') ? 'location_normal' : props.deviceType } })
  116. }
  117. if(result){
  118. deviceOptions = []
  119. deviceOptions = result.map((item) => {
  120. return {label: item['strinstallpos'], value: item['id'], strtype: item['strtype'], strinstallpos: item['strinstallpos'], devicekind: item['devicekind'] }
  121. // return { label: item['strname'], value: item['id']}
  122. })
  123. }
  124. }
  125. await getDeviceList()
  126. loading.value = true
  127. // 列表页面公共参数、方法
  128. const { tableContext } = useListPage(
  129. globalConfig.History_Type == 'vent' ? {
  130. tableProps: {
  131. api: list,
  132. columns: props.columnsType ? columns : (props.columns as any[]),
  133. canResize: true,
  134. showTableSetting: false,
  135. showActionColumn: false,
  136. bordered: false,
  137. size: 'small',
  138. scroll: tableScroll,
  139. showIndexColumn: true,
  140. formConfig: {
  141. labelAlign: 'left',
  142. showAdvancedButton: false,
  143. baseColProps: {
  144. // offset: 0.5,
  145. xs: 24,
  146. sm: 24,
  147. md: 24,
  148. lg: 9,
  149. xl: 7,
  150. xxl: 4,
  151. },
  152. schemas: props.formSchemas.length > 0 ? props.formSchemas : [
  153. {
  154. label: '查询日期',
  155. field: 'tData',
  156. component: 'DatePicker',
  157. defaultValue: dayjs(),
  158. colProps: {
  159. span: 4,
  160. },
  161. componentProps: {
  162. valueFormat: 'YYYY-MM-DD',
  163. },
  164. },
  165. {
  166. label: '时间区间',
  167. field: 'tickectDate',
  168. component: 'TimeRangePicker',
  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: '1分钟',
  225. value: '3',
  226. },
  227. {
  228. label: '5分钟',
  229. value: '4',
  230. },
  231. {
  232. label: '10分钟',
  233. value: '5',
  234. },
  235. ],
  236. },
  237. colProps: {
  238. span: 4,
  239. },
  240. },
  241. ],
  242. fieldMapToTime: [['tickectDate', ['ttime_begin', 'ttime_end'], '']],
  243. },
  244. fetchSetting: {
  245. listField: 'datalist',
  246. totalField: 'datalist.total',
  247. },
  248. pagination: {
  249. current: 1,
  250. pageSize: 10,
  251. pageSizeOptions: ['10', '30', '50', '100'],
  252. showQuickJumper: false
  253. },
  254. beforeFetch(params) {
  255. params.strtype = props.deviceType + '*';
  256. if(props.sysId){
  257. params.sysId = props.sysId;
  258. }
  259. },
  260. afterFetch(result) {
  261. const resultItems = result['records']
  262. resultItems.map((item) => {
  263. Object.assign(item, item['readData']);
  264. });
  265. console.log('result---------------->', result)
  266. return resultItems;
  267. },
  268. },
  269. }: {
  270. tableProps: {
  271. api: list,
  272. columns: props.columnsType ? columns : (props.columns as any[]),
  273. canResize: true,
  274. showTableSetting: false,
  275. showActionColumn: false,
  276. bordered: false,
  277. size: 'small',
  278. scroll: tableScroll,
  279. showIndexColumn: true,
  280. formConfig: {
  281. labelAlign: 'left',
  282. showAdvancedButton: false,
  283. // autoAdvancedCol: 2,
  284. baseColProps: {
  285. // offset: 0.5,
  286. xs: 24,
  287. sm: 24,
  288. md: 24,
  289. lg: 9,
  290. xl: 7,
  291. xxl: 4,
  292. },
  293. schemas: props.formSchemas.length > 0 ? props.formSchemas : [
  294. {
  295. field: 'startTime',
  296. label: '开始时间',
  297. component: 'DatePicker',
  298. required: true,
  299. componentProps: {
  300. showTime: true,
  301. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  302. getPopupContainer: getAutoScrollContainer,
  303. },
  304. },
  305. {
  306. field: 'endTime',
  307. label: '结束时间',
  308. component: 'DatePicker',
  309. required: true,
  310. componentProps: {
  311. showTime: true,
  312. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  313. getPopupContainer: getAutoScrollContainer,
  314. },
  315. },
  316. {
  317. label: '查询设备',
  318. field: 'deviceId',
  319. component: 'Select',
  320. defaultValue: deviceOptions[0] ? deviceOptions[0]['value'] : '',
  321. required: true,
  322. componentProps: {
  323. options: deviceOptions,
  324. // api: () => defHttp.get({ url: '/safety/ventanalyManageSystem/linkdevicelist', params: { sysId: props.sysId, deviceType: props.deviceType.startsWith('vehicle') ? 'location_normal' : props.deviceType } }),
  325. // // resultField: 'result',
  326. // labelField: 'strinstallpos',
  327. // valueField: 'id',
  328. // numberToString: true,
  329. onChange: (e, option) => {
  330. if (option && (option['strinstallpos'] || option['strtype'] || option['devicekind'])) historyType.value = option['strtype'] || option['devicekind']
  331. },
  332. },
  333. // componentProps: ({ formModel }) => {
  334. // return {
  335. // options: deviceOptions.value,
  336. // // api: () => defHttp.get({ url: '/safety/ventanalyManageSystem/linkdevicelist', params: { sysId: props.sysId, deviceType: props.deviceType.startsWith('vehicle') ? 'location_normal' : props.deviceType } }),
  337. // // resultField: 'result',
  338. // // labelField: 'strinstallpos',
  339. // // valueField: 'id',
  340. // // onChange: (e, option) => {
  341. // // if(option && (option['strtype'] || option['devicekind'])) historyType.value = option['strtype'] || option['devicekind']
  342. // // },
  343. // }
  344. // },
  345. },
  346. {
  347. label: '间隔时间',
  348. field: 'interval',
  349. component: 'Select',
  350. defaultValue: '30s',
  351. componentProps: {
  352. options: [
  353. {
  354. label: '1秒',
  355. value: '1s',
  356. },
  357. {
  358. label: '5秒',
  359. value: '5s',
  360. },
  361. {
  362. label: '10秒',
  363. value: '10s',
  364. },
  365. {
  366. label: '30秒',
  367. value: '30s',
  368. },
  369. {
  370. label: '1分钟',
  371. value: '1m',
  372. },
  373. {
  374. label: '10分钟',
  375. value: '10m',
  376. },
  377. {
  378. label: '30分钟',
  379. value: '30m',
  380. },
  381. {
  382. label: '1小时',
  383. value: '1h',
  384. },
  385. ],
  386. },
  387. },
  388. ],
  389. },
  390. pagination: {
  391. current: 1,
  392. pageSize: 10,
  393. pageSizeOptions: ['10', '30', '50', '100'],
  394. showQuickJumper: false
  395. },
  396. // pagination: false,
  397. fetchSetting: {
  398. totalField: 'total',
  399. // 每页显示多少条
  400. sizeField: 'pageSize',
  401. // 请求结果列表字段 支持 a.b.c
  402. pageField: 'pageNo'
  403. },
  404. beforeFetch(params) {
  405. params.strtype = props.deviceType + '*';
  406. if (props.sysId) {
  407. params.sysId = props.sysId;
  408. }
  409. if(params.interval){
  410. params.interval = params.interval
  411. }else{
  412. params.interval = '1m'
  413. }
  414. if (props.deviceType.startsWith('vehicle')) {
  415. params['isEmployee'] = false
  416. } else if (props.deviceType.startsWith('location')) {
  417. params['isEmployee'] = true
  418. }
  419. },
  420. afterFetch(result) {
  421. return result;
  422. },
  423. },
  424. }
  425. );
  426. //注册table数据
  427. const [registerTable, { getDataSource, reload, setLoading, getForm, setColumns }] = tableContext;
  428. watchEffect(() => {
  429. if (historyTable.value && getDataSource) {
  430. const data = getDataSource() || [];
  431. emit('change', data);
  432. console.log('[ data ] >', data);
  433. }
  434. });
  435. onMounted(() => {
  436. if (!props.columnsType) {
  437. historyType.value = deviceOptions[0]['strtype'] || deviceOptions[0]['devicekind']
  438. }
  439. })
  440. defineExpose({ setLoading })
  441. </script>
  442. <style scoped lang="less">
  443. @import '/@/design/vent/color.less';
  444. :deep(.@{ventSpace}-table-body) {
  445. height: auto !important;
  446. }
  447. :deep(.zxm-picker){
  448. height: 30px !important;
  449. }
  450. .history-table {
  451. width: 100%;
  452. :deep(.jeecg-basic-table-form-container) {
  453. .@{ventSpace}-form {
  454. padding: 0 !important;
  455. border: none !important;
  456. margin-bottom: 0 !important;
  457. .@{ventSpace}-picker,
  458. .@{ventSpace}-select-selector {
  459. width: 100% !important;
  460. height: 100%;
  461. background: #00000017;
  462. border: 1px solid #b7b7b7;
  463. input,
  464. .@{ventSpace}-select-selection-item,
  465. .@{ventSpace}-picker-suffix {
  466. color: #fff;
  467. }
  468. .@{ventSpace}-select-selection-placeholder {
  469. color: #ffffffaa;
  470. }
  471. }
  472. }
  473. .@{ventSpace}-table-title {
  474. min-height: 0 !important;
  475. }
  476. }
  477. .pagination-box{
  478. display: flex;
  479. justify-content: flex-end;
  480. align-items: center;
  481. .page-num{
  482. border: 1px solid #0090D8;
  483. padding: 4px 8px;
  484. margin-right: 5px;
  485. color: #0090D8;
  486. }
  487. .btn{
  488. margin-right: 10px;
  489. }
  490. }
  491. }
  492. </style>