HistoryTable.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <template>
  2. <div class="history-table">
  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. const globalConfig = inject('globalConfig');
  21. const historyTable = ref();
  22. const dataSource = ref([])
  23. const list = (params) => {
  24. if(globalConfig.History_Type == 'vent') {
  25. return defHttp.get({ url: '/safety/ventanalyMonitorData/list', params })
  26. } else {
  27. return defHttp.post({ url: '/ventanaly-device/history/getHistoryData', params })
  28. }
  29. };
  30. const emit = defineEmits(['change']);
  31. const props = defineProps({
  32. columnsType: {
  33. type: String,
  34. },
  35. columns: {
  36. type: Array,
  37. // required: true,
  38. default: () => [],
  39. },
  40. deviceType: {
  41. type: String,
  42. required: true,
  43. },
  44. deviceListApi: {
  45. type: Function,
  46. },
  47. designScope: {
  48. type: String,
  49. },
  50. sysId: {
  51. type: String,
  52. },
  53. scroll: {
  54. type: Object,
  55. default: { y: 0 }
  56. },
  57. formSchemas: {
  58. type: Array<FormSchema>,
  59. default: () => []
  60. }
  61. });
  62. const columns = ref([])
  63. const tableScroll = props.scroll.y ? ref({ y: props.scroll.y - 100 }) : ref({})
  64. watch(
  65. () => {
  66. return props.columnsType;
  67. },
  68. (newVal) => {
  69. if (!newVal) return
  70. if(historyTable.value) getForm().resetFields()
  71. const column = getTableHeaderColumns(newVal.includes('_history') ? newVal : newVal + '_history')
  72. if (column && column.length < 1) {
  73. const arr = newVal.split('_')
  74. const columnKey = arr.reduce((prev, cur, index) => {
  75. if (index !== arr.length - 2) {
  76. return prev + '_' + cur
  77. } else {
  78. return prev
  79. }
  80. })
  81. console.log('历史记录列表表头------------>', arr[0] + '_monitor')
  82. columns.value = getTableHeaderColumns(arr[0] + '_history');
  83. } else {
  84. columns.value = column
  85. }
  86. if(historyTable.value) reload()
  87. },
  88. {
  89. immediate: true
  90. }
  91. );
  92. watch(() => props.scroll.y, (newVal) => {
  93. if(newVal){
  94. tableScroll.value = {y: newVal - 100 }
  95. }else{
  96. tableScroll.value = {}
  97. }
  98. })
  99. // 列表页面公共参数、方法
  100. const { tableContext } = useListPage(
  101. globalConfig.History_Type == 'vent' ? {
  102. tableProps: {
  103. api: list,
  104. columns: props.columnsType ? columns : (props.columns as any[]),
  105. canResize: true,
  106. showTableSetting: false,
  107. showActionColumn: false,
  108. bordered: false,
  109. size: 'small',
  110. scroll: tableScroll,
  111. showIndexColumn: true,
  112. formConfig: {
  113. labelAlign: 'left',
  114. showAdvancedButton: false,
  115. baseColProps: {
  116. // offset: 0.5,
  117. xs: 24,
  118. sm: 24,
  119. md: 24,
  120. lg: 9,
  121. xl: 7,
  122. xxl: 4,
  123. },
  124. schemas: props.formSchemas.length > 0 ? props.formSchemas : [
  125. {
  126. label: '查询日期',
  127. field: 'tData',
  128. component: 'DatePicker',
  129. defaultValue: dayjs(),
  130. colProps: {
  131. span: 4,
  132. },
  133. componentProps: {
  134. valueFormat: 'YYYY-MM-DD',
  135. },
  136. },
  137. {
  138. label: '时间区间',
  139. field: 'tickectDate',
  140. component: 'TimeRangePicker',
  141. componentProps: {
  142. placeholder: ['开始时间', '结束时间'],
  143. valueFormat: 'HH:mm:ss',
  144. },
  145. colProps: {
  146. span: 4,
  147. },
  148. },
  149. {
  150. label: '查询设备',
  151. field: 'gdeviceid',
  152. component: 'ApiSelect',
  153. required: true,
  154. componentProps: {
  155. api: () => defHttp.get({ url: '/safety/ventanalyManageSystem/linkdevicelist', params: { sysId: props.sysId, deviceType: props.deviceType } }),
  156. // resultField: 'result',
  157. labelField: 'strinstallpos',
  158. valueField: 'id',
  159. // numberToString: true,
  160. },
  161. colProps: {
  162. span: 4,
  163. },
  164. },
  165. {
  166. label: '间隔时间',
  167. field: 'skip',
  168. component: 'Select',
  169. componentProps: {
  170. options: [
  171. {
  172. label: '5秒',
  173. value: '1',
  174. },
  175. {
  176. label: '10秒',
  177. value: '2',
  178. },
  179. {
  180. label: '1分钟',
  181. value: '3',
  182. },
  183. {
  184. label: '5分钟',
  185. value: '4',
  186. },
  187. {
  188. label: '10分钟',
  189. value: '5',
  190. },
  191. ],
  192. },
  193. colProps: {
  194. span: 4,
  195. },
  196. },
  197. ],
  198. fieldMapToTime: [['tickectDate', ['ttime_begin', 'ttime_end'], '']],
  199. },
  200. fetchSetting: {
  201. listField: 'datalist',
  202. totalField: 'datalist.total',
  203. },
  204. pagination: {
  205. current: 1,
  206. pageSize: 10,
  207. pageSizeOptions: ['10', '30', '50', '100'],
  208. showQuickJumper: false
  209. },
  210. beforeFetch(params) {
  211. params.strtype = props.deviceType + '*';
  212. if(props.sysId){
  213. params.sysId = props.sysId;
  214. }
  215. },
  216. afterFetch(result) {
  217. const resultItems = result['records']
  218. resultItems.map((item) => {
  219. Object.assign(item, item['readData']);
  220. });
  221. console.log('result---------------->', result)
  222. return resultItems;
  223. },
  224. },
  225. }: {
  226. tableProps: {
  227. api: list,
  228. columns: props.columnsType ? columns : (props.columns as any[]),
  229. canResize: true,
  230. showTableSetting: false,
  231. showActionColumn: false,
  232. bordered: false,
  233. size: 'small',
  234. scroll: tableScroll,
  235. showIndexColumn: true,
  236. formConfig: {
  237. labelAlign: 'left',
  238. showAdvancedButton: false,
  239. // autoAdvancedCol: 2,
  240. baseColProps: {
  241. // offset: 0.5,
  242. xs: 24,
  243. sm: 24,
  244. md: 24,
  245. lg: 9,
  246. xl: 7,
  247. xxl: 4,
  248. },
  249. schemas: props.formSchemas.length > 0 ? props.formSchemas : [
  250. {
  251. field: 'startTime',
  252. label: '开始时间',
  253. component: 'DatePicker',
  254. required: true,
  255. componentProps: {
  256. showTime: true,
  257. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  258. getPopupContainer: getAutoScrollContainer,
  259. },
  260. },
  261. {
  262. field: 'endTime',
  263. label: '结束时间',
  264. component: 'DatePicker',
  265. required: true,
  266. componentProps: {
  267. showTime: true,
  268. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  269. getPopupContainer: getAutoScrollContainer,
  270. },
  271. },
  272. {
  273. label: '查询设备',
  274. field: 'deviceId',
  275. component: 'ApiSelect',
  276. required: true,
  277. componentProps: {
  278. api: () => defHttp.get({ url: '/safety/ventanalyManageSystem/linkdevicelist', params: { sysId: props.sysId, deviceType: props.deviceType.startsWith('vehicle') ? 'location_normal' : props.deviceType } }),
  279. // resultField: 'result',
  280. labelField: 'strinstallpos',
  281. valueField: 'id',
  282. // numberToString: true,
  283. },
  284. },
  285. {
  286. label: '间隔时间',
  287. field: 'interval',
  288. component: 'Select',
  289. defaultValue: '30s',
  290. componentProps: {
  291. options: [
  292. {
  293. label: '1秒',
  294. value: '1s',
  295. },
  296. {
  297. label: '5秒',
  298. value: '5s',
  299. },
  300. {
  301. label: '10秒',
  302. value: '10s',
  303. },
  304. {
  305. label: '30秒',
  306. value: '30s',
  307. },
  308. {
  309. label: '1分钟',
  310. value: '1m',
  311. },
  312. {
  313. label: '10分钟',
  314. value: '10m',
  315. },
  316. {
  317. label: '30分钟',
  318. value: '30m',
  319. },
  320. {
  321. label: '1小时',
  322. value: '1h',
  323. },
  324. ],
  325. },
  326. },
  327. ],
  328. },
  329. pagination: {
  330. current: 1,
  331. pageSize: 10,
  332. pageSizeOptions: ['10', '30', '50', '100'],
  333. showQuickJumper: false
  334. },
  335. // pagination: false,
  336. fetchSetting: {
  337. totalField: 'total',
  338. // 每页显示多少条
  339. sizeField: 'pageSize',
  340. // 请求结果列表字段 支持 a.b.c
  341. pageField: 'pageNo'
  342. },
  343. beforeFetch(params) {
  344. params.strtype = props.deviceType + '*';
  345. if (props.sysId) {
  346. params.sysId = props.sysId;
  347. }
  348. if(params.interval){
  349. params.interval = params.interval
  350. }else{
  351. params.interval = '1m'
  352. }
  353. if (props.deviceType.startsWith('vehicle')) {
  354. params['isEmployee'] = false
  355. } else if (props.deviceType.startsWith('location')) {
  356. params['isEmployee'] = true
  357. }
  358. },
  359. afterFetch(result) {
  360. return result;
  361. },
  362. },
  363. }
  364. );
  365. //注册table数据
  366. const [registerTable, { getDataSource, reload, setLoading, getForm }] = tableContext;
  367. watchEffect(() => {
  368. if (historyTable.value && getDataSource) {
  369. const data = getDataSource() || [];
  370. emit('change', data);
  371. console.log('[ data ] >', data);
  372. }
  373. });
  374. defineExpose({ setLoading })
  375. </script>
  376. <style scoped lang="less">
  377. @import '/@/design/vent/color.less';
  378. :deep(.@{ventSpace}-table-body) {
  379. height: auto !important;
  380. }
  381. :deep(.zxm-picker){
  382. height: 30px !important;
  383. }
  384. .history-table {
  385. width: 100%;
  386. :deep(.jeecg-basic-table-form-container) {
  387. .@{ventSpace}-form {
  388. padding: 0 !important;
  389. border: none !important;
  390. margin-bottom: 0 !important;
  391. .@{ventSpace}-picker,
  392. .@{ventSpace}-select-selector {
  393. width: 100% !important;
  394. height: 100%;
  395. background: #00000017;
  396. border: 1px solid #b7b7b7;
  397. input,
  398. .@{ventSpace}-select-selection-item,
  399. .@{ventSpace}-picker-suffix {
  400. color: #fff;
  401. }
  402. .@{ventSpace}-select-selection-placeholder {
  403. color: #ffffffaa;
  404. }
  405. }
  406. }
  407. .@{ventSpace}-table-title {
  408. min-height: 0 !important;
  409. }
  410. }
  411. .pagination-box{
  412. display: flex;
  413. justify-content: flex-end;
  414. align-items: center;
  415. .page-num{
  416. border: 1px solid #0090D8;
  417. padding: 4px 8px;
  418. margin-right: 5px;
  419. color: #0090D8;
  420. }
  421. .btn{
  422. margin-right: 10px;
  423. }
  424. }
  425. }
  426. </style>