HistoryTable.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 } from 'vue';
  13. import { BasicTable } from '/@/components/Table';
  14. import { useListPage } from '/@/hooks/system/useListPage';
  15. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  16. import { defHttp } from '/@/utils/http/axios';
  17. import dayjs from 'dayjs';
  18. const historyTable = ref();
  19. const list = (params) => defHttp.get({ url: '/safety/ventanalyMonitorData/list', params });
  20. const emit = defineEmits(['change']);
  21. const props = defineProps({
  22. columnsType: {
  23. type: String,
  24. required: true,
  25. },
  26. deviceType: {
  27. type: String,
  28. required: true,
  29. },
  30. deviceListApi: {
  31. type: Function,
  32. required: true,
  33. },
  34. designScope: {
  35. type: String,
  36. },
  37. sysId: {
  38. type: String,
  39. },
  40. scroll: {
  41. type: Object,
  42. default: () => { }
  43. }
  44. });
  45. const columns = ref([])
  46. watch(
  47. () => {
  48. return props.columnsType;
  49. },
  50. (newVal) => {
  51. debugger
  52. const column = getTableHeaderColumns(newVal + '_history')
  53. if (column && column.length < 1) {
  54. const arr = newVal.split('_')
  55. const columnKey = arr.reduce((prev, cur, index) => {
  56. if (index !== arr.length - 2) {
  57. return prev + '_' + cur
  58. } else {
  59. return prev
  60. }
  61. })
  62. columns.value = getTableHeaderColumns(arr[0] + '_history');
  63. } else {
  64. columns.value = column
  65. }
  66. if(historyTable.value) reload()
  67. },
  68. {
  69. immediate: true
  70. }
  71. );
  72. // 列表页面公共参数、方法
  73. const { tableContext } = useListPage({
  74. tableProps: {
  75. api: list,
  76. columns: columns,
  77. canResize: true,
  78. showTableSetting: false,
  79. showActionColumn: false,
  80. bordered: false,
  81. size: 'small',
  82. scroll: props.scroll,
  83. formConfig: {
  84. labelAlign: 'left',
  85. showAdvancedButton: false,
  86. // autoAdvancedCol: 2,
  87. baseColProps: {
  88. // offset: 0.5,
  89. xs: 24,
  90. sm: 24,
  91. md: 24,
  92. lg: 9,
  93. xl: 7,
  94. xxl: 4,
  95. },
  96. schemas: [
  97. {
  98. label: '查询日期',
  99. field: 'tData',
  100. component: 'DatePicker',
  101. defaultValue: dayjs(),
  102. componentProps: {
  103. valueFormat: 'YYYY-MM-DD',
  104. },
  105. },
  106. {
  107. label: '时间区间',
  108. field: 'tickectDate',
  109. component: 'TimeRangePicker',
  110. componentProps: {
  111. placeholder: ['开始时间', '结束时间'],
  112. valueFormat: 'HH:mm:ss',
  113. },
  114. },
  115. {
  116. label: '查询设备',
  117. field: 'gdeviceid',
  118. component: 'ApiSelect',
  119. componentProps: {
  120. api: props.deviceListApi,
  121. resultField: 'records',
  122. labelField: 'strname',
  123. valueField: 'id',
  124. },
  125. },
  126. {
  127. label: '间隔时间',
  128. field: 'skip',
  129. component: 'Select',
  130. componentProps: {
  131. options: [
  132. {
  133. label: '5秒',
  134. value: '1',
  135. },
  136. {
  137. label: '10秒',
  138. value: '2',
  139. },
  140. {
  141. label: '1分钟',
  142. value: '3',
  143. },
  144. {
  145. label: '5分钟',
  146. value: '4',
  147. },
  148. {
  149. label: '10分钟',
  150. value: '5',
  151. },
  152. ],
  153. },
  154. },
  155. ],
  156. fieldMapToTime: [['tickectDate', ['ttime_begin', 'ttime_end'], '']],
  157. },
  158. fetchSetting: {
  159. listField: 'datalist.records',
  160. },
  161. pagination: {
  162. current: 1,
  163. pageSize: 5,
  164. pageSizeOptions: ['5', '10', '20'],
  165. },
  166. beforeFetch(params) {
  167. params.strtype = props.deviceType + '*';
  168. if(props.sysId){
  169. params.sysId = props.sysId;
  170. }
  171. },
  172. afterFetch(resultItems) {
  173. resultItems.map((item) => {
  174. Object.assign(item, item['readData']);
  175. });
  176. return resultItems;
  177. },
  178. },
  179. });
  180. //注册table数据
  181. const [registerTable, { getDataSource, reload, setLoading }] = tableContext;
  182. watchEffect(() => {
  183. if (historyTable.value && getDataSource) {
  184. const data = getDataSource() || [];
  185. emit('change', data);
  186. console.log('[ data ] >', data);
  187. }
  188. });
  189. defineExpose({ setLoading })
  190. </script>
  191. <style scoped lang="less">
  192. @import '/@/design/vent/color.less';
  193. :deep(.@{ventSpace}-table-body) {
  194. height: auto !important;
  195. }
  196. :deep(.zxm-picker){
  197. height: 30px !important;
  198. }
  199. .history-table {
  200. width: 100%;
  201. :deep(.jeecg-basic-table-form-container) {
  202. .@{ventSpace}-form {
  203. padding: 0 !important;
  204. border: none !important;
  205. margin-bottom: 0 !important;
  206. .@{ventSpace}-picker,
  207. .@{ventSpace}-select-selector {
  208. width: 100% !important;
  209. height: 100%;
  210. background: #00000017;
  211. border: 1px solid #b7b7b7;
  212. input,
  213. .@{ventSpace}-select-selection-item,
  214. .@{ventSpace}-picker-suffix {
  215. color: #fff;
  216. }
  217. .@{ventSpace}-select-selection-placeholder {
  218. color: #ffffffaa;
  219. }
  220. }
  221. }
  222. .@{ventSpace}-table-title {
  223. min-height: 0 !important;
  224. }
  225. }
  226. }
  227. </style>