界面优先模板、简易模板:代码打包下载功能

This commit is contained in:
suguangxu
2025-04-24 15:05:13 +08:00
parent 56ea74d365
commit be3f19fb05
2 changed files with 59 additions and 13 deletions

View File

@ -25,9 +25,21 @@
<a-button type="primary" @click="handleStepNext" v-show="current < 5">
{{ t('下一步') }}
</a-button>
<a-button type="primary" @click="handleCodeGenerator" v-show="current === 5">
{{ t('完成') }}
</a-button>
<a-dropdown placement="bottom" :arrow="{ pointAtCenter: true }">
<a-button type="primary" v-show="current === 5">
{{ t('完成') }}
</a-button>
<template #overlay>
<a-menu>
<a-menu-item>
<a href="javascript:;" @click="handleCodeGenerator('packAndDownload')">打包下载</a>
</a-menu-item>
<a-menu-item>
<a href="javascript:;" @click="handleCodeGenerator('genCodeToProject')">生成到项目中</a>
</a-menu-item>
</a-menu>
</template>
</a-dropdown>
<a-button type="primary" danger @click="handleClose">{{ t('关闭') }}</a-button>
</div>
</div>
@ -57,6 +69,7 @@
getCodeTemplateInfo,
saveDraftGeneratorCode,
updateDraftGeneratorCode,
downloadCodes,
} from '/@/api/system/generator';
import { FormProps } from '/@/components/Form';
import { buildOption } from '/@/utils/helper/designHelper';
@ -73,6 +86,9 @@
import DesignLogo from '/@/components/ModalPanel/src/DesignLogo.vue';
import AjaxErrorIcon from '/@/components/SecondDev/AjaxErrorIcon.vue';
import useGlobalFlag from '/@/hooks/core/useGlobalFlag';
import { downloadByData } from '/@/utils/file/download';
import { dateUtil } from '/@/utils/dateUtil';
const { t } = useI18n();
const StructureConfigStep = defineAsyncComponent({
loader: () => import('/@/components/CreateCodeStep/src/StructureConfigStep.vue'),
@ -114,7 +130,6 @@
const widgetForm = ref(JSON.parse(JSON.stringify(antd.widgetForm))); //FormDesignStep -> designer和StructureConfigStep页面使用
const mainTableName = ref('table_' + random(10000, 99999));
const emit = defineEmits(['close', 'register', 'success']);
watch(current, () => {
isEditorOpen.value = current.value === 0;
});
@ -245,7 +260,7 @@
handleClose();
emit('success');
}
async function handleCodeGenerator() {
async function handleCodeGenerator(actionType:String) {
const isOk = await stepValidate[5]();
if (
generatorConfig.formJson?.hiddenComponent &&
@ -268,9 +283,16 @@
// await appGeneratorCode(
// buildAppCode(generatorConfig, buildAppFormProps(generatorConfig.formJson)),
// );
await codeFirstGeneratorCode(data);
data.actionType=actionType;
const result =await codeFirstGeneratorCode(data);
if(data.actionType=="packAndDownload"&&result){
const fileName=data.outputConfig.className+'_'+dateUtil(new Date()).format('YYYY-MM-DD_HH_mm_ss');
const res = await downloadCodes({uuid:result});
downloadByData(
res.data,
fileName+".zip"
);
}
handleClose();
emit('success');
}

View File

@ -24,9 +24,21 @@
<a-button type="primary" @click="handleStepNext" v-show="current < 5">
{{ t('下一步') }}
</a-button>
<a-button type="primary" @click="handleCodeGenerator" v-show="current === 5">
{{ t('完成') }}
</a-button>
<a-dropdown placement="bottom" :arrow="{ pointAtCenter: true }">
<a-button type="primary" v-show="current === 5">
{{ t('完成') }}
</a-button>
<template #overlay>
<a-menu>
<a-menu-item>
<a href="javascript:;" @click="handleCodeGenerator('packAndDownload')">打包下载</a>
</a-menu-item>
<a-menu-item>
<a href="javascript:;" @click="handleCodeGenerator('genCodeToProject')">生成到项目中</a>
</a-menu-item>
</a-menu>
</template>
</a-dropdown>
<a-button type="primary" danger @click="handleClose">{{ t('关闭') }}</a-button>
</div>
</div>
@ -57,6 +69,7 @@
saveDraftGeneratorCode,
updateDraftGeneratorCode,
getMasterInfo,
downloadCodes,
} from '/@/api/system/generator';
import { FormProps } from '/@/components/Form';
import { buildOption } from '/@/utils/helper/designHelper';
@ -71,6 +84,8 @@
import { MenuConfig } from '/@/model/generator/menuConfig';
import { FormEventColumnConfig } from '/@/model/generator/formEventConfig';
import DesignLogo from '/@/components/ModalPanel/src/DesignLogo.vue';
import { downloadByData } from '/@/utils/file/download';
import { dateUtil } from '/@/utils/dateUtil';
const { t } = useI18n();
const StructureConfigStep = defineAsyncComponent({
@ -244,7 +259,7 @@
handleClose();
emit('success');
}
async function handleCodeGenerator() {
async function handleCodeGenerator(actionType:String) {
const isOk = await stepValidate[5]();
if (
generatorConfig.formJson?.hiddenComponent &&
@ -263,7 +278,16 @@
buildOption(generatorConfig.formJson) as FormProps,
);
if (templateId.value) data.id = templateId.value;
await codeFirstGeneratorCode(data);
data.actionType=actionType;
const result =await codeFirstGeneratorCode(data);
if(data.actionType=="packAndDownload"&&result){
const fileName=data.outputConfig.className+'_'+dateUtil(new Date()).format('YYYY-MM-DD_HH_mm_ss');
const res = await downloadCodes({uuid:result});
downloadByData(
res.data,
fileName+".zip"
);
}
handleClose();
emit('success');
}