refactor: 更新API接口与数据结构,统一分页返回格式

This commit is contained in:
Ray.Hao
2026-01-09 00:07:25 +08:00
parent 4a8efc770e
commit a5885d0710
64 changed files with 1085 additions and 910 deletions

View File

@@ -870,13 +870,11 @@ function fetchPageData(formData: IObject = {}, isRestart = false) {
)
.then((data) => {
if (showPagination) {
if (props.contentConfig.parseData) {
data = props.contentConfig.parseData(data);
}
pagination.total = data.total;
pageData.value = data.list;
const pageResult = Array.isArray(data) ? { data, page: null } : data;
pagination.total = pageResult.page?.total ?? 0;
pageData.value = pageResult.data ?? [];
} else {
pageData.value = data;
pageData.value = Array.isArray(data) ? data : (data.data ?? []);
}
})
.finally(() => {

View File

@@ -55,7 +55,7 @@ export interface ISearchConfig {
grid?: boolean | "left" | "right";
}
export interface IContentConfig<T = any> {
export interface IContentConfig<TQuery = any, TItem = any> {
// 权限前缀(如sys:user用于组成权限标识),不提供则不进行权限校验
permPrefix?: string;
// table组件属性
@@ -72,18 +72,13 @@ export interface IContentConfig<T = any> {
>
>;
// 列表的网络请求函数(需返回promise)
indexAction: (queryParams: T) => Promise<any>;
indexAction: (queryParams: TQuery) => Promise<PageResult<TItem> | TItem[]>;
// 默认的分页相关的请求参数
request?: {
pageName: string;
limitName: string;
};
// 数据格式解析的回调函数
parseData?: (res: any) => {
total: number;
list: IObject[];
[key: string]: any;
};
// 分页接口统一返回 PageResult { data, page }
// 修改属性的网络请求函数(需返回promise)
modifyAction?: (data: {
[key: string]: any;
@@ -93,9 +88,9 @@ export interface IContentConfig<T = any> {
// 删除的网络请求函数(需返回promise)
deleteAction?: (ids: string) => Promise<any>;
// 后端导出的网络请求函数(需返回promise)
exportAction?: (queryParams: T) => Promise<any>;
exportAction?: (queryParams: TQuery) => Promise<any>;
// 前端全量导出的网络请求函数(需返回promise)
exportsAction?: (queryParams: T) => Promise<IObject[]>;
exportsAction?: (queryParams: TQuery) => Promise<TItem[]>;
// 导入模板
importTemplate?: string | (() => Promise<any>);
// 后端导入的网络请求函数(需返回promise)

View File

@@ -2,7 +2,7 @@
* 通知中心逻辑
*/
import { ref, onMounted, onBeforeUnmount } from "vue";
import type { NoticePageVo, NoticeDetailVo, NoticePageQuery } from "@/types/api";
import type { NoticeItem, NoticeDetail, NoticeQueryParams } from "@/types/api";
import NoticeAPI from "@/api/system/notice";
import { useStomp } from "@/composables";
import router from "@/router";
@@ -13,8 +13,8 @@ export function useNotice() {
const { subscribe, unsubscribe, isConnected } = useStomp();
// 状态
const list = ref<NoticePageVo[]>([]);
const detail = ref<NoticeDetailVo | null>(null);
const list = ref<NoticeItem[]>([]);
const detail = ref<NoticeDetail | null>(null);
const dialogVisible = ref(false);
let subscribed = false;
@@ -23,15 +23,15 @@ export function useNotice() {
// 数据获取
// ============================================
async function fetchList(params?: Partial<NoticePageQuery>) {
const query: NoticePageQuery = {
async function fetchList(params?: Partial<NoticeQueryParams>) {
const query: NoticeQueryParams = {
pageNum: 1,
pageSize: PAGE_SIZE,
isRead: 0,
...params,
} as NoticePageQuery;
};
const page = await NoticeAPI.getMyNoticePage(query);
list.value = page.list || [];
list.value = page.data || [];
}
async function read(id: string) {
@@ -39,7 +39,7 @@ export function useNotice() {
dialogVisible.value = true;
// 从列表中移除已读项
const idx = list.value.findIndex((item: NoticePageVo) => item.id === id);
const idx = list.value.findIndex((item: NoticeItem) => item.id === id);
if (idx >= 0) list.value.splice(idx, 1);
}
@@ -65,14 +65,14 @@ export function useNotice() {
if (!data.id) return;
// 避免重复
if (list.value.some((item: NoticePageVo) => item.id === data.id)) return;
if (list.value.some((item: NoticeItem) => item.id === data.id)) return;
list.value.unshift({
id: data.id,
title: data.title,
type: data.type,
publishTime: data.publishTime,
} as NoticePageVo);
} as NoticeItem);
ElNotification({
title: "您收到一条新的通知消息!",

View File

@@ -261,9 +261,9 @@ function fetchPageData(isRestart = false) {
}
props.selectConfig
.indexAction(queryParams)
.then((data) => {
total.value = data.total;
pageData.value = data.list;
.then((res) => {
total.value = res.page?.total ?? 0;
pageData.value = res.data ?? [];
})
.finally(() => {
loading.value = false;