From 68f1feb630980d5a4104b8571ee7e407f1752388 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Thu, 17 Apr 2025 16:27:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=A1=88=E4=BE=8B-=E4=B8=BB=E5=AD=90=E8=A1=A8=E6=A0=87?= =?UTF-8?q?=E5=87=86=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/api/infra/demo/demo03/normal/index.ts | 76 ++++++ .../views/infra/demo/demo03/normal/data.ts | 252 ++++++++++++++++++ .../views/infra/demo/demo03/normal/index.vue | 131 +++++++++ .../normal/modules/Demo03CourseForm.vue | 100 +++++++ .../demo03/normal/modules/Demo03GradeForm.vue | 43 +++ .../infra/demo/demo03/normal/modules/form.vue | 104 ++++++++ 6 files changed, 706 insertions(+) create mode 100644 apps/web-antd/src/api/infra/demo/demo03/normal/index.ts create mode 100644 apps/web-antd/src/views/infra/demo/demo03/normal/data.ts create mode 100644 apps/web-antd/src/views/infra/demo/demo03/normal/index.vue create mode 100644 apps/web-antd/src/views/infra/demo/demo03/normal/modules/Demo03CourseForm.vue create mode 100644 apps/web-antd/src/views/infra/demo/demo03/normal/modules/Demo03GradeForm.vue create mode 100644 apps/web-antd/src/views/infra/demo/demo03/normal/modules/form.vue diff --git a/apps/web-antd/src/api/infra/demo/demo03/normal/index.ts b/apps/web-antd/src/api/infra/demo/demo03/normal/index.ts new file mode 100644 index 000000000..85352c516 --- /dev/null +++ b/apps/web-antd/src/api/infra/demo/demo03/normal/index.ts @@ -0,0 +1,76 @@ +import type { PageParam, PageResult } from '@vben/request'; + +import { requestClient } from '#/api/request'; + +export namespace Demo03StudentApi { + /** 学生课程信息 */ + export interface Demo03Course { + id: number; // 编号 + studentId?: number; // 学生编号 + name?: string; // 名字 + score?: number; // 分数 + } + /** 学生班级信息 */ + export interface Demo03Grade { + id: number; // 编号 + studentId?: number; // 学生编号 + name?: string; // 名字 + teacher?: string; // 班主任 + } + /** 学生信息 */ + export interface Demo03Student { + id: number; // 编号 + name?: string; // 名字 + sex?: number; // 性别 + birthday?: Date; // 出生日期 + description?: string; // 简介 + demo03courses?: Demo03Course[]; + demo03grade?: Demo03Grade; + } +} + +/** 查询学生分页 */ +export function getDemo03StudentPage(params: PageParam) { + return requestClient.get>('/infra/demo03-student/page', { params }); +} + +/** 查询学生详情 */ +export function getDemo03Student(id: number) { + return requestClient.get(`/infra/demo03-student/get?id=${id}`); +} + +/** 新增学生 */ +export function createDemo03Student(data: Demo03StudentApi.Demo03Student) { + return requestClient.post('/infra/demo03-student/create', data); +} + +/** 修改学生 */ +export function updateDemo03Student(data: Demo03StudentApi.Demo03Student) { + return requestClient.put('/infra/demo03-student/update', data); +} + +/** 删除学生 */ +export function deleteDemo03Student(id: number) { + return requestClient.delete(`/infra/demo03-student/delete?id=${id}`); +} + +/** 导出学生 */ +export function exportDemo03Student(params: any) { + return requestClient.download('/infra/demo03-student/export-excel', params); +} + +// ==================== 子表(学生课程) ==================== +/** 获得学生课程列表 */ +export function getDemo03CourseListByStudentId(studentId: number) { + return requestClient.get( + `/infra/demo03-student/demo03-course/list-by-student-id?studentId=${studentId}`, + ); +} + +// ==================== 子表(学生班级) ==================== +/** 获得学生班级 */ +export function getDemo03GradeByStudentId(studentId: number) { + return requestClient.get( + `/infra/demo03-student/demo03-grade/get-by-student-id?studentId=${studentId}`, + ); +} diff --git a/apps/web-antd/src/views/infra/demo/demo03/normal/data.ts b/apps/web-antd/src/views/infra/demo/demo03/normal/data.ts new file mode 100644 index 000000000..1c32a0a4c --- /dev/null +++ b/apps/web-antd/src/views/infra/demo/demo03/normal/data.ts @@ -0,0 +1,252 @@ +import type { VbenFormSchema } from '#/adapter/form'; +import type { OnActionClickFn } from '#/adapter/vxe-table'; +import type { Demo03StudentApi } from '#/api/infra/demo/demo03/normal'; +import type { VxeTableGridOptions } from '@vben/plugins/vxe-table'; + +import { getRangePickerDefaultProps } from '#/utils/date'; +import { DICT_TYPE, getDictOptions } from '#/utils/dict'; + +import { useAccess } from '@vben/access'; + +const { hasAccessByCodes } = useAccess(); + +/** 新增/修改的表单 */ +export function useFormSchema(): VbenFormSchema[] { + return [ + { + fieldName: 'id', + component: 'Input', + dependencies: { + triggerFields: [''], + show: () => false, + }, + }, + { + fieldName: 'name', + label: '名字', + rules: 'required', + component: 'Input', + componentProps: { + placeholder: '请输入名字', + }, + }, + { + fieldName: 'sex', + label: '性别', + rules: 'required', + component: 'RadioGroup', + componentProps: { + options: getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number'), + buttonStyle: 'solid', + optionType: 'button', + }, + }, + { + fieldName: 'birthday', + label: '出生日期', + rules: 'required', + component: 'DatePicker', + componentProps: { + showTime: true, + format: 'YYYY-MM-DD HH:mm:ss', + valueFormat: 'x', + }, + }, + { + fieldName: 'description', + label: '简介', + rules: 'required', + component: 'Textarea', + }, + ]; +} + +/** 列表的搜索表单 */ +export function useGridFormSchema(): VbenFormSchema[] { + return [ + { + fieldName: 'name', + label: '名字', + component: 'Input', + componentProps: { + allowClear: true, + placeholder: '请输入名字', + }, + }, + { + fieldName: 'sex', + label: '性别', + component: 'Select', + componentProps: { + allowClear: true, + options: getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number'), + placeholder: '请选择性别', + }, + }, + { + fieldName: 'description', + label: '简介', + component: 'Input', + componentProps: { + allowClear: true, + placeholder: '请输入简介', + }, + }, + { + fieldName: 'createTime', + label: '创建时间', + component: 'RangePicker', + componentProps: { + ...getRangePickerDefaultProps(), + allowClear: true, + }, + }, + ]; +} + +/** 列表的字段 */ +export function useGridColumns( + onActionClick?: OnActionClickFn, +): VxeTableGridOptions['columns'] { + return [ + { + field: 'id', + title: '编号', + minWidth: 120, + }, + { + field: 'name', + title: '名字', + minWidth: 120, + }, + { + field: 'sex', + title: '性别', + minWidth: 120, + cellRender: { + name: 'CellDict', + props: { type: DICT_TYPE.SYSTEM_USER_SEX }, + }, + }, + { + field: 'birthday', + title: '出生日期', + minWidth: 120, + formatter: 'formatDateTime', + }, + { + field: 'description', + title: '简介', + minWidth: 120, + }, + { + field: 'createTime', + title: '创建时间', + minWidth: 120, + formatter: 'formatDateTime', + }, + { + field: 'operation', + title: '操作', + minWidth: 200, + align: 'center', + fixed: 'right', + headerAlign: 'center', + showOverflow: false, + cellRender: { + attrs: { + nameField: 'id', + nameTitle: '学生', + onClick: onActionClick, + }, + name: 'CellOperation', + options: [ + { + code: 'edit', + show: hasAccessByCodes(['infra:demo03-student:update']), + }, + { + code: 'delete', + show: hasAccessByCodes(['infra:demo03-student:delete']), + }, + ], + }, + }, + ]; +} + +// ==================== 子表(学生课程) ==================== +/** 列表的字段 */ +export function useDemo03CourseGridColumns( + onActionClick?: OnActionClickFn, +): VxeTableGridOptions['columns'] { + return [ + { + field: 'name', + title: '名字', + minWidth: 120, + slots: { default: 'name' }, + }, + { + field: 'score', + title: '分数', + minWidth: 120, + slots: { default: 'score' }, + }, + { + field: 'operation', + title: '操作', + minWidth: 60, + align: 'center', + fixed: 'right', + headerAlign: 'center', + showOverflow: false, + cellRender: { + attrs: { + nameField: 'id', + nameTitle: '学生', + onClick: onActionClick, + }, + name: 'CellOperation', + options: [ + { + code: 'delete', + show: hasAccessByCodes(['infra:demo03-student:delete']), + }, + ], + }, + }, + ]; +} +// ==================== 子表(学生班级) ==================== +/** 新增/修改的表单 */ +export function useDemo03GradeFormSchema(): VbenFormSchema[] { + return [ + { + fieldName: 'id', + component: 'Input', + dependencies: { + triggerFields: [''], + show: () => false, + }, + }, + { + fieldName: 'name', + label: '名字', + rules: 'required', + component: 'Input', + componentProps: { + placeholder: '请输入名字', + }, + }, + { + fieldName: 'teacher', + label: '班主任', + rules: 'required', + component: 'Input', + componentProps: { + placeholder: '请输入班主任', + }, + }, + ]; +} diff --git a/apps/web-antd/src/views/infra/demo/demo03/normal/index.vue b/apps/web-antd/src/views/infra/demo/demo03/normal/index.vue new file mode 100644 index 000000000..0a499d7dc --- /dev/null +++ b/apps/web-antd/src/views/infra/demo/demo03/normal/index.vue @@ -0,0 +1,131 @@ + + + diff --git a/apps/web-antd/src/views/infra/demo/demo03/normal/modules/Demo03CourseForm.vue b/apps/web-antd/src/views/infra/demo/demo03/normal/modules/Demo03CourseForm.vue new file mode 100644 index 000000000..a6ac61224 --- /dev/null +++ b/apps/web-antd/src/views/infra/demo/demo03/normal/modules/Demo03CourseForm.vue @@ -0,0 +1,100 @@ + + + diff --git a/apps/web-antd/src/views/infra/demo/demo03/normal/modules/Demo03GradeForm.vue b/apps/web-antd/src/views/infra/demo/demo03/normal/modules/Demo03GradeForm.vue new file mode 100644 index 000000000..7a54bd134 --- /dev/null +++ b/apps/web-antd/src/views/infra/demo/demo03/normal/modules/Demo03GradeForm.vue @@ -0,0 +1,43 @@ + + + diff --git a/apps/web-antd/src/views/infra/demo/demo03/normal/modules/form.vue b/apps/web-antd/src/views/infra/demo/demo03/normal/modules/form.vue new file mode 100644 index 000000000..6beddbf7b --- /dev/null +++ b/apps/web-antd/src/views/infra/demo/demo03/normal/modules/form.vue @@ -0,0 +1,104 @@ + + +