表格组件增加数据总行数显示

This commit is contained in:
孟帅 2023-08-10 20:09:50 +08:00
parent 4069411156
commit 7fcf8fb73c
3 changed files with 10 additions and 1 deletions

View File

@ -33,11 +33,13 @@ func (req *PageReq) GetPerPage() int {
// PageRes 分页响应
type PageRes struct {
PageReq
PageCount int `json:"pageCount" example:"0" dc:"全部数据量"`
PageCount int `json:"pageCount" example:"0" dc:"分页个数"`
TotalCount int `json:"totalCount" example:"0" dc:"数据总行数"`
}
// Pack 打包分页数据
func (res *PageRes) Pack(req ReqPageFunc, totalCount int) {
res.TotalCount = totalCount
res.PageCount = CalPageCount(totalCount, req.GetPerPage())
res.Page = req.GetPage()
res.PerPage = req.GetPerPage()

View File

@ -53,6 +53,7 @@ export function useDataSource(
const sizeField = APISETTING.sizeField;
const totalField = APISETTING.totalField;
const listField = APISETTING.listField;
const itemCountField = APISETTING.itemCountField;
let pageParams = {};
const { page = 1, pageSize = 10 } = unref(getPaginationInfo) as PaginationProps;
@ -75,6 +76,7 @@ export function useDataSource(
const resultTotal = res[totalField] || 0;
const currentPage = res[pageField];
const itemCount = res[itemCountField] || 0;
// 如果数据异常,需获取正确的页码再次执行
if (resultTotal) {
@ -108,6 +110,9 @@ export function useDataSource(
setPagination({
[pageField]: currentPage,
[totalField]: resultTotal,
prefix: () => {
return `${itemCount}`;
},
});
if (opt && opt[pageField]) {
setPagination({

View File

@ -9,6 +9,8 @@ export default {
listField: 'list',
// 接口返回总页数字段名
totalField: 'pageCount',
// 接口返回总行数字段名
itemCountField: 'totalCount',
},
//默认分页数量
defaultPageSize: 10,