fix: 代码生成器 模板内容预览 系统内容

This commit is contained in:
cuijiawang 2025-09-28 09:32:01 +08:00
parent 37f50ca1d3
commit 42c0433472
2 changed files with 31 additions and 15 deletions

View File

@ -219,7 +219,7 @@ export function toggleTemplateVisibilityApi(id: number, isEnabled: number) {
);
}
// 获取模板内容
// 获取模板内容(用户模板)
export function getTemplateContentApi(id: number | string) {
return http.request<ResponseData<string>>(
"get",
@ -227,6 +227,18 @@ export function getTemplateContentApi(id: number | string) {
);
}
// 获取模板内容(通用接口,支持系统和用户模板)
export function getTemplateContentBySourceApi(
templateSource: string,
templateId: string
) {
return http.request<ResponseData<string>>(
"get",
"/codegen/template/content",
{ params: { templateSource, templateId } }
);
}
// ============= 模板仓库管理 API =============
// 获取用户的模板仓库列表

View File

@ -7,7 +7,7 @@ import {
getUserRepositoryListApi,
toggleTemplateStatusApi,
previewTemplateCodeApi,
getTemplateContentApi,
getTemplateContentBySourceApi,
type TemplateRepository
} from "@/api/system/codegen";
@ -174,6 +174,11 @@ const previewTemplate = async (template: TemplateRepository) => {
previewLoading.value = true;
previewCode.value = "";
//
templateContentVisible.value = false;
templateContent.value = "";
templateContentLoading.value = false;
try {
// API使
const res = await previewTemplateCodeApi(
@ -200,6 +205,10 @@ const closePreview = () => {
previewVisible.value = false;
currentPreviewTemplate.value = null;
previewCode.value = "";
//
templateContentVisible.value = false;
templateContent.value = "";
templateContentLoading.value = false;
};
//
@ -224,20 +233,15 @@ const viewTemplateContent = async () => {
templateContent.value = "";
try {
if (currentPreviewTemplate.value?.templateSource === "system") {
//
templateContent.value = "// 系统模板内容(需要后端实现系统模板内容获取)";
// 使
const res = await getTemplateContentBySourceApi(
currentPreviewTemplate.value?.templateSource || "",
currentPreviewTemplate.value?.templateId || ""
);
if (res.code === 200) {
templateContent.value = res.data !== undefined ? res.data : "// 暂无内容";
} else {
//
const res = await getTemplateContentApi(
currentPreviewTemplate.value?.templateId || "0"
);
if (res.code === 200) {
templateContent.value =
res.data !== undefined ? res.data : "// 暂无内容";
} else {
templateContent.value = res.data || "// 获取失败";
}
templateContent.value = res.data || "// 获取失败";
}
templateContentVisible.value = true;
} catch (error) {