diff --git a/src/component/table/src/index.vue b/src/component/table/src/index.vue index db4d4c7..e55bc6c 100644 --- a/src/component/table/src/index.vue +++ b/src/component/table/src/index.vue @@ -269,6 +269,7 @@ import { useStore } from 'vuex'; + import { message } from '@hwork/ant-design-vue'; import { defineComponent, onMounted, @@ -643,20 +644,23 @@ const handleSearch = async (selectedKeys, confirm, dataIndex) => { confirm(); state.loading = true; - /// 请求数据:将请求参数与 列搜索参数进行合并,单键相同时,会被 请求参数覆盖 - const pageInfo = await getPageInfo(undefined); - let searchParams = Object.assign({}, pageInfo, state.columnSearchParams, props.param) - console.log("查询条件", searchParams) - const { - total, - data - } = await props.fetch(searchParams); - // 状态重置 - if (state.pagination != false) { - state.pagination.total = total; + try { + // 将请求参数与列搜索参数进行合并 + const pageInfo = await getPageInfo(undefined); + let searchParams = Object.assign({}, pageInfo, state.columnSearchParams, props.param) + console.log("查询条件", searchParams) + const { total, data } = await props.fetch(searchParams); + if (state.pagination != false) { + state.pagination.total = total || 0; + } + state.datasource = data || []; + } catch (error) { + console.error('列搜索请求失败:', error); + if (state.pagination != false) state.pagination.total = 0; + state.datasource = []; + } finally { + state.loading = false; } - state.datasource = data; - state.loading = false; }; /** @@ -740,31 +744,32 @@ } } } - //分页信息:包含queryType,当queryType = 'like'时,配合后端使用模糊查询 + // 分页信息:包含queryType,当queryType = 'like'时,配合后端使用模糊查询 const pageInfo = await getPageInfo(pagination); state.loading = true; - var sortFeild = null - if (sorter && sorter.columnKey && sorter.order) { - sortFeild = { - sortColumn: toUnderline(sorter.columnKey), - sortType: sorter.order ? (sorter.order === "ascend" ? "ASC" : sorter.order === "descend" ? - "DESC" : "") : "" + try { + let sortFeild = null + if (sorter && sorter.columnKey && sorter.order) { + sortFeild = { + sortColumn: toUnderline(sorter.columnKey), + sortType: sorter.order ? (sorter.order === 'ascend' ? 'ASC' : sorter.order === 'descend' ? 'DESC' : '') : '' + } + console.log('sortFeild 列排序条件', sortFeild) } - console.log("sortFeild 列排序条件", sortFeild) + const searchParams = Object.assign({}, pageInfo, state.columnSearchParams, props.param, sortFeild) + console.log('查询条件', searchParams) + const { total, data } = await props.fetch(searchParams) + if (state.pagination != false) state.pagination.total = total || 0 + state.datasource = data || [] + } catch (error) { + console.error('表格加载失败:', error) + if (state.pagination != false) state.pagination.total = 0 + state.datasource = [] + // 可选:给出全局提示 + // message.error('数据加载失败') + } finally { + state.loading = false } - let searchParams = Object.assign({}, pageInfo, state.columnSearchParams, props.param, sortFeild) - console.log("查询条件", searchParams) - ///查询后端的数据 - const { - total, - data - } = await props.fetch(searchParams); - /// 状态重置 - if (state.pagination != false) { - state.pagination.total = total; - } - state.datasource = data; - state.loading = false; }; ///从上下文中获取分页信息,随着分页属性的复杂化,并不是所有分页属性都需要放到请求消息中 @@ -844,26 +849,24 @@ let activeKey = store.getters.activeKey; var exportFileName = panes.filter(item => item.path == activeKey)[0].title+new Date().toLocaleString().replace(/[/]/g, '_').replace(/[:]/g, ''); console.log("ExportExcel tablename", exportFileName) - state.exportExcelPagination.pageNum = 1; - state.exportExcelPagination.pageSize = state.pagination.total; - let searchParams = Object.assign({}, state.exportExcelPagination, state.columnSearchParams, props.param) - console.log("导出数据条件", searchParams) - const { total, data} = await props.fetch(searchParams); - if (data) { - // 供导出用 - state.datasourceExport = data; - //excelExportRef.value.excelExport() - nextTick(() => { - //缺陷:依赖于table才能打印 - exportDataMethod(props.tableId,exportFileName); - }) - // nextTick(() => { - //优点:指定数据源就可以完成导出操作 缺点:表头是英文 之后在优化 - // exportExcelWithData(exportFileName,data); - // }) - + try { + state.exportExcelPagination.pageNum = 1; + state.exportExcelPagination.pageSize = state.pagination.total; + let searchParams = Object.assign({}, state.exportExcelPagination, state.columnSearchParams, props.param) + console.log('导出数据条件', searchParams) + const { total, data } = await props.fetch(searchParams) + if (data) { + state.datasourceExport = data; + nextTick(() => { + exportDataMethod(props.tableId, exportFileName); + }) + } + } catch (error) { + console.error('导出失败:', error) + message.error('导出失败') + } finally { + state.loading = false } - state.loading = false; }; const exportDataMethod = function(elementId ,fileName) { diff --git a/src/view/log/auth.vue b/src/view/log/auth.vue index 5dff9ba..51fee6b 100644 --- a/src/view/log/auth.vue +++ b/src/view/log/auth.vue @@ -26,8 +26,6 @@