2025-06-21 15:19:49 +00:00
|
|
|
import { z } from "zod";
|
2025-06-21 09:44:14 +00:00
|
|
|
|
|
|
|
// 基础用户 schema
|
|
|
|
export const baseUserSchema = z.object({
|
|
|
|
id: z.string(),
|
|
|
|
name: z.string().optional(),
|
|
|
|
email: z.string(),
|
|
|
|
password: z.string().optional(),
|
|
|
|
role: z.string().optional(),
|
|
|
|
createdAt: z.string(),
|
|
|
|
updatedAt: z.string().optional(),
|
2025-06-21 15:19:49 +00:00
|
|
|
});
|
2025-06-21 09:44:14 +00:00
|
|
|
|
|
|
|
// 基础添加用户 schema
|
|
|
|
export const baseAddUserSchema = z.object({
|
|
|
|
name: z.string().min(1, "姓名为必填项"),
|
|
|
|
email: z.string().email("请输入有效的邮箱地址"),
|
|
|
|
password: z.string().min(8, "密码长度8-32位").max(32, "密码长度8-32位"),
|
|
|
|
createdAt: z.string(),
|
2025-06-21 15:19:49 +00:00
|
|
|
});
|
2025-06-21 09:44:14 +00:00
|
|
|
|
|
|
|
// 基础编辑用户 schema
|
|
|
|
export const baseEditUserSchema = z.object({
|
|
|
|
id: z.string(),
|
|
|
|
name: z.string().min(1, "姓名为必填项"),
|
|
|
|
email: z.string().email("请输入有效的邮箱地址"),
|
|
|
|
password: z.string().min(8, "密码长度8-32位").max(32, "密码长度8-32位"),
|
|
|
|
createdAt: z.string(),
|
2025-06-21 15:19:49 +00:00
|
|
|
});
|
2025-06-21 09:44:14 +00:00
|
|
|
|
|
|
|
// 基础表格列配置
|
|
|
|
export const baseColumns = [
|
|
|
|
{ key: "id", label: "ID", sortable: true },
|
2025-06-21 15:19:49 +00:00
|
|
|
{
|
|
|
|
key: "name",
|
|
|
|
label: "姓名",
|
|
|
|
sortable: true,
|
|
|
|
searchable: true,
|
|
|
|
placeholder: "搜索姓名",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "email",
|
|
|
|
label: "邮箱",
|
|
|
|
sortable: true,
|
|
|
|
searchable: true,
|
|
|
|
placeholder: "搜索邮箱",
|
|
|
|
},
|
2025-06-21 09:44:14 +00:00
|
|
|
{ key: "createdAt", label: "创建时间", sortable: true },
|
2025-06-21 15:19:49 +00:00
|
|
|
];
|
2025-06-21 09:44:14 +00:00
|
|
|
|
|
|
|
// 基础表单字段配置
|
|
|
|
export const baseFormFields = [
|
2025-06-21 15:19:49 +00:00
|
|
|
{
|
|
|
|
key: "name",
|
|
|
|
label: "姓名",
|
|
|
|
type: "text",
|
|
|
|
placeholder: "请输入姓名",
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "email",
|
|
|
|
label: "邮箱",
|
|
|
|
type: "email",
|
|
|
|
placeholder: "请输入邮箱",
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "password",
|
|
|
|
label: "密码",
|
|
|
|
type: "password",
|
|
|
|
placeholder: "请输入8-32位密码",
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "createdAt",
|
|
|
|
label: "创建时间",
|
|
|
|
type: "datetime-local",
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
];
|
2025-06-21 09:44:14 +00:00
|
|
|
|
|
|
|
// 基础操作配置
|
|
|
|
export const baseActions = {
|
|
|
|
add: { label: "添加", icon: "PlusIcon" },
|
|
|
|
edit: { label: "编辑", icon: "PencilIcon" },
|
|
|
|
delete: { label: "删除", icon: "TrashIcon" },
|
|
|
|
batchDelete: { label: "批量删除", icon: "TrashIcon" },
|
2025-06-21 15:19:49 +00:00
|
|
|
};
|
2025-06-21 09:44:14 +00:00
|
|
|
|
|
|
|
// 基础分页配置
|
|
|
|
export const basePagination = {
|
|
|
|
pageSizes: [10, 50, 100, 500],
|
|
|
|
defaultPageSize: 10,
|
2025-06-21 15:19:49 +00:00
|
|
|
};
|
2025-06-21 09:44:14 +00:00
|
|
|
|
|
|
|
// 创建用户配置的工厂函数
|
|
|
|
export function createUserConfig(
|
|
|
|
userType: string,
|
|
|
|
title: string,
|
|
|
|
addLabel: string,
|
|
|
|
namePlaceholder: string,
|
|
|
|
emailPlaceholder: string
|
|
|
|
) {
|
|
|
|
return {
|
|
|
|
userType,
|
|
|
|
title,
|
|
|
|
apiPath: "/api/user",
|
|
|
|
columns: baseColumns,
|
2025-06-21 15:19:49 +00:00
|
|
|
formFields: baseFormFields.map((field) => ({
|
2025-06-21 09:44:14 +00:00
|
|
|
...field,
|
2025-06-21 15:19:49 +00:00
|
|
|
placeholder:
|
|
|
|
field.key === "name"
|
|
|
|
? namePlaceholder
|
|
|
|
: field.key === "email"
|
|
|
|
? emailPlaceholder
|
|
|
|
: field.placeholder,
|
2025-06-21 09:44:14 +00:00
|
|
|
})),
|
|
|
|
actions: {
|
|
|
|
...baseActions,
|
2025-06-21 15:19:49 +00:00
|
|
|
add: { ...baseActions.add, label: addLabel },
|
2025-06-21 09:44:14 +00:00
|
|
|
},
|
|
|
|
pagination: basePagination,
|
2025-06-21 15:19:49 +00:00
|
|
|
};
|
|
|
|
}
|