fix: 代码生成器 模板内容预览 系统内容
This commit is contained in:
parent
37f50ca1d3
commit
42c0433472
@ -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 =============
|
||||
|
||||
// 获取用户的模板仓库列表
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user