From d9ea8d9604f0160a22f5c667e1a76c25bc7c71ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=A6=8F=E8=B4=A2?= <1471584931@qq.com> Date: Tue, 21 Oct 2025 17:59:52 +0800 Subject: [PATCH] =?UTF-8?q?--=E6=B7=BB=E5=8A=A0=E5=89=8D=E7=AB=AF=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E7=94=9F=E6=88=90=E4=BB=A3=E7=A0=81=20=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E5=90=AF=E7=94=A8=E3=80=81=E4=BD=9C=E5=BA=9F=E3=80=81?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CreateCodeStep/src/ViewDesignStep.vue | 67 +++++++++ src/utils/helper/generatorHelper.ts | 135 +++++++++++++++++- 2 files changed, 201 insertions(+), 1 deletion(-) diff --git a/src/components/CreateCodeStep/src/ViewDesignStep.vue b/src/components/CreateCodeStep/src/ViewDesignStep.vue index b2c95ad..27e5e55 100644 --- a/src/components/CreateCodeStep/src/ViewDesignStep.vue +++ b/src/components/CreateCodeStep/src/ViewDesignStep.vue @@ -640,6 +640,62 @@ const loading = ref(true); const apiConfig = ref({}); + + const handlerEnableAndDisableButtonConfig = ()=>{ + let hasValid = false; + let fields = generatorConfig?.tableStructureConfigs[0]?.tableFieldConfigs; + if(fields!=undefined){ + for (const field of fields) { + if(field?.fieldName=='valid'){ + hasValid = true; + break; + } + } + } + if(hasValid){ + let hasBtn = false; + for (let i = 0; i < generatorConfig.listConfig.buttonConfigs.length; i++) { + let btn = generatorConfig.listConfig.buttonConfigs[i]; + if(btn.code=='enable' || btn.code=='disable'){ + hasBtn = true; + break; + } + } + if(!hasBtn){ + generatorConfig.listConfig.buttonConfigs.splice(2,0,{ + isUse: true, + name: t('启用'), + code: 'enable', + icon: 'ant-design:form-outlined', + isDefault: true, + type: 'primary' + },{ + isUse: true, + name: t('作废'), + code: 'disable', + icon: 'ant-design:stop-outlined', + isDefault: true, + type: 'dashed' + }) + } + }else{ + let dIndex = -1; + do { + dIndex = -1; + for (let i = 0; i < generatorConfig.listConfig.buttonConfigs.length; i++) { + let btn = generatorConfig.listConfig.buttonConfigs[i]; + if(btn.code=='enable' || btn.code=='disable'){ + dIndex = i; + break; + } + } + if(dIndex!=-1){ + generatorConfig.listConfig.buttonConfigs.splice(dIndex,1); + } + } while (dIndex!=-1); + } + } + onMounted(() => { //如果已经有按钮设置了 就不再添加默认值 if ( @@ -690,6 +746,13 @@ icon: 'ant-design:delete-outlined', isDefault: true, }, + { + isUse: false, + name: t('数据日志'), + code: 'datalog', + icon: 'ant-design:profile-outlined', + isDefault: true, + }, { isUse: false, name: '复制数据', @@ -747,6 +810,8 @@ isDefault: true, }, ]; + + handlerEnableAndDisableButtonConfig(); } }); @@ -947,6 +1012,8 @@ generatorConfig.listConfig.columnConfigs.unshift(...columnConfigs); generatorConfig.listConfig.queryConfigs.unshift(...queryConfigs); } + + handlerEnableAndDisableButtonConfig(); }; watch( diff --git a/src/utils/helper/generatorHelper.ts b/src/utils/helper/generatorHelper.ts index f71317d..c668068 100644 --- a/src/utils/helper/generatorHelper.ts +++ b/src/utils/helper/generatorHelper.ts @@ -99,6 +99,8 @@ export function buildApiCode(model: GeneratorConfig, _tableInfo: TableInfo[]): s const pascalMainTableName = upperFirst(camelCase(camelCaseMainTableName)); const hasSetUserIdButton = hasButton(model.listConfig.buttonConfigs, 'batchSetUserId'); const hasExportButton = hasButton(model.listConfig.buttonConfigs, 'export'); + const hasEnableButton = hasButton(model.listConfig.buttonConfigs, 'enable'); + const hasDataLogButton = hasButton(model.listConfig.buttonConfigs, 'datalog'); const code = ` import { ${pascalMainTableName}PageModel, ${pascalMainTableName}PageParams, ${pascalMainTableName}PageResult } from './model/${pascalClassName}Model'; @@ -122,6 +124,19 @@ enum Api { Export = '/${model.outputConfig.outputValue}/${lowerFirstPascalClassName}/export',` : '' } + ${ + hasEnableButton + ? ` + Enable = '/${model.outputConfig.outputValue}/${lowerFirstPascalClassName}/enable', + Disable= '/${model.outputConfig.outputValue}/${lowerFirstPascalClassName}/disable',` + : '' + } + ${ + hasDataLogButton + ? ` + DataLog = '/${model.outputConfig.outputValue}/${lowerFirstPascalClassName}/datalog',` + : '' + } } /** @@ -199,6 +214,62 @@ export async function delete${pascalMainTableName}(ids: string[], mode: ErrorMes ); } +${ + hasEnableButton + ? ` +/** + * @description: 启用数据${pascalMainTableName} + */ +export async function enable${pascalMainTableName}(ids: string[], mode: ErrorMessageMode = 'modal') { + return defHttp.post( + { + url: Api.Enable, + data: ids, + }, + { + errorMessageMode: mode, + }, + ); +} +/** + * @description: 作废数据${pascalMainTableName} + */ +export async function disable${pascalMainTableName}(ids: string[], mode: ErrorMessageMode = 'modal') { + return defHttp.post( + { + url: Api.Disable, + data: ids, + }, + { + errorMessageMode: mode, + }, + ); +} + ` + : '' +} + +${ + hasDataLogButton? + ` + /** + * @description: 获取数据日志${pascalMainTableName} + */ + export async function getDataLog${pascalMainTableName}(id: string, mode: ErrorMessageMode = 'modal') { + return defHttp.post( + { + url: Api.Datalog, + data: id, + }, + { + errorMessageMode: mode, + }, + ); + } + ` + :'' +} + ${ hasSetUserIdButton ? ` @@ -469,6 +540,8 @@ export function buildListCode(model: GeneratorConfig): string { const hasCopyDataButton = hasButton(buttonConfigs, 'copyData'); const hasTemplatePrint = hasButton(buttonConfigs, PrintButton.CODE); const isSetDataAuth = model.outputConfig.isDataAuth; + const hasEnableButton = hasButton(buttonConfigs, 'enable'); + const hasDataLogButton = hasButton(buttonConfigs, 'datalog'); //判断是否有用到数据源数据字典的组件 const code = ` @@ -777,7 +850,7 @@ ${hasTemplatePrint ? ' reactive ' : ''} //所有按钮 const buttons = ref(${JSON.stringify(model.listConfig.buttonConfigs.filter((x) => x.isUse))}); //展示在列表内的按钮 - const actionButtons = ref(['view', 'edit', 'copyData', 'delete', 'startwork','flowRecord']); + const actionButtons = ref(['view', 'edit','datalog', 'copyData', 'delete', 'startwork','flowRecord']); const buttonConfigs = computed(()=>{ return filterButtonAuth(buttons.value); }) @@ -1108,6 +1181,66 @@ ${hasTemplatePrint ? ' reactive ' : ''} }` : '' } + ${ + hasEnableButton?` + function handleEnable() { + if (!selectedKeys.value.length) { + notification.warning({ + message: 'Tip', + description: t('请选择需要启用的数据'), + }); + return; + } + + let ids = selectedKeys.value; + Modal.confirm({ + title: '提示信息', + icon: createVNode(ExclamationCircleOutlined), + content: '是否确认启用?', + okText: '确认', + cancelText: '取消', + onOk() { + enable${pascalMainTableName}(ids).then((_) => { + handleSuccess(); + notification.success({ + message: 'Tip', + description: t('启用成功!'), + }); + }); + }, + onCancel() {}, + }); + + } + function handleDisable() { + if (!selectedKeys.value.length) { + notification.warning({ + message: 'Tip', + description: t('请选择需要禁用的数据'), + }); + return; + } + let ids = selectedKeys.value; + Modal.confirm({ + title: '提示信息', + icon: createVNode(ExclamationCircleOutlined), + content: '是否确认禁用?', + okText: '确认', + cancelText: '取消', + onOk() { + disable${pascalMainTableName}(ids).then((_) => { + handleSuccess(); + notification.success({ + message: 'Tip', + description: t('禁用成功!'), + }); + }); + }, + onCancel() {}, + }); + } + `: '' + } ${ hasBatchDeleteButton ? `