diff --git a/src/components/DataTable/index.vue b/src/components/DataTable/index.vue index 4a1b79c..b387284 100644 --- a/src/components/DataTable/index.vue +++ b/src/components/DataTable/index.vue @@ -28,7 +28,11 @@ :pagination="pagination" @update:page="updatePage" @update:page-size="updatePageSize" - /> + > + + diff --git a/src/components/DataTable/tools/Action.vue b/src/components/DataTable/tools/Action.vue index d8a19bd..b738a78 100644 --- a/src/components/DataTable/tools/Action.vue +++ b/src/components/DataTable/tools/Action.vue @@ -50,7 +50,10 @@ export default defineComponent({ const getActions = computed(() => { return (toRaw(props.actions) || []) .filter((action) => { - return data.permissionList.includes(action.auth) || action.auth === '' + if (!Object.keys(action).includes('show')) { + action.show = Object.keys(action).includes('hidden') ? !action.hidden : true + } + return (data.permissionList.includes(action.auth) || action.auth === '') && action.show }) }) diff --git a/src/components/DataTable/tools/Tags.vue b/src/components/DataTable/tools/Tags.vue index 6a65fa1..b1f0627 100644 --- a/src/components/DataTable/tools/Tags.vue +++ b/src/components/DataTable/tools/Tags.vue @@ -58,10 +58,10 @@ export default defineComponent({ const { filters } = unref(props) function getFilter(value) { const data = filters.find(item => { - return item.key === value + return item.value === value }) return data || { - key: value, + value: value, label: value } } diff --git a/src/components/DataTable/tools/props.js b/src/components/DataTable/tools/props.js index 3d86f04..a720e5a 100644 --- a/src/components/DataTable/tools/props.js +++ b/src/components/DataTable/tools/props.js @@ -29,6 +29,8 @@ export const tableProps = { pageField: 'page', // 每页数量字段名 sizeField: 'limit', + // 接口返回的字段名 + listPageField: 'current', // 接口返回的数据字段名 listField: 'records', // 接口返回总页数字段名 diff --git a/src/components/DataTable/tools/useDataSource.js b/src/components/DataTable/tools/useDataSource.js index 5c85051..2ee9a63 100644 --- a/src/components/DataTable/tools/useDataSource.js +++ b/src/components/DataTable/tools/useDataSource.js @@ -4,7 +4,7 @@ import { toTreeData } from './toTree' export function useDataSource(propsRef, { getPaginationInfo, setPagination, setLoading, tableData }, emit) { const dataSourceRef = ref([]) - + const paginationPage = ref(1) async function fetch(opt) { try { /* 设置loading */ @@ -14,6 +14,7 @@ export function useDataSource(propsRef, { getPaginationInfo, setPagination, setL if (!request) return /* 获取分页信息 */ const pageField = paginationSetting.pageField + const listPageField = paginationSetting.listPageField const sizeField = paginationSetting.sizeField const totalField = paginationSetting.totalField const listField = paginationSetting.listField @@ -25,6 +26,7 @@ export function useDataSource(propsRef, { getPaginationInfo, setPagination, setL pageParams = {} } else { pageParams[pageField] = (opt && opt[pageField]) || page + paginationPage.value = pageParams[pageField] pageParams[sizeField] = pageSize } const params = { @@ -33,7 +35,7 @@ export function useDataSource(propsRef, { getPaginationInfo, setPagination, setL const response = await request(params) const res = noPagination ? response : response.data const resultTotal = res[totalField] || 0 - const currentPage = res[pageField] + const currentPage = res[listPageField] // 如果数据异常,需获取正确的页码再次执行 if (resultTotal) { if (page > Math.ceil(resultTotal / pageSize)) { @@ -45,10 +47,11 @@ export function useDataSource(propsRef, { getPaginationInfo, setPagination, setL } // 处理数据结构 const resultInfo = res[listField] ? res[listField] : res - dataSourceRef.value = dataType === 'tree' ? dealTree(resultInfo) : resultInfo + dataSourceRef.value = dataType === 'tree' ? dealTree(resultInfo.data) : resultInfo setPagination({ [pageField]: currentPage, - [totalField]: Math.ceil(resultTotal / pageSize) + [totalField]: Math.ceil(resultTotal / pageSize), + itemCount: resultTotal }) /* 更新页码数据 */ if (opt && opt[pageField]) { @@ -105,13 +108,13 @@ export function useDataSource(propsRef, { getPaginationInfo, setPagination, setL await fetch(opt) } - async function reFetch(opt) { + async function reFetch(opt, reload = true) { const { paginationSetting } = unref(propsRef) const pageField = paginationSetting.pageField const sizeField = paginationSetting.sizeField const pageSize = paginationSetting.pageSize setPagination({ - [pageField]: 1, + [pageField]: reload ? 1 : paginationPage.value, [sizeField]: pageSize }) await fetch(opt) diff --git a/src/components/DataTable/tools/usePagination.js b/src/components/DataTable/tools/usePagination.js index a8e8d7e..3af61c4 100644 --- a/src/components/DataTable/tools/usePagination.js +++ b/src/components/DataTable/tools/usePagination.js @@ -17,7 +17,10 @@ export function usePagination(refProps) { showQuickJumper: paginationSetting.showQuickJumper, ...(isBoolean(pagination) ? {} : pagination), ...unref(configRef), - pageCount: unref(configRef)[paginationSetting.totalField] + pageCount: unref(configRef)[paginationSetting.totalField], + prefix({ itemCount }) { + return `共 ${itemCount} 条` + } } }) diff --git a/src/components/Modal/index.vue b/src/components/Modal/index.vue index 81e1a96..4559862 100644 --- a/src/components/Modal/index.vue +++ b/src/components/Modal/index.vue @@ -1,5 +1,6 @@