HistoryTable.vue 11 KB

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