HistoryTable.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <div class="history-table">
  3. <BasicTable v-if="globalConfig.History_Type == 'vent'" ref="historyTable" @register="registerTable" >
  4. <template #bodyCell="{ column, record }">
  5. <slot name="filterCell" v-bind="{ column, record }"></slot>
  6. </template>
  7. </BasicTable>
  8. <BasicTable v-else ref="historyTable" @register="registerTable" >
  9. <template #bodyCell="{ column, record }">
  10. <slot name="filterCell" v-bind="{ column, record }"></slot>
  11. </template>
  12. </BasicTable>
  13. </div>
  14. </template>
  15. <script lang="ts" name="system-user" setup>
  16. //ts语法
  17. import { watchEffect, ref, watch, defineExpose, inject } from 'vue';
  18. import { FormSchema } from '/@/components/Form/index';
  19. import { BasicTable } from '/@/components/Table';
  20. import { useListPage } from '/@/hooks/system/useListPage';
  21. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  22. import { defHttp } from '/@/utils/http/axios';
  23. import dayjs from 'dayjs';
  24. const globalConfig = inject('globalConfig');
  25. const historyTable = ref();
  26. const dataSource = ref([])
  27. const list = (params) => {
  28. if(globalConfig.History_Type == 'vent') {
  29. return defHttp.get({ url: '/safety/ventanalyMonitorData/list', params })
  30. } else {
  31. return defHttp.post({ url: '/ventanaly-device/history/getHistoryData', params })
  32. }
  33. };
  34. const emit = defineEmits(['change']);
  35. const props = defineProps({
  36. columnsType: {
  37. type: String,
  38. },
  39. columns: {
  40. type: Array,
  41. // required: true,
  42. default: () => [],
  43. },
  44. deviceType: {
  45. type: String,
  46. required: true,
  47. },
  48. deviceListApi: {
  49. type: Function,
  50. required: true,
  51. },
  52. designScope: {
  53. type: String,
  54. },
  55. sysId: {
  56. type: String,
  57. },
  58. scroll: {
  59. type: Object,
  60. default: { y: 0 }
  61. },
  62. formSchemas: {
  63. type: Array<FormSchema>,
  64. default: () => []
  65. }
  66. });
  67. const columns = ref([])
  68. const tableScroll = props.scroll.y ? ref({ y: props.scroll.y - 100 }) : ref({})
  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 + '_history')
  77. if (column && column.length < 1) {
  78. const arr = newVal.split('_')
  79. const columnKey = arr.reduce((prev, cur, index) => {
  80. if (index !== arr.length - 2) {
  81. return prev + '_' + cur
  82. } else {
  83. return prev
  84. }
  85. })
  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(() => props.scroll.y, (newVal) => {
  97. if(newVal){
  98. tableScroll.value = {y: newVal - 100 }
  99. }else{
  100. tableScroll.value = {}
  101. }
  102. })
  103. // 列表页面公共参数、方法
  104. const { tableContext } = useListPage(
  105. globalConfig.History_Type == 'vent' ? {
  106. tableProps: {
  107. api: list,
  108. columns: props.columnsType ? columns : (props.columns as any[]),
  109. canResize: true,
  110. showTableSetting: false,
  111. showActionColumn: false,
  112. bordered: false,
  113. size: 'small',
  114. scroll: tableScroll,
  115. formConfig: {
  116. labelAlign: 'left',
  117. showAdvancedButton: false,
  118. // autoAdvancedCol: 2,
  119. baseColProps: {
  120. // offset: 0.5,
  121. xs: 24,
  122. sm: 24,
  123. md: 24,
  124. lg: 9,
  125. xl: 7,
  126. xxl: 4,
  127. },
  128. schemas: props.formSchemas.length > 0 ? props.formSchemas : [
  129. {
  130. label: '查询日期',
  131. field: 'tData',
  132. component: 'DatePicker',
  133. defaultValue: dayjs(),
  134. componentProps: {
  135. valueFormat: 'YYYY-MM-DD',
  136. },
  137. },
  138. {
  139. label: '时间区间',
  140. field: 'tickectDate',
  141. component: 'TimeRangePicker',
  142. componentProps: {
  143. placeholder: ['开始时间', '结束时间'],
  144. valueFormat: 'HH:mm:ss',
  145. },
  146. },
  147. {
  148. label: '查询设备',
  149. field: 'gdeviceid',
  150. component: 'ApiSelect',
  151. required: true,
  152. componentProps: {
  153. api: () => defHttp.get({ url: '/safety/ventanalyManageSystem/linkdevicelist', params: { sysId: props.sysId, deviceType: props.deviceType } }),
  154. // resultField: 'result',
  155. labelField: 'strinstallpos',
  156. valueField: 'id',
  157. // numberToString: true,
  158. },
  159. },
  160. {
  161. label: '间隔时间',
  162. field: 'skip',
  163. component: 'Select',
  164. componentProps: {
  165. options: [
  166. {
  167. label: '5秒',
  168. value: '1',
  169. },
  170. {
  171. label: '10秒',
  172. value: '2',
  173. },
  174. {
  175. label: '1分钟',
  176. value: '3',
  177. },
  178. {
  179. label: '5分钟',
  180. value: '4',
  181. },
  182. {
  183. label: '10分钟',
  184. value: '5',
  185. },
  186. ],
  187. },
  188. },
  189. ],
  190. fieldMapToTime: [['tickectDate', ['ttime_begin', 'ttime_end'], '']],
  191. },
  192. fetchSetting: {
  193. listField: globalConfig.History_Type == 'iot'? 'records': globalConfig.History_Type == 'records'? '': 'datalist.records',
  194. totalField: globalConfig.History_Type == 'iot' ? 'total' : globalConfig.History_Type == 'total' ? 'total' : 'datalist.total',
  195. },
  196. beforeFetch(params) {
  197. params.strtype = props.deviceType + '*';
  198. if(props.sysId){
  199. params.sysId = props.sysId;
  200. }
  201. },
  202. afterFetch(resultItems) {
  203. resultItems.map((item) => {
  204. Object.assign(item, item['readData']);
  205. });
  206. return resultItems;
  207. },
  208. },
  209. }: {
  210. tableProps: {
  211. api: list,
  212. columns: props.columnsType ? columns : (props.columns as any[]),
  213. canResize: true,
  214. showTableSetting: false,
  215. showActionColumn: false,
  216. bordered: false,
  217. size: 'small',
  218. scroll: tableScroll,
  219. formConfig: {
  220. labelAlign: 'left',
  221. showAdvancedButton: false,
  222. // autoAdvancedCol: 2,
  223. baseColProps: {
  224. // offset: 0.5,
  225. xs: 24,
  226. sm: 24,
  227. md: 24,
  228. lg: 9,
  229. xl: 7,
  230. xxl: 4,
  231. },
  232. schemas: props.formSchemas.length > 0 ? props.formSchemas : [
  233. {
  234. label: '查询日期',
  235. field: 'tData',
  236. component: 'DatePicker',
  237. defaultValue: dayjs(),
  238. componentProps: {
  239. valueFormat: 'YYYY-MM-DD hh:mm:ss',
  240. },
  241. },
  242. {
  243. label: '查询设备',
  244. field: 'deviceId',
  245. component: 'ApiSelect',
  246. required: true,
  247. componentProps: {
  248. api: () => defHttp.get({ url: '/safety/ventanalyManageSystem/linkdevicelist', params: { sysId: props.sysId, deviceType: props.deviceType } }),
  249. // resultField: 'result',
  250. labelField: 'strinstallpos',
  251. valueField: 'id',
  252. // numberToString: true,
  253. },
  254. },
  255. {
  256. label: '间隔时间',
  257. field: 'interval',
  258. component: 'Select',
  259. defaultValue: 1,
  260. componentProps: {
  261. options: [
  262. {
  263. label: '5秒',
  264. value: '1',
  265. },
  266. {
  267. label: '10秒',
  268. value: '2',
  269. },
  270. {
  271. label: '1分钟',
  272. value: '3',
  273. },
  274. {
  275. label: '10分钟',
  276. value: '4',
  277. },
  278. {
  279. label: '20分钟',
  280. value: '5',
  281. },
  282. ],
  283. },
  284. },
  285. ],
  286. fieldMapToTime: [['tData', ['startTime', 'endTime'], 'YYYY-MM-DD HH:mm:ss']],
  287. },
  288. beforeFetch(params) {
  289. params.strtype = props.deviceType + '*';
  290. if (props.sysId) {
  291. params.sysId = props.sysId;
  292. }
  293. if(params.interval){
  294. params.interval = params.interval+'m'
  295. }else{
  296. params.interval = '1m'
  297. }
  298. },
  299. afterFetch(result) {
  300. let dataSource = []
  301. if(result['records'] && result['records'].length >0){
  302. dataSource = result['records'].map((item) => {
  303. Object.assign(item, result['deviceId'], result['deviceName'], result['devicePos'] );
  304. })
  305. }
  306. return dataSource;
  307. },
  308. },
  309. }
  310. );
  311. //注册table数据
  312. const [registerTable, { getDataSource, reload, setLoading, getForm }] = tableContext;
  313. watchEffect(() => {
  314. if (historyTable.value && getDataSource) {
  315. const data = getDataSource() || [];
  316. emit('change', data);
  317. console.log('[ data ] >', data);
  318. }
  319. });
  320. defineExpose({ setLoading })
  321. </script>
  322. <style scoped lang="less">
  323. @import '/@/design/vent/color.less';
  324. :deep(.@{ventSpace}-table-body) {
  325. height: auto !important;
  326. }
  327. :deep(.zxm-picker){
  328. height: 30px !important;
  329. }
  330. .history-table {
  331. width: 100%;
  332. :deep(.jeecg-basic-table-form-container) {
  333. .@{ventSpace}-form {
  334. padding: 0 !important;
  335. border: none !important;
  336. margin-bottom: 0 !important;
  337. .@{ventSpace}-picker,
  338. .@{ventSpace}-select-selector {
  339. width: 100% !important;
  340. height: 100%;
  341. background: #00000017;
  342. border: 1px solid #b7b7b7;
  343. input,
  344. .@{ventSpace}-select-selection-item,
  345. .@{ventSpace}-picker-suffix {
  346. color: #fff;
  347. }
  348. .@{ventSpace}-select-selection-placeholder {
  349. color: #ffffffaa;
  350. }
  351. }
  352. }
  353. .@{ventSpace}-table-title {
  354. min-height: 0 !important;
  355. }
  356. }
  357. }
  358. </style>