HistoryTable.vue 9.6 KB

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