fix: 代码生成器

This commit is contained in:
cuijiawang
2025-09-27 18:51:50 +08:00
parent 0f6043ce01
commit 0f896a421c
2 changed files with 17 additions and 7 deletions

View File

@@ -277,11 +277,6 @@ const handleBatchDelete = async () => {
const handleToggleVisibility = async (row: UserTemplate, newValue: number) => {
const originalStatus = row.isEnabled; // 保存原始状态
try {
console.log("切换前端状态:", {
id: row.id,
original: originalStatus,
new: newValue
});
const res = await toggleTemplateVisibilityApi(row.id!, newValue);
if (res.code === 200) {
// 手动更新状态

View File

@@ -98,6 +98,17 @@ export function useCodegen() {
loading.value = true;
const { data } = await getAllTemplatesApi();
templates.value = data;
// 自动选择第一个可用模板
if (
data &&
data.length > 0 &&
data[0].templates &&
data[0].templates.length > 0
) {
const firstTemplate = data[0].templates[0];
currentSelect.value = firstTemplate.name;
}
} catch (error) {
console.error("加载模板失败:", error);
ElMessage.error("加载模板失败");
@@ -109,8 +120,12 @@ export function useCodegen() {
// 设置输出模板
function setOutputModel(template: TemplateInfo) {
currentSelect.value = template.name;
if (outputStr.value.length > 30) {
outputStr.value = outputJson.value[template.name] || "";
// 如果已经有生成的代码,立即切换显示对应模板的代码
if (outputJson.value && outputJson.value[template.name]) {
outputStr.value = outputJson.value[template.name];
} else if (Object.keys(outputJson.value).length > 0) {
// 如果当前模板没有生成代码,但有其他模板的代码,清空显示
outputStr.value = "";
}
}