HistoryTable.vue 15 KB

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