HistoryTable.vue 5.8 KB

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