refactor: 重新生成单表代码生成预览

pull/78/head
puhui999 2025-04-22 14:57:11 +08:00
parent 062111502f
commit 6ca22ff155
4 changed files with 19 additions and 24 deletions

View File

@ -10,7 +10,7 @@ export namespace Demo03StudentApi {
name?: string; // 名字 name?: string; // 名字
score?: number; // 分数 score?: number; // 分数
} }
// TODO @puhui999要不要每个 interface 之间,有个空行
/** 学生班级信息 */ /** 学生班级信息 */
export interface Demo03Grade { export interface Demo03Grade {
id: number; // 编号 id: number; // 编号
@ -18,6 +18,7 @@ export namespace Demo03StudentApi {
name?: string; // 名字 name?: string; // 名字
teacher?: string; // 班主任 teacher?: string; // 班主任
} }
/** 学生信息 */ /** 学生信息 */
export interface Demo03Student { export interface Demo03Student {
id: number; // 编号 id: number; // 编号
@ -61,7 +62,7 @@ export function exportDemo03Student(params: any) {
} }
// ==================== 子表(学生课程) ==================== // ==================== 子表(学生课程) ====================
// TODO @puhui999==================== 后面,加个空行,会更清晰一点
/** 获得学生课程列表 */ /** 获得学生课程列表 */
export function getDemo03CourseListByStudentId(studentId: number) { export function getDemo03CourseListByStudentId(studentId: number) {
return requestClient.get<Demo03StudentApi.Demo03Course[]>( return requestClient.get<Demo03StudentApi.Demo03Course[]>(
@ -70,6 +71,7 @@ export function getDemo03CourseListByStudentId(studentId: number) {
} }
// ==================== 子表(学生班级) ==================== // ==================== 子表(学生班级) ====================
/** 获得学生班级 */ /** 获得学生班级 */
export function getDemo03GradeByStudentId(studentId: number) { export function getDemo03GradeByStudentId(studentId: number) {
return requestClient.get<Demo03StudentApi.Demo03Grade>( return requestClient.get<Demo03StudentApi.Demo03Grade>(

View File

@ -52,22 +52,16 @@ export function useFormSchema(): VbenFormSchema[] {
valueFormat: 'x', valueFormat: 'x',
}, },
}, },
// TODO 【富文本】@puhui999@芋艿:后续要封装下;单独 pr
{ {
fieldName: 'description', fieldName: 'description',
label: '简介', label: '简介',
rules: 'required', rules: 'required',
component: 'Editor', component: 'RichTextarea',
}, },
// TODO 【文件上传】@puhui999@芋艿:后续要封装下;单独 pr
{ {
fieldName: 'avatar', fieldName: 'avatar',
label: '头像', label: '头像',
component: 'FileUpload', component: 'ImageUpload',
componentProps: {
fileType: 'image',
maxCount: 1,
},
}, },
]; ];
} }
@ -91,6 +85,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
componentProps: { componentProps: {
allowClear: true, allowClear: true,
options: getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number'), options: getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number'),
placeholder: '请选择性别',
}, },
}, },
{ {

View File

@ -25,15 +25,9 @@ function onRefresh() {
gridApi.query(); gridApi.query();
} }
/** 导出表格 */
async function onExport() {
const data = await exportDemo01Contact(await gridApi.formApi.getValues());
downloadByData(data, '示例联系人.xls');
}
/** 创建示例联系人 */ /** 创建示例联系人 */
function onCreate() { function onCreate() {
formModalApi.setData(null).open(); formModalApi.setData({}).open();
} }
/** 编辑示例联系人 */ /** 编辑示例联系人 */
@ -60,18 +54,23 @@ async function onDelete(row: Demo01ContactApi.Demo01Contact) {
} }
} }
/** 导出表格 */
async function onExport() {
const data = await exportDemo01Contact(await gridApi.formApi.getValues());
downloadByData(data, '示例联系人.xls');
}
/** 表格操作按钮的回调函数 */ /** 表格操作按钮的回调函数 */
function onActionClick({ code, row }: OnActionClickParams<Demo01ContactApi.Demo01Contact>) { function onActionClick({ code, row }: OnActionClickParams<Demo01ContactApi.Demo01Contact>) {
switch (code) { switch (code) {
case 'delete': {
onDelete(row);
break;
}
// TODO @puhui999edit delete =>
case 'edit': { case 'edit': {
onEdit(row); onEdit(row);
break; break;
} }
case 'delete': {
onDelete(row);
break;
}
} }
} }

View File

@ -47,6 +47,7 @@ const [Modal, modalApi] = useVbenModal({
}, },
async onOpenChange(isOpen: boolean) { async onOpenChange(isOpen: boolean) {
if (!isOpen) { if (!isOpen) {
formData.value = undefined;
return; return;
} }
@ -55,9 +56,7 @@ const [Modal, modalApi] = useVbenModal({
if (!data) { if (!data) {
return; return;
} }
if (data.id) { if (data.id) {
// TODO @puhui99912data.id
modalApi.lock(); modalApi.lock();
try { try {
data = await getDemo01Contact(data.id); data = await getDemo01Contact(data.id);