diff --git a/src/components/CreateCodeStep/src/ViewDesignStep.vue b/src/components/CreateCodeStep/src/ViewDesignStep.vue index 19c70a4..271a1fa 100644 --- a/src/components/CreateCodeStep/src/ViewDesignStep.vue +++ b/src/components/CreateCodeStep/src/ViewDesignStep.vue @@ -489,67 +489,77 @@ const loading = ref(true); const apiConfig = ref({}); - const handlerEnableAndDisableButtonConfig = () => { + const handlerEnableAndDisableButtonConfig = ()=>{ let hasValid = false; - // let fields = generatorConfig?.tableStructureConfigs[0]?.tableFieldConfigs; - let a = generatorConfig?.tableStructureConfigs || [] - let fields = (a[0] || {}).tableFieldConfigs; - if (fields != undefined) { + + if(generatorConfig.tableStructureConfigs!=undefined){ + let structure = generatorConfig.tableStructureConfigs; + let fields = structure!=undefined && structure.length > 0? structure[0].tableFieldConfigs:undefined; + if(fields!=undefined){ for (const field of fields) { - if (field?.fieldName == 'valid') { - hasValid = true; + if(field?.fieldName=='valid'){ + hasValid = true; + break; + } + } + } + }else{ + let fields = generatorConfig.formJson.list; + if(fields!=undefined){ + for (const field of fields) { + if(field?.bindField=='valid'){ + hasValid = true; + break; + } + } + } + } + + let buttonConfigs = generatorConfig?.listConfig?.buttonConfigs; + if(buttonConfigs==undefined) return; + if(hasValid){ + let hasBtn = false; + for (let i = 0; i < buttonConfigs.length; i++) { + let btn = buttonConfigs[i]; + if(btn.code=='enable' || btn.code=='disable'){ + hasBtn = true; + break; + } + } + if(!hasBtn){ + 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 < buttonConfigs.length; i++) { + let btn = buttonConfigs[i]; + if(btn.code=='enable' || btn.code=='disable'){ + dIndex = i; break; } - } + } + if(dIndex!=-1){ + buttonConfigs.splice(dIndex,1); + } + } while (dIndex!=-1); } - 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(() => { //如果已经有按钮设置了 就不再添加默认值