HistoryTable.vue 16 KB

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