From 1f03da9ccb63a7efcc420c10811d3f26b3cbef4c Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 28 Mar 2025 22:26:02 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=88=9D=E5=A7=8B=E5=8C=96=20dept?= =?UTF-8?q?=20=E9=83=A8=E9=97=A8=EF=BC=88from=20=E5=AE=98=E6=96=B9=20examp?= =?UTF-8?q?le=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/views/system/dept/data.ts | 135 +++++++++++++++++ apps/web-antd/src/views/system/dept/index.vue | 143 ++++++++++++++++++ .../src/views/system/dept/modules/form.vue | 78 ++++++++++ 3 files changed, 356 insertions(+) create mode 100644 apps/web-antd/src/views/system/dept/data.ts create mode 100644 apps/web-antd/src/views/system/dept/index.vue create mode 100644 apps/web-antd/src/views/system/dept/modules/form.vue diff --git a/apps/web-antd/src/views/system/dept/data.ts b/apps/web-antd/src/views/system/dept/data.ts new file mode 100644 index 000000000..39d7034b4 --- /dev/null +++ b/apps/web-antd/src/views/system/dept/data.ts @@ -0,0 +1,135 @@ +import type { VxeTableGridOptions } from '@vben/plugins/vxe-table'; + +import type { VbenFormSchema } from '#/adapter/form'; +import type { OnActionClickFn } from '#/adapter/vxe-table'; +// import type { SystemDeptApi } from '#/api/system/dept'; + +import { z } from '#/adapter/form'; +// import { getDeptList } from '#/api/system/dept'; +import { $t } from '#/locales'; + +/** + * 获取编辑表单的字段配置。如果没有使用多语言,可以直接export一个数组常量 + */ +export function useSchema(): VbenFormSchema[] { + return [ + { + component: 'Input', + fieldName: 'name', + label: $t('system.dept.deptName'), + rules: z + .string() + .min(2, $t('ui.formRules.minLength', [$t('system.dept.deptName'), 2])) + .max( + 20, + $t('ui.formRules.maxLength', [$t('system.dept.deptName'), 20]), + ), + }, + // { + // component: 'ApiTreeSelect', + // componentProps: { + // allowClear: true, + // api: getDeptList, + // class: 'w-full', + // labelField: 'name', + // valueField: 'id', + // childrenField: 'children', + // }, + // fieldName: 'pid', + // label: $t('system.dept.parentDept'), + // }, + { + component: 'RadioGroup', + componentProps: { + buttonStyle: 'solid', + options: [ + { label: $t('common.enabled'), value: 1 }, + { label: $t('common.disabled'), value: 0 }, + ], + optionType: 'button', + }, + defaultValue: 1, + fieldName: 'status', + label: $t('system.dept.status'), + }, + { + component: 'Textarea', + componentProps: { + maxLength: 50, + rows: 3, + showCount: true, + }, + fieldName: 'remark', + label: $t('system.dept.remark'), + rules: z + .string() + .max(50, $t('ui.formRules.maxLength', [$t('system.dept.remark'), 50])) + .optional(), + }, + ]; +} + +/** + * 获取表格列配置 + * @description 使用函数的形式返回列数据而不是直接export一个Array常量,是为了响应语言切换时重新翻译表头 + * @param onActionClick 表格操作按钮点击事件 + */ +export function useColumns( + onActionClick?: OnActionClickFn, +): VxeTableGridOptions['columns'] { + return [ + { + align: 'left', + field: 'name', + fixed: 'left', + title: $t('system.dept.deptName'), + treeNode: true, + width: 150, + }, + { + cellRender: { name: 'CellTag' }, + field: 'status', + title: $t('system.dept.status'), + width: 100, + }, + { + field: 'createTime', + title: $t('system.dept.createTime'), + width: 180, + }, + { + field: 'remark', + title: $t('system.dept.remark'), + }, + { + align: 'right', + cellRender: { + attrs: { + nameField: 'name', + nameTitle: $t('system.dept.name'), + onClick: onActionClick, + }, + name: 'CellOperation', + options: [ + { + code: 'append', + text: '新增下级', + }, + 'edit', // 默认的编辑按钮 + { + code: 'delete', // 默认的删除按钮 + disabled: (row: SystemDeptApi.SystemDept) => { + return !!(row.children && row.children.length > 0); + }, + }, + ], + }, + field: 'operation', + fixed: 'right', + headerAlign: 'center', + showOverflow: false, + title: $t('system.dept.operation'), + width: 200, + }, + ]; +} diff --git a/apps/web-antd/src/views/system/dept/index.vue b/apps/web-antd/src/views/system/dept/index.vue new file mode 100644 index 000000000..4f7bfd1cd --- /dev/null +++ b/apps/web-antd/src/views/system/dept/index.vue @@ -0,0 +1,143 @@ + + diff --git a/apps/web-antd/src/views/system/dept/modules/form.vue b/apps/web-antd/src/views/system/dept/modules/form.vue new file mode 100644 index 000000000..0a03140a5 --- /dev/null +++ b/apps/web-antd/src/views/system/dept/modules/form.vue @@ -0,0 +1,78 @@ + + +