HistoryTable.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <div class="history-table" v-if="loading">
  3. <BasicTable ref="historyTable" @register="registerTable" :data-source="dataSource">
  4. <template #form-submitBefore>
  5. <a-button type="primary" preIcon="ant-design:search-outlined" @click="getDataSource">查询</a-button>
  6. </template>
  7. </BasicTable>
  8. </div>
  9. </template>
  10. <script lang="ts" setup>
  11. //ts语法
  12. import { watchEffect, ref, watch, defineExpose, inject, nextTick, onMounted, computed } 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 props = defineProps({
  21. columnsType: {
  22. type: String,
  23. },
  24. columns: {
  25. type: Array,
  26. // required: true,
  27. default: () => [],
  28. },
  29. historyColumns: {
  30. type: Array,
  31. default: () => [],
  32. },
  33. id: {
  34. type: String,
  35. },
  36. scroll: {
  37. type: Object,
  38. default: { y: 0 },
  39. },
  40. formSchemas: {
  41. type: Array<FormSchema>,
  42. default: () => [],
  43. },
  44. });
  45. //获取分站数据
  46. const getDeviceListApi = (params) => defHttp.get({ url: '/safety/ventanalySubStation/alllist', params });
  47. const historyTable = ref();
  48. const loading = ref(false);
  49. const dataSource = ref([]);
  50. const emit = defineEmits(['change']);
  51. const historyType = ref('');
  52. const deviceKide = ref('');
  53. const columns = ref([]);
  54. const deviceOptions = ref([]);
  55. const tableScroll = props.scroll.y ? ref({ y: props.scroll.y - 100 }) : ref({});
  56. const deviceTypeStr = ref('');
  57. loading.value = true;
  58. watch(
  59. () => {
  60. return props.columnsType;
  61. },
  62. async (newVal) => {
  63. debugger;
  64. if (!newVal) return;
  65. deviceKide.value = newVal;
  66. if (historyTable.value) {
  67. getForm().resetFields();
  68. // getForm().updateSchema();
  69. // getForm();
  70. }
  71. dataSource.value = [];
  72. await getDeviceList();
  73. nextTick(() => {
  74. getDataSource();
  75. });
  76. if (historyTable.value) reload();
  77. },
  78. {
  79. immediate: true,
  80. }
  81. );
  82. watch(
  83. () => props.scroll.y,
  84. (newVal) => {
  85. if (newVal) {
  86. tableScroll.value = { y: newVal - 100 };
  87. } else {
  88. tableScroll.value = {};
  89. }
  90. }
  91. );
  92. watch(
  93. () => props.id,
  94. async () => {
  95. await getForm().setFieldsValue({});
  96. await getDeviceList();
  97. }
  98. );
  99. async function getDeviceList() {
  100. let result;
  101. const res = await getDeviceListApi({ column: 'createTime', pageNo: 1, pageSize: 10000 });
  102. result = res;
  103. if (result) {
  104. deviceOptions.value = [];
  105. deviceOptions.value = result.map((item) => {
  106. return {
  107. label: item['strinstallpos'],
  108. value: item['id'],
  109. strinstallpos: item['strinstallpos'],
  110. };
  111. // return { label: item['strname'], value: item['id']}
  112. });
  113. }
  114. deviceOptions.value.unshift({ label: '--请选择设备--', value: '', strinstallpos: '' });
  115. }
  116. function resetFormParam() {
  117. const formData = getForm().getFieldsValue();
  118. const pagination = getPaginationRef();
  119. formData['pageNo'] = pagination['current'];
  120. formData['pageSize'] = pagination['pageSize'];
  121. formData['column'] = 'createTime';
  122. const params = {
  123. pageNum: pagination['current'],
  124. pageSize: pagination['pageSize'],
  125. column: pagination['createTime'],
  126. starttime_begin: formData['starttime_begin'],
  127. starttime_endtime: formData['starttime_endtime'],
  128. nsubstationid: formData['nsubstationid'],
  129. nwartype: 1001,
  130. };
  131. return params;
  132. }
  133. async function getDataSource() {
  134. dataSource.value = [];
  135. setLoading(true);
  136. const params = await resetFormParam();
  137. const result = await defHttp.get({ url: '/safety/ventanalyAlarmLog/list', params: params });
  138. // if (result['datalist']['records'].length > 0) {
  139. // dataSource.value = result['datalist']['records'].map((item: any) => {
  140. // return Object.assign(item, item['readData']);
  141. // });
  142. // } else {
  143. // dataSource.value = [];
  144. // }
  145. return result;
  146. setLoading(false);
  147. }
  148. // 列表页面公共参数、方法
  149. const { tableContext } = useListPage({
  150. tableProps: {
  151. // api: list,
  152. columns: props.historyColumns ? props.historyColumns : (props.historyColumns as any[]),
  153. canResize: true,
  154. showTableSetting: false,
  155. showActionColumn: false,
  156. bordered: false,
  157. size: 'small',
  158. scroll: tableScroll,
  159. showIndexColumn: true,
  160. tableLayout: 'auto',
  161. formConfig: {
  162. labelAlign: 'left',
  163. showAdvancedButton: false,
  164. showSubmitButton: false,
  165. showResetButton: false,
  166. baseColProps: {
  167. xs: 24,
  168. sm: 24,
  169. md: 24,
  170. lg: 9,
  171. xl: 7,
  172. xxl: 4,
  173. },
  174. schemas:
  175. props.formSchemas.length > 0
  176. ? props.formSchemas
  177. : [
  178. {
  179. field: 'starttime_begin',
  180. label: '开始时间',
  181. component: 'DatePicker',
  182. defaultValue: dayjs().startOf('date'),
  183. required: true,
  184. componentProps: {
  185. showTime: true,
  186. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  187. getPopupContainer: getAutoScrollContainer,
  188. },
  189. colProps: {
  190. span: 4,
  191. },
  192. },
  193. {
  194. field: 'starttime_endtime',
  195. label: '结束时间',
  196. component: 'DatePicker',
  197. defaultValue: dayjs(),
  198. required: true,
  199. componentProps: {
  200. showTime: true,
  201. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  202. getPopupContainer: getAutoScrollContainer,
  203. },
  204. colProps: {
  205. span: 4,
  206. },
  207. },
  208. {
  209. label: '查询设备',
  210. field: 'nsubstationid',
  211. component: 'Select',
  212. defaultValue: props.id ? props.id : deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
  213. componentProps: {
  214. showSearch: true,
  215. filterOption: (input: string, option: any) => {
  216. return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
  217. },
  218. options: deviceOptions,
  219. onChange: (e, option) => {
  220. if (option) {
  221. historyType.value = option.value; // 使用选项的value(即id)更新historyType
  222. }
  223. },
  224. },
  225. colProps: {
  226. span: 4,
  227. },
  228. },
  229. {
  230. field: 'nwartype',
  231. required: true,
  232. componentProps: {
  233. valueFormat: '1001',
  234. },
  235. colProps: {
  236. span: 4,
  237. },
  238. },
  239. ],
  240. },
  241. // fetchSetting: {
  242. pagination: {
  243. current: 1,
  244. pageSize: 10,
  245. pageSizeOptions: ['10', '30', '50', '100'],
  246. showQuickJumper: false,
  247. },
  248. beforeFetch() {
  249. const newParams = { ...resetFormParam() };
  250. // debugger;
  251. return newParams;
  252. },
  253. },
  254. });
  255. //注册table数据
  256. const [registerTable, { reload, setLoading, getForm, setColumns, getPaginationRef, setPagination }] = tableContext;
  257. watchEffect(() => {
  258. if (historyTable.value && dataSource) {
  259. const data = dataSource.value || [];
  260. emit('change', data);
  261. }
  262. });
  263. onMounted(async () => {
  264. await getDeviceList();
  265. if (deviceOptions.value[0]) {
  266. historyType.value = deviceOptions.value[0]['strinstallpos'] || deviceOptions.value[0]['id'];
  267. nextTick(async () => {
  268. await getDataSource();
  269. });
  270. }
  271. });
  272. defineExpose({ setLoading });
  273. </script>
  274. <style scoped lang="less">
  275. @import '/@/design/vent/color.less';
  276. :deep(.@{ventSpace}-table-body) {
  277. height: auto !important;
  278. }
  279. :deep(.zxm-picker) {
  280. height: 30px !important;
  281. }
  282. .history-table {
  283. width: 100%;
  284. :deep(.jeecg-basic-table-form-container) {
  285. .@{ventSpace}-form {
  286. padding: 0 !important;
  287. border: none !important;
  288. margin-bottom: 0 !important;
  289. .@{ventSpace}-picker,
  290. .@{ventSpace}-select-selector {
  291. width: 100% !important;
  292. height: 100%;
  293. background: #00000017;
  294. border: 1px solid #b7b7b7;
  295. input,
  296. .@{ventSpace}-select-selection-item,
  297. .@{ventSpace}-picker-suffix {
  298. color: #fff;
  299. }
  300. .@{ventSpace}-select-selection-placeholder {
  301. color: #ffffffaa;
  302. }
  303. }
  304. }
  305. .@{ventSpace}-table-title {
  306. min-height: 0 !important;
  307. }
  308. }
  309. .pagination-box {
  310. display: flex;
  311. justify-content: flex-end;
  312. align-items: center;
  313. .page-num {
  314. border: 1px solid #0090d8;
  315. padding: 4px 8px;
  316. margin-right: 5px;
  317. color: #0090d8;
  318. }
  319. .btn {
  320. margin-right: 10px;
  321. }
  322. }
  323. }
  324. </style>