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. deviceArr: {
  50. type: Array,
  51. // required: true,
  52. default: () => [],
  53. },
  54. designScope: {
  55. type: String,
  56. },
  57. sysId: {
  58. type: String,
  59. },
  60. scroll: {
  61. type: Object,
  62. default: { y: 0 }
  63. },
  64. formSchemas: {
  65. type: Array<FormSchema>,
  66. default: () => []
  67. }
  68. });
  69. const historyType = ref('')
  70. const columns = ref([])
  71. const tableScroll = props.scroll.y ? ref({ y: props.scroll.y - 100 }) : ref({})
  72. let deviceOptions = ref([])
  73. let deviceList = <any[]>[]
  74. watch(
  75. () => {
  76. return props.columnsType;
  77. },
  78. async(newVal) => {
  79. if (!newVal) return
  80. if(historyTable.value) getForm().resetFields()
  81. await getDeviceList()
  82. const column = getTableHeaderColumns(newVal.includes('_history') ? newVal : newVal + '_history')
  83. if (column && column.length < 1) {
  84. const arr = newVal.split('_')
  85. console.log('历史记录列表表头------------>', arr[0] + '_monitor')
  86. columns.value = getTableHeaderColumns(arr[0] + '_history');
  87. } else {
  88. columns.value = column
  89. }
  90. if(historyTable.value) reload()
  91. },
  92. {
  93. immediate: true
  94. }
  95. );
  96. watch(historyType, (type) => {
  97. if (!type) return
  98. // if (historyTable.value) getForm().resetFields()
  99. const column = getTableHeaderColumns(type.includes('_history') ? type : type + '_history')
  100. if (column && column.length < 1) {
  101. const arr = type.split('_')
  102. columns.value = getTableHeaderColumns(arr[0] + '_history');
  103. } else {
  104. columns.value = column
  105. }
  106. setColumns(columns.value)
  107. })
  108. watch(() => props.scroll.y, (newVal) => {
  109. if(newVal){
  110. tableScroll.value = {y: newVal - 100 }
  111. }else{
  112. tableScroll.value = {}
  113. }
  114. })
  115. async function getDeviceList() {
  116. if( props.deviceType.split('_')[1] && props.deviceType.split('_')[1] === 'history') return
  117. let result;
  118. if(globalConfig.History_Type == 'vent'){
  119. debugger;
  120. if(props.deviceListApi && !props.sysId){
  121. const res = await props.deviceListApi()
  122. if (res['records'] && res['records'].length > 0) result = res['records']
  123. }else{
  124. result = await defHttp.get({ url: '/safety/ventanalyManageSystem/linkdevicelist', params: { sysId: props.sysId, deviceType: props.deviceType, pageSize: 9999 } })
  125. }
  126. }else {
  127. result = await defHttp.get({ url: '/safety/ventanalyManageSystem/linkdevicelist', params: { sysId: props.sysId, deviceType: props.deviceType.startsWith('vehicle') ? 'location_normal' : props.deviceType } })
  128. }
  129. if(result){
  130. deviceOptions.value = []
  131. deviceOptions.value = result.map((item) => {
  132. return {label: item['strinstallpos'], value: item['id'], strtype: item['strtype'], strinstallpos: item['strinstallpos'], devicekind: item['devicekind'] }
  133. // return { label: item['strname'], value: item['id']}
  134. })
  135. }
  136. (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'] : ''})
  137. }
  138. loading.value = true
  139. // 列表页面公共参数、方法
  140. const { tableContext } = useListPage(
  141. globalConfig.History_Type == 'vent' ? {
  142. tableProps: {
  143. api: list,
  144. columns: props.columnsType ? columns : (props.columns as any[]),
  145. canResize: true,
  146. showTableSetting: false,
  147. showActionColumn: false,
  148. bordered: false,
  149. size: 'small',
  150. scroll: tableScroll,
  151. showIndexColumn: true,
  152. formConfig: {
  153. labelAlign: 'left',
  154. showAdvancedButton: false,
  155. baseColProps: {
  156. // offset: 0.5,
  157. xs: 24,
  158. sm: 24,
  159. md: 24,
  160. lg: 9,
  161. xl: 7,
  162. xxl: 4,
  163. },
  164. schemas: props.formSchemas.length > 0 ? props.formSchemas : [
  165. {
  166. label: '查询日期',
  167. field: 'tData',
  168. component: 'DatePicker',
  169. defaultValue: dayjs(),
  170. colProps: {
  171. span: 4,
  172. },
  173. componentProps: {
  174. valueFormat: 'YYYY-MM-DD',
  175. },
  176. },
  177. {
  178. label: '时间区间',
  179. field: 'tickectDate',
  180. component: 'TimeRangePicker',
  181. defaultValue: [dayjs().startOf('date').format('HH:mm:ss'), dayjs().format('HH:mm:ss')],
  182. componentProps: {
  183. placement: 'topLeft',
  184. placeholder: ['开始时间', '结束时间'],
  185. valueFormat: 'HH:mm:ss',
  186. },
  187. colProps: {
  188. span: 4,
  189. },
  190. },
  191. {
  192. label: '查询设备',
  193. field: 'gdeviceid',
  194. component: 'Select',
  195. defaultValue: deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
  196. required: true,
  197. componentProps: {
  198. options: deviceOptions,
  199. onChange: (e, option) => {
  200. if (option && (option['strinstallpos'] || option['strtype'] || option['devicekind'])) historyType.value = option['strtype'] || option['devicekind']
  201. },
  202. },
  203. colProps: {
  204. span: 4,
  205. },
  206. },
  207. {
  208. label: '间隔时间',
  209. field: 'skip',
  210. component: 'Select',
  211. defaultValue: 5,
  212. componentProps: {
  213. options: [
  214. {
  215. label: '5秒',
  216. value: '1',
  217. },
  218. {
  219. label: '10秒',
  220. value: '2',
  221. },
  222. {
  223. label: '30秒',
  224. value: '3',
  225. },
  226. {
  227. label: '1分钟',
  228. value: '4',
  229. },
  230. {
  231. label: '5分钟',
  232. value: '5',
  233. },
  234. {
  235. label: '10分钟',
  236. value: '6',
  237. },
  238. {
  239. label: '30分钟',
  240. value: '7',
  241. },
  242. {
  243. label: '1小时',
  244. value: '8',
  245. },
  246. ],
  247. },
  248. colProps: {
  249. span: 4,
  250. },
  251. },
  252. ],
  253. fieldMapToTime: [['tickectDate', ['ttime_begin', 'ttime_end'], '']],
  254. },
  255. fetchSetting: {
  256. listField: 'datalist',
  257. totalField: 'datalist.total',
  258. },
  259. pagination: {
  260. current: 1,
  261. pageSize: 10,
  262. pageSizeOptions: ['10', '30', '50', '100'],
  263. showQuickJumper: false
  264. },
  265. beforeFetch(params) {
  266. params.strtype = props.deviceType + '*';
  267. if(props.sysId){
  268. params.sysId = props.sysId;
  269. }
  270. },
  271. afterFetch(result) {
  272. const resultItems = result['records']
  273. resultItems.map((item) => {
  274. Object.assign(item, item['readData']);
  275. });
  276. console.log('result---------------->', result)
  277. return resultItems;
  278. },
  279. },
  280. }: {
  281. tableProps: {
  282. api: list,
  283. columns: props.columnsType ? columns : (props.columns as any[]),
  284. canResize: true,
  285. showTableSetting: false,
  286. showActionColumn: false,
  287. bordered: false,
  288. size: 'small',
  289. scroll: tableScroll,
  290. showIndexColumn: true,
  291. formConfig: {
  292. labelAlign: 'left',
  293. showAdvancedButton: false,
  294. // autoAdvancedCol: 2,
  295. baseColProps: {
  296. // offset: 0.5,
  297. xs: 24,
  298. sm: 24,
  299. md: 24,
  300. lg: 9,
  301. xl: 7,
  302. xxl: 4,
  303. },
  304. schemas: props.formSchemas.length > 0 ? props.formSchemas : [
  305. {
  306. field: 'startTime',
  307. label: '开始时间',
  308. component: 'DatePicker',
  309. defaultValue: dayjs().startOf('date'),
  310. required: true,
  311. componentProps: {
  312. showTime: true,
  313. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  314. getPopupContainer: getAutoScrollContainer,
  315. },
  316. },
  317. {
  318. field: 'endTime',
  319. label: '结束时间',
  320. component: 'DatePicker',
  321. defaultValue: dayjs(),
  322. required: true,
  323. componentProps: {
  324. showTime: true,
  325. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  326. getPopupContainer: getAutoScrollContainer,
  327. },
  328. },
  329. {
  330. label: '查询设备',
  331. field: 'deviceId',
  332. component: 'Select',
  333. defaultValue: deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
  334. required: true,
  335. componentProps: {
  336. options: deviceOptions,
  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. // numberToString: true,
  342. onChange: (e, option) => {
  343. if (option && (option['strinstallpos'] || option['strtype'] || option['devicekind'])) historyType.value = option['strtype'] || option['devicekind']
  344. },
  345. },
  346. // componentProps: ({ formModel }) => {
  347. // return {
  348. // options: deviceOptions.value,
  349. // // api: () => defHttp.get({ url: '/safety/ventanalyManageSystem/linkdevicelist', params: { sysId: props.sysId, deviceType: props.deviceType.startsWith('vehicle') ? 'location_normal' : props.deviceType } }),
  350. // // resultField: 'result',
  351. // // labelField: 'strinstallpos',
  352. // // valueField: 'id',
  353. // // onChange: (e, option) => {
  354. // // if(option && (option['strtype'] || option['devicekind'])) historyType.value = option['strtype'] || option['devicekind']
  355. // // },
  356. // }
  357. // },
  358. },
  359. {
  360. label: '间隔时间',
  361. field: 'interval',
  362. component: 'Select',
  363. defaultValue: '30s',
  364. componentProps: {
  365. options: [
  366. {
  367. label: '1秒',
  368. value: '1s',
  369. },
  370. {
  371. label: '5秒',
  372. value: '5s',
  373. },
  374. {
  375. label: '10秒',
  376. value: '10s',
  377. },
  378. {
  379. label: '30秒',
  380. value: '30s',
  381. },
  382. {
  383. label: '1分钟',
  384. value: '1m',
  385. },
  386. {
  387. label: '10分钟',
  388. value: '10m',
  389. },
  390. {
  391. label: '30分钟',
  392. value: '30m',
  393. },
  394. {
  395. label: '1小时',
  396. value: '1h',
  397. },
  398. ],
  399. },
  400. },
  401. ],
  402. },
  403. pagination: {
  404. current: 1,
  405. pageSize: 10,
  406. pageSizeOptions: ['10', '30', '50', '100'],
  407. showQuickJumper: false
  408. },
  409. // pagination: false,
  410. fetchSetting: {
  411. totalField: 'total',
  412. // 每页显示多少条
  413. sizeField: 'pageSize',
  414. // 请求结果列表字段 支持 a.b.c
  415. pageField: 'pageNo'
  416. },
  417. beforeFetch(params) {
  418. params.strtype = props.deviceType + '*';
  419. if (props.sysId) {
  420. params.sysId = props.sysId;
  421. }
  422. if(params.interval){
  423. params.interval = params.interval
  424. }else{
  425. params.interval = '1m'
  426. }
  427. if (props.deviceType.startsWith('vehicle')) {
  428. params['isEmployee'] = false
  429. } else if (props.deviceType.startsWith('location')) {
  430. params['isEmployee'] = true
  431. }
  432. },
  433. afterFetch(result) {
  434. return result;
  435. },
  436. },
  437. }
  438. );
  439. //注册table数据
  440. const [registerTable, { getDataSource, reload, setLoading, getForm, setColumns }] = tableContext;
  441. watchEffect(() => {
  442. if (historyTable.value && getDataSource) {
  443. const data = getDataSource() || [];
  444. emit('change', data);
  445. console.log('[ data ] >', data);
  446. }
  447. });
  448. onMounted(async() => {
  449. if (!props.columnsType) {
  450. await getDeviceList()
  451. if(deviceOptions.value[0]) historyType.value = deviceOptions.value[0]['strtype'] || deviceOptions.value[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>