refactor: 更新API接口与数据结构,统一分页返回格式
This commit is contained in:
@@ -71,7 +71,7 @@
|
||||
import UserAPI from "@/api/system/user";
|
||||
import DeptAPI from "@/api/system/dept";
|
||||
import RoleAPI from "@/api/system/role";
|
||||
import type { UserForm, UserPageQuery } from "@/types/api";
|
||||
import type { UserForm, UserQueryParams, UserItem } from "@/types/api";
|
||||
import type { IObject, IModalConfig, IContentConfig, ISearchConfig } from "@/components/CURD/types";
|
||||
import { DeviceEnum } from "@/enums/settings";
|
||||
import { useAppStore } from "@/store";
|
||||
@@ -83,16 +83,16 @@ defineOptions({
|
||||
});
|
||||
|
||||
// ========================= 选项数据管理 =========================
|
||||
interface OptionType {
|
||||
interface OptionItem {
|
||||
label: string;
|
||||
value: any;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
// 共享选项数据
|
||||
const deptArr = ref<OptionType[]>([]);
|
||||
const roleArr = ref<OptionType[]>([]);
|
||||
const stateArr = ref<OptionType[]>([
|
||||
const deptArr = ref<OptionItem[]>([]);
|
||||
const roleArr = ref<OptionItem[]>([]);
|
||||
const stateArr = ref<OptionItem[]>([
|
||||
{ label: "启用", value: 1 },
|
||||
{ label: "禁用", value: 0 },
|
||||
]);
|
||||
@@ -165,7 +165,7 @@ const searchConfig: ISearchConfig = reactive({
|
||||
});
|
||||
|
||||
// ========================= 内容配置 =========================
|
||||
const contentConfig: IContentConfig<UserPageQuery> = reactive({
|
||||
const contentConfig: IContentConfig<UserQueryParams, UserItem> = reactive({
|
||||
permPrefix: "sys:user",
|
||||
table: {
|
||||
border: true,
|
||||
@@ -177,12 +177,6 @@ const contentConfig: IContentConfig<UserPageQuery> = reactive({
|
||||
pageSize: 20,
|
||||
pageSizes: [10, 20, 30, 50],
|
||||
},
|
||||
parseData(res: any) {
|
||||
return {
|
||||
total: res.total,
|
||||
list: res.list,
|
||||
};
|
||||
},
|
||||
indexAction(params: any) {
|
||||
return UserAPI.getPage(params);
|
||||
},
|
||||
@@ -198,8 +192,8 @@ const contentConfig: IContentConfig<UserPageQuery> = reactive({
|
||||
},
|
||||
async exportsAction(params: any) {
|
||||
const res = await UserAPI.getPage(params);
|
||||
console.log("exportsAction", res.list);
|
||||
return res.list;
|
||||
console.log("exportsAction", res.data);
|
||||
return res.data;
|
||||
},
|
||||
pk: "id",
|
||||
toolbar: [
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import UserAPI from "@/api/system/user";
|
||||
import RoleAPI from "@/api/system/role";
|
||||
import type { UserPageQuery } from "@/types/api";
|
||||
import type { UserQueryParams, UserItem } from "@/types/api";
|
||||
import type { IContentConfig } from "@/components/CURD/types";
|
||||
|
||||
const contentConfig: IContentConfig<UserPageQuery> = {
|
||||
const contentConfig: IContentConfig<UserQueryParams, UserItem> = {
|
||||
permPrefix: "sys:user", // 不写不进行按钮权限校验
|
||||
table: {
|
||||
border: true,
|
||||
@@ -15,12 +15,6 @@ const contentConfig: IContentConfig<UserPageQuery> = {
|
||||
pageSize: 20,
|
||||
pageSizes: [10, 20, 30, 50],
|
||||
},
|
||||
parseData(res) {
|
||||
return {
|
||||
total: res.total,
|
||||
list: res.list,
|
||||
};
|
||||
},
|
||||
indexAction(params) {
|
||||
return UserAPI.getPage(params);
|
||||
},
|
||||
@@ -38,8 +32,8 @@ const contentConfig: IContentConfig<UserPageQuery> = {
|
||||
async exportsAction(params) {
|
||||
// 模拟获取到的是全量数据
|
||||
const res = await UserAPI.getPage(params);
|
||||
console.log("exportsAction", res.list);
|
||||
return res.list;
|
||||
console.log("exportsAction", res.data);
|
||||
return res.data;
|
||||
},
|
||||
pk: "id",
|
||||
toolbar: [
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
import DeptAPI from "@/api/system/dept";
|
||||
import RoleAPI from "@/api/system/role";
|
||||
|
||||
interface OptionType {
|
||||
interface OptionItem {
|
||||
label: string;
|
||||
value: any;
|
||||
[key: string]: any; // 允许其他属性
|
||||
}
|
||||
|
||||
// 明确指定类型为 OptionType[]
|
||||
export const deptArr = ref<OptionType[]>([]);
|
||||
export const roleArr = ref<OptionType[]>([]);
|
||||
export const stateArr = ref<OptionType[]>([
|
||||
// 明确指定类型为 OptionItem[]
|
||||
export const deptArr = ref<OptionItem[]>([]);
|
||||
export const roleArr = ref<OptionItem[]>([]);
|
||||
export const stateArr = ref<OptionItem[]>([
|
||||
{ label: "启用", value: 1 },
|
||||
{ label: "禁用", value: 0 },
|
||||
]);
|
||||
|
||||
@@ -1,6 +1,27 @@
|
||||
import type { IContentConfig } from "@/components/CURD/types";
|
||||
|
||||
const contentConfig: IContentConfig = {
|
||||
interface DemoQueryParams {
|
||||
pageNum?: number;
|
||||
pageSize?: number;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface DemoItem {
|
||||
id: number;
|
||||
username: string;
|
||||
avatar: string;
|
||||
percent: number;
|
||||
price: number;
|
||||
url: string;
|
||||
icon: string;
|
||||
gender: number;
|
||||
status: number;
|
||||
status2: number;
|
||||
sort: number;
|
||||
createTime: number;
|
||||
}
|
||||
|
||||
const contentConfig: IContentConfig<DemoQueryParams, DemoItem> = {
|
||||
// permPrefix: "sys:demo", // 不写不进行按钮权限校验
|
||||
table: {
|
||||
showOverflowTooltip: true,
|
||||
@@ -10,38 +31,49 @@ const contentConfig: IContentConfig = {
|
||||
indexAction(params) {
|
||||
// 模拟发起网络请求获取列表数据
|
||||
console.log("indexAction:", params);
|
||||
const list = [
|
||||
{
|
||||
id: 1,
|
||||
username: "root",
|
||||
avatar: "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif",
|
||||
percent: 99,
|
||||
price: 10,
|
||||
url: "https://www.baidu.com",
|
||||
icon: "el-icon-setting",
|
||||
gender: 1,
|
||||
status: 1,
|
||||
status2: 1,
|
||||
sort: 99,
|
||||
createTime: 1715647982437,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
username: "jerry",
|
||||
avatar: "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif",
|
||||
percent: 88,
|
||||
price: 999,
|
||||
url: "https://www.google.com",
|
||||
icon: "el-icon-user",
|
||||
gender: 0,
|
||||
status: 0,
|
||||
status2: 0,
|
||||
sort: 0,
|
||||
createTime: 1715648977426,
|
||||
},
|
||||
];
|
||||
|
||||
const pageNum = Number(params?.pageNum ?? 1) || 1;
|
||||
const pageSize = Number(params?.pageSize ?? list.length) || list.length;
|
||||
const start = (pageNum - 1) * pageSize;
|
||||
const end = start + pageSize;
|
||||
|
||||
return Promise.resolve({
|
||||
total: 2,
|
||||
list: [
|
||||
{
|
||||
id: 1,
|
||||
username: "root",
|
||||
avatar: "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif",
|
||||
percent: 99,
|
||||
price: 10,
|
||||
url: "https://www.baidu.com",
|
||||
icon: "el-icon-setting",
|
||||
gender: 1,
|
||||
status: 1,
|
||||
status2: 1,
|
||||
sort: 99,
|
||||
createTime: 1715647982437,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
username: "jerry",
|
||||
avatar: "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif",
|
||||
percent: 88,
|
||||
price: 999,
|
||||
url: "https://www.google.com",
|
||||
icon: "el-icon-user",
|
||||
gender: 0,
|
||||
status: 0,
|
||||
status2: 0,
|
||||
sort: 0,
|
||||
createTime: 1715648977426,
|
||||
},
|
||||
],
|
||||
data: list.slice(start, end),
|
||||
page: {
|
||||
pageNum,
|
||||
pageSize,
|
||||
total: list.length,
|
||||
},
|
||||
});
|
||||
},
|
||||
modifyAction(data) {
|
||||
|
||||
Reference in New Issue
Block a user