From 54152d65f2f1c64cc632b71339c085e18864ce43 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 9 Apr 2025 12:21:14 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E7=94=9F=E6=88=90=E4=BF=A1=E6=81=AF=E8=A1=A8=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/utils/constants.ts | 244 ++++++------ .../codegen/components/GenerateInfoForm.vue | 357 ------------------ apps/web-antd/src/views/infra/codegen/data.ts | 242 ++++++++++++ .../infra/codegen/modules/generation-info.vue | 207 ++++++++++ 4 files changed, 571 insertions(+), 479 deletions(-) delete mode 100644 apps/web-antd/src/views/infra/codegen/components/GenerateInfoForm.vue create mode 100644 apps/web-antd/src/views/infra/codegen/modules/generation-info.vue diff --git a/apps/web-antd/src/utils/constants.ts b/apps/web-antd/src/utils/constants.ts index 39803bb7d..ac1d8120a 100644 --- a/apps/web-antd/src/utils/constants.ts +++ b/apps/web-antd/src/utils/constants.ts @@ -9,14 +9,14 @@ // 全局通用状态枚举 export const CommonStatusEnum = { ENABLE: 0, // 开启 - DISABLE: 1 // 禁用 -} + DISABLE: 1, // 禁用 +}; // 全局用户类型枚举 export const UserTypeEnum = { MEMBER: 1, // 会员 - ADMIN: 2 // 管理员 -} + ADMIN: 2, // 管理员 +}; // ========== SYSTEM 模块 ========== /** @@ -25,16 +25,16 @@ export const UserTypeEnum = { export const SystemMenuTypeEnum = { DIR: 1, // 目录 MENU: 2, // 菜单 - BUTTON: 3 // 按钮 -} + BUTTON: 3, // 按钮 +}; /** * 角色的类型枚举 */ export const SystemRoleTypeEnum = { SYSTEM: 1, // 内置角色 - CUSTOM: 2 // 自定义角色 -} + CUSTOM: 2, // 自定义角色 +}; /** * 数据权限的范围枚举 @@ -44,8 +44,8 @@ export const SystemDataScopeEnum = { DEPT_CUSTOM: 2, // 指定部门数据权限 DEPT_ONLY: 3, // 部门数据权限 DEPT_AND_CHILD: 4, // 部门及以下数据权限 - DEPT_SELF: 5 // 仅本人数据权限 -} + DEPT_SELF: 5, // 仅本人数据权限 +}; /** * 用户的社交平台的类型枚举 @@ -55,15 +55,15 @@ export const SystemUserSocialTypeEnum = { title: '钉钉', type: 20, source: 'dingtalk', - img: 'https://s1.ax1x.com/2022/05/22/OzMDRs.png' + img: 'https://s1.ax1x.com/2022/05/22/OzMDRs.png', }, WECHAT_ENTERPRISE: { title: '企业微信', type: 30, source: 'wechat_enterprise', - img: 'https://s1.ax1x.com/2022/05/22/OzMrzn.png' - } -} + img: 'https://s1.ax1x.com/2022/05/22/OzMrzn.png', + }, +}; // ========== INFRA 模块 ========== /** @@ -72,8 +72,8 @@ export const SystemUserSocialTypeEnum = { export const InfraCodegenTemplateTypeEnum = { CRUD: 1, // 基础 CRUD TREE: 2, // 树形 CRUD - SUB: 3 // 主子表 CRUD -} + SUB: 15, // 主子表 CRUD +}; /** * 任务状态的枚举 @@ -81,8 +81,8 @@ export const InfraCodegenTemplateTypeEnum = { export const InfraJobStatusEnum = { INIT: 0, // 初始化中 NORMAL: 1, // 运行中 - STOP: 2 // 暂停运行 -} + STOP: 2, // 暂停运行 +}; /** * API 异常数据的处理状态 @@ -90,8 +90,8 @@ export const InfraJobStatusEnum = { export const InfraApiErrorLogProcessStatusEnum = { INIT: 0, // 未处理 DONE: 1, // 已处理 - IGNORE: 2 // 已忽略 -} + IGNORE: 2, // 已忽略 +}; // ========== PAY 模块 ========== /** @@ -100,78 +100,78 @@ export const InfraApiErrorLogProcessStatusEnum = { export const PayChannelEnum = { WX_PUB: { code: 'wx_pub', - name: '微信 JSAPI 支付' + name: '微信 JSAPI 支付', }, WX_LITE: { code: 'wx_lite', - name: '微信小程序支付' + name: '微信小程序支付', }, WX_APP: { code: 'wx_app', - name: '微信 APP 支付' + name: '微信 APP 支付', }, WX_NATIVE: { code: 'wx_native', - name: '微信 Native 支付' + name: '微信 Native 支付', }, WX_WAP: { code: 'wx_wap', - name: '微信 WAP 网站支付' + name: '微信 WAP 网站支付', }, WX_BAR: { code: 'wx_bar', - name: '微信条码支付' + name: '微信条码支付', }, ALIPAY_PC: { code: 'alipay_pc', - name: '支付宝 PC 网站支付' + name: '支付宝 PC 网站支付', }, ALIPAY_WAP: { code: 'alipay_wap', - name: '支付宝 WAP 网站支付' + name: '支付宝 WAP 网站支付', }, ALIPAY_APP: { code: 'alipay_app', - name: '支付宝 APP 支付' + name: '支付宝 APP 支付', }, ALIPAY_QR: { code: 'alipay_qr', - name: '支付宝扫码支付' + name: '支付宝扫码支付', }, ALIPAY_BAR: { code: 'alipay_bar', - name: '支付宝条码支付' + name: '支付宝条码支付', }, WALLET: { code: 'wallet', - name: '钱包支付' + name: '钱包支付', }, MOCK: { code: 'mock', - name: '模拟支付' - } -} + name: '模拟支付', + }, +}; /** * 支付的展示模式每局 */ export const PayDisplayModeEnum = { URL: { - mode: 'url' + mode: 'url', }, IFRAME: { - mode: 'iframe' + mode: 'iframe', }, FORM: { - mode: 'form' + mode: 'form', }, QR_CODE: { - mode: 'qr_code' + mode: 'qr_code', }, APP: { - mode: 'app' - } -} + mode: 'app', + }, +}; /** * 支付类型枚举 @@ -179,8 +179,8 @@ export const PayDisplayModeEnum = { export const PayType = { WECHAT: 'WECHAT', ALIPAY: 'ALIPAY', - MOCK: 'MOCK' -} + MOCK: 'MOCK', +}; /** * 支付订单状态枚举 @@ -188,17 +188,17 @@ export const PayType = { export const PayOrderStatusEnum = { WAITING: { status: 0, - name: '未支付' + name: '未支付', }, SUCCESS: { status: 10, - name: '已支付' + name: '已支付', }, CLOSED: { status: 20, - name: '未支付' - } -} + name: '未支付', + }, +}; // ========== MALL - 商品模块 ========== /** @@ -207,17 +207,17 @@ export const PayOrderStatusEnum = { export const ProductSpuStatusEnum = { RECYCLE: { status: -1, - name: '回收站' + name: '回收站', }, DISABLE: { status: 0, - name: '下架' + name: '下架', }, ENABLE: { status: 1, - name: '上架' - } -} + name: '上架', + }, +}; // ========== MALL - 营销模块 ========== /** @@ -226,13 +226,13 @@ export const ProductSpuStatusEnum = { export const CouponTemplateValidityTypeEnum = { DATE: { type: 1, - name: '固定日期可用' + name: '固定日期可用', }, TERM: { type: 2, - name: '领取之后可用' - } -} + name: '领取之后可用', + }, +}; /** * 优惠劵模板的领取方式的枚举 @@ -240,17 +240,17 @@ export const CouponTemplateValidityTypeEnum = { export const CouponTemplateTakeTypeEnum = { USER: { type: 1, - name: '直接领取' + name: '直接领取', }, ADMIN: { type: 2, - name: '指定发放' + name: '指定发放', }, REGISTER: { type: 3, - name: '新人券' - } -} + name: '新人券', + }, +}; /** * 营销的商品范围枚举 @@ -258,17 +258,17 @@ export const CouponTemplateTakeTypeEnum = { export const PromotionProductScopeEnum = { ALL: { scope: 1, - name: '通用劵' + name: '通用劵', }, SPU: { scope: 2, - name: '商品劵' + name: '商品劵', }, CATEGORY: { scope: 3, - name: '品类劵' - } -} + name: '品类劵', + }, +}; /** * 营销的条件类型枚举 @@ -276,13 +276,13 @@ export const PromotionProductScopeEnum = { export const PromotionConditionTypeEnum = { PRICE: { type: 10, - name: '满 N 元' + name: '满 N 元', }, COUNT: { type: 20, - name: '满 N 件' - } -} + name: '满 N 件', + }, +}; /** * 优惠类型枚举 @@ -290,13 +290,13 @@ export const PromotionConditionTypeEnum = { export const PromotionDiscountTypeEnum = { PRICE: { type: 1, - name: '满减' + name: '满减', }, PERCENT: { type: 2, - name: '折扣' - } -} + name: '折扣', + }, +}; // ========== MALL - 交易模块 ========== /** @@ -305,89 +305,89 @@ export const PromotionDiscountTypeEnum = { export const BrokerageBindModeEnum = { ANYTIME: { mode: 1, - name: '首次绑定' + name: '首次绑定', }, REGISTER: { mode: 2, - name: '注册绑定' + name: '注册绑定', }, OVERRIDE: { mode: 3, - name: '覆盖绑定' - } -} + name: '覆盖绑定', + }, +}; /** * 分佣模式枚举 */ export const BrokerageEnabledConditionEnum = { ALL: { condition: 1, - name: '人人分销' + name: '人人分销', }, ADMIN: { condition: 2, - name: '指定分销' - } -} + name: '指定分销', + }, +}; /** * 佣金记录业务类型枚举 */ export const BrokerageRecordBizTypeEnum = { ORDER: { type: 1, - name: '获得推广佣金' + name: '获得推广佣金', }, WITHDRAW: { type: 2, - name: '提现申请' - } -} + name: '提现申请', + }, +}; /** * 佣金提现状态枚举 */ export const BrokerageWithdrawStatusEnum = { AUDITING: { status: 0, - name: '审核中' + name: '审核中', }, AUDIT_SUCCESS: { status: 10, - name: '审核通过' + name: '审核通过', }, AUDIT_FAIL: { status: 20, - name: '审核不通过' + name: '审核不通过', }, WITHDRAW_SUCCESS: { status: 11, - name: '提现成功' + name: '提现成功', }, WITHDRAW_FAIL: { status: 21, - name: '提现失败' - } -} + name: '提现失败', + }, +}; /** * 佣金提现类型枚举 */ export const BrokerageWithdrawTypeEnum = { WALLET: { type: 1, - name: '钱包' + name: '钱包', }, BANK: { type: 2, - name: '银行卡' + name: '银行卡', }, WECHAT: { type: 3, - name: '微信' + name: '微信', }, ALIPAY: { type: 4, - name: '支付宝' - } -} + name: '支付宝', + }, +}; /** * 配送方式枚举 @@ -395,38 +395,38 @@ export const BrokerageWithdrawTypeEnum = { export const DeliveryTypeEnum = { EXPRESS: { type: 1, - name: '快递发货' + name: '快递发货', }, PICK_UP: { type: 2, - name: '到店自提' - } -} + name: '到店自提', + }, +}; /** * 交易订单 - 状态 */ export const TradeOrderStatusEnum = { UNPAID: { status: 0, - name: '待支付' + name: '待支付', }, UNDELIVERED: { status: 10, - name: '待发货' + name: '待发货', }, DELIVERED: { status: 20, - name: '已发货' + name: '已发货', }, COMPLETED: { status: 30, - name: '已完成' + name: '已完成', }, CANCELED: { status: 40, - name: '已取消' - } -} + name: '已取消', + }, +}; // ========== ERP - 企业资源计划 ========== @@ -436,31 +436,31 @@ export const ErpBizType = { PURCHASE_RETURN: 12, SALE_ORDER: 20, SALE_OUT: 21, - SALE_RETURN: 22 -} + SALE_RETURN: 22, +}; // ========== BPM 模块 ========== export const BpmModelType = { BPMN: 10, // BPMN 设计器 - SIMPLE: 20 // 简易设计器 -} + SIMPLE: 20, // 简易设计器 +}; export const BpmModelFormType = { NORMAL: 10, // 流程表单 - CUSTOM: 20 // 业务表单 -} + CUSTOM: 20, // 业务表单 +}; export const BpmProcessInstanceStatus = { NOT_START: -1, // 未开始 RUNNING: 1, // 审批中 APPROVE: 2, // 审批通过 REJECT: 3, // 审批不通过 - CANCEL: 4 // 已取消 -} + CANCEL: 4, // 已取消 +}; export const BpmAutoApproveType = { NONE: 0, // 不自动通过 APPROVE_ALL: 1, // 仅审批一次,后续重复的审批节点均自动通过 APPROVE_SEQUENT: 2, // 仅针对连续审批的节点自动通过 -} +}; diff --git a/apps/web-antd/src/views/infra/codegen/components/GenerateInfoForm.vue b/apps/web-antd/src/views/infra/codegen/components/GenerateInfoForm.vue deleted file mode 100644 index ef20fbc65..000000000 --- a/apps/web-antd/src/views/infra/codegen/components/GenerateInfoForm.vue +++ /dev/null @@ -1,357 +0,0 @@ - - - - - diff --git a/apps/web-antd/src/views/infra/codegen/data.ts b/apps/web-antd/src/views/infra/codegen/data.ts index 8accef7db..222542c01 100644 --- a/apps/web-antd/src/views/infra/codegen/data.ts +++ b/apps/web-antd/src/views/infra/codegen/data.ts @@ -2,8 +2,11 @@ import type { VbenFormSchema } from '#/adapter/form'; import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; import type { InfraCodegenApi } from '#/api/infra/codegen'; import type { InfraDataSourceConfigApi } from '#/api/infra/data-source-config'; +import type { SystemMenuApi } from '#/api/system/menu'; +import { z } from '#/adapter/form'; import { getRangePickerDefaultProps } from '#/utils/date'; +import { DICT_TYPE, getDictOptions } from '#/utils/dict'; import { useAccess } from '@vben/access'; @@ -102,6 +105,245 @@ export function useBasicInfoFormSchema(): VbenFormSchema[] { ]; } +/** 生成信息表单基础 schema */ +export function useGenerationInfoBaseFormSchema(menus: SystemMenuApi.SystemMenu[]): VbenFormSchema[] { + /** 菜单树选项 */ + const menuTreeProps = { + value: 'id', + title: 'name', + children: 'children', + }; + + return [ + { + component: 'Select', + fieldName: 'templateType', + label: '生成模板', + componentProps: { + class: 'w-full', + options: getDictOptions(DICT_TYPE.INFRA_CODEGEN_TEMPLATE_TYPE, 'number'), + }, + rules: z.number().min(1, { message: '生成模板不能为空' }), + }, + { + component: 'Select', + fieldName: 'frontType', + label: '前端类型', + componentProps: { + class: 'w-full', + options: getDictOptions(DICT_TYPE.INFRA_CODEGEN_FRONT_TYPE, 'number'), + }, + rules: z.number().min(1, { message: '前端类型不能为空' }), + }, + { + component: 'Select', + fieldName: 'scene', + label: '生成场景', + componentProps: { + class: 'w-full', + options: getDictOptions(DICT_TYPE.INFRA_CODEGEN_SCENE, 'number'), + }, + rules: z.number().min(1, { message: '生成场景不能为空' }), + }, + { + component: 'TreeSelect', + fieldName: 'parentMenuId', + label: '上级菜单', + help: '分配到指定菜单下,例如 系统管理', + componentProps: { + class: 'w-full', + showSearch: true, + treeData: menus, + fieldNames: menuTreeProps, + treeNodeFilterProp: 'title', + treeDefaultExpandAll: false, + treeCheckable: false, + placeholder: '请选择系统菜单', + }, + }, + { + component: 'Input', + fieldName: 'moduleName', + label: '模块名', + help: '模块名,即一级目录,例如 system、infra、tool 等等', + rules: z.string().min(1, { message: '模块名不能为空' }), + }, + { + component: 'Input', + fieldName: 'businessName', + label: '业务名', + help: '业务名,即二级目录,例如 user、permission、dict 等等', + rules: z.string().min(1, { message: '业务名不能为空' }), + }, + { + component: 'Input', + fieldName: 'className', + label: '类名称', + help: '类名称(首字母大写),例如SysUser、SysMenu、SysDictData 等等', + rules: z.string().min(1, { message: '类名称不能为空' }), + }, + { + component: 'Input', + fieldName: 'classComment', + label: '类描述', + help: '用作类描述,例如 用户', + rules: z.string().min(1, { message: '类描述不能为空' }), + }, + ]; +} + +/** 树表信息 schema */ +export function useTreeTableFormSchema(columns: InfraCodegenApi.CodegenColumn[] = []): VbenFormSchema[] { + return [ + { + component: 'Divider', + fieldName: 'treeDivider', + label: '', + renderComponentContent: () => { + return { + default: () => ['树表信息'], + }; + }, + formItemClass: 'md:col-span-2', + }, + { + component: 'Select', + fieldName: 'treeParentColumnId', + label: '父编号字段', + help: '树显示的父编码字段名, 如:parent_Id', + componentProps: { + class: 'w-full', + allowClear: true, + placeholder: '请选择', + options: columns.map((column) => ({ + label: column.columnName, + value: column.id, + })), + }, + }, + { + component: 'Select', + fieldName: 'treeNameColumnId', + label: '名称字段', + help: '树节点显示的名称字段,一般是name', + componentProps: { + class: 'w-full', + allowClear: true, + placeholder: '请选择', + options: columns.map((column) => ({ + label: column.columnName, + value: column.id, + })), + }, + }, + ]; +} + +/** 主子表信息 schema */ +export function useSubTableFormSchema( + columns: InfraCodegenApi.CodegenColumn[] = [], + tables: InfraCodegenApi.CodegenTable[] = [], + subColumns: InfraCodegenApi.CodegenColumn[] = [], + onSubTableNameSelected: (value: string) => void, +): VbenFormSchema[] { + return [ + { + component: 'Divider', + fieldName: 'subDivider', + label: '', + renderComponentContent: () => { + return { + default: () => ['主子表信息'], + }; + }, + formItemClass: 'md:col-span-2', + }, + { + component: 'Input', + fieldName: 'subJoinColumnId', + label: '关联子表的成员变量名', + help: '子表的成员变量名,默认为子表的名称', + componentProps: { + placeholder: '请输入', + }, + formItemClass: 'md:col-span-2', + }, + { + component: 'Select', + fieldName: 'subTableName', + label: '子表的表名', + help: '关联的子表的表名, 如:sys_user_post', + componentProps: { + class: 'w-full', + allowClear: true, + placeholder: '请选择', + options: tables.map((table) => ({ + label: `${table.tableName}:${table.tableComment}`, + value: table.tableName, + })), + onChange: onSubTableNameSelected, + }, + }, + { + component: 'Input', + fieldName: 'subTableClassName', + label: '子表的类名', + help: '子表的类名, 如:SysUserPost', + componentProps: { + placeholder: '请输入', + }, + }, + { + component: 'Select', + fieldName: 'subTableFkColumnId', + label: '子表的外键字段', + help: '子表的外键字段的编号,对应主表的主键', + componentProps: { + class: 'w-full', + allowClear: true, + placeholder: '请选择', + options: subColumns.map((column) => ({ + label: column.columnName, + value: column.id, + })), + }, + }, + { + component: 'Input', + fieldName: 'mainTableClassName', + label: '主表的类名', + help: '主表的类名, 如:SysUser', + componentProps: { + placeholder: '请输入', + }, + }, + { + component: 'Select', + fieldName: 'mainTableFKColumnId', + label: '主表的外键字段', + help: '子表的外键关联到主表的主键字段编号', + componentProps: { + class: 'w-full', + allowClear: true, + placeholder: '请选择', + options: columns.map((column) => ({ + label: column.columnName, + value: column.id, + })), + }, + }, + { + component: 'Input', + fieldName: 'subTableClassComment', + label: '子表的类描述', + help: '子表的描述,例如 用户岗位', + componentProps: { + placeholder: '请输入', + }, + }, + ]; +} + /** 列表的搜索表单 */ export function useGridFormSchema(): VbenFormSchema[] { return [ diff --git a/apps/web-antd/src/views/infra/codegen/modules/generation-info.vue b/apps/web-antd/src/views/infra/codegen/modules/generation-info.vue new file mode 100644 index 000000000..d745a7ea2 --- /dev/null +++ b/apps/web-antd/src/views/infra/codegen/modules/generation-info.vue @@ -0,0 +1,207 @@ + + +