diff --git a/src/api/module_energy_report/report.ts b/src/api/module_energy_report/report.ts new file mode 100644 index 0000000..75d9245 --- /dev/null +++ b/src/api/module_energy_report/report.ts @@ -0,0 +1,302 @@ +// 能源报告模块接口 +// 包含:文件上传(通用)、能源报告模板(CRUD) +import { request } from "@utils"; + +const FILE_PATH = "/common/file"; +const TEMPLATE_PATH = "/attachment-template"; + +// ============ 文件上传(通用) ============ + +const FileAPI = { + /** + * 上传文件 + * @param file 文件本体 + * @param business_type 业务类型(能源报告模板固定传 energy_report_template) + * @param options 其他 query 参数 + */ + upload( + file: File, + business_type = "energy_report_template", + options?: { upload_type?: string; business_id?: number } + ) { + const formData = new FormData(); + formData.append("file", file); + const params: Record = { + business_type, + upload_type: options?.upload_type || "file", + }; + if (options?.business_id) { + params.business_id = options.business_id; + } + return request>({ + url: `${FILE_PATH}/upload`, + method: "post", + data: formData, + params, + headers: { "Content-Type": "multipart/form-data" }, + }); + }, + + /** 生成文件预签名访问地址(私有桶使用) */ + presigned(id: number) { + return request>({ + url: `${FILE_PATH}/presigned/${id}`, + method: "get", + }); + }, + + /** 删除文件记录(可选同时删 MinIO 对象) */ + remove(ids: number[], delete_object = false) { + return request({ + url: `${FILE_PATH}/delete`, + method: "delete", + data: ids, + params: delete_object ? { delete_object: true } : undefined, + }); + }, +}; + +// ============ 能源报告模板 ============ + +const ReportTemplateAPI = { + /** 查询模板分页列表 */ + page(query?: ReportTemplatePageQuery) { + return request>>({ + url: `${TEMPLATE_PATH}/list`, + method: "get", + params: query, + }); + }, + + /** 查询模板详情 */ + detail(id: number) { + return request>({ + url: `${TEMPLATE_PATH}/detail/${id}`, + method: "get", + }); + }, + + /** 创建模板 */ + create(body: ReportTemplateCreateForm) { + return request>({ + url: `${TEMPLATE_PATH}/create`, + method: "post", + data: body, + }); + }, + + /** 修改模板 */ + update(id: number, body: ReportTemplateUpdateForm) { + return request>({ + url: `${TEMPLATE_PATH}/update/${id}`, + method: "put", + data: body, + }); + }, + + /** 删除模板(传 ID 数组) */ + remove(ids: number[]) { + return request({ + url: `${TEMPLATE_PATH}/delete`, + method: "delete", + data: ids, + }); + }, +}; + +// ============ 章节标注与变量绑定 ============ + +const CHAPTER_PATH = "/chapter"; +const CONFIG_PATH = "/attachment-template/config/chapter"; +const VARIABLE_PATH = "/variable/chapter"; + +const ChapterAnnotationAPI = { + /** 查询模板下全部章节规则标注 */ + listByTemplate(templateId: number) { + return request>({ + url: `${CHAPTER_PATH}/list_by_template`, + method: "get", + params: { template_id: templateId }, + }); + }, + + /** 点击标注查看变量绑定 */ + getVariableConfig(chapterId: number) { + return request>({ + url: `${VARIABLE_PATH}/${chapterId}`, + method: "get", + }); + }, + + /** 新增单个章节标注并保存变量 */ + create(body: ChapterConfigForm) { + return request>({ + url: `${CONFIG_PATH}/create`, + method: "post", + data: body, + }); + }, + + /** 更新单个章节标注并保存变量 */ + update(chapterId: number, body: ChapterConfigForm) { + return request>({ + url: `${CONFIG_PATH}/update/${chapterId}`, + method: "put", + data: body, + }); + }, + + /** 删除章节规则标注(传 ID 数组) */ + remove(ids: number[]) { + return request({ + url: `${CHAPTER_PATH}/delete`, + method: "delete", + data: ids, + }); + }, +}; + +export { FileAPI, ReportTemplateAPI, ChapterAnnotationAPI }; +export default { FileAPI, ReportTemplateAPI, ChapterAnnotationAPI }; + +// ============ 类型定义 ============ + +/** 模板状态:0 启用 / 1 停用 */ +export type ReportTemplateStatus = 0 | 1; + +/** 文件记录对象(common_file) */ +export interface FileInfo { + id: number; + uuid?: string; + storage_type?: string; + bucket_name?: string; + object_name?: string; + original_name?: string; + origin_name?: string; + file_name?: string; + file_ext?: string; + content_type?: string; + file_size?: number; + file_path?: string; + file_url?: string; + upload_type?: string; + business_type?: string; + business_id?: number; +} + +/** 模板分页查询参数 */ +export interface ReportTemplatePageQuery { + page_no?: number; + page_size?: number; + order_by?: string; + template_name?: string; + template_type?: string; + version?: string; + status?: ReportTemplateStatus; + created_time?: string[]; + updated_time?: string[]; + created_id?: number; + updated_id?: number; + tenant_id?: number; +} + +/** 模板对象(后端返回) */ +export interface ReportTemplateItem { + id: number; + uuid?: string; + template_name: string; + template_type: string; + version?: string; + file_id: number; + status: ReportTemplateStatus; + order?: number; + description?: string; + /** 文件记录对象 */ + file?: FileInfo; + /** 文件访问地址,可直接用于下载 */ + file_url?: string; + /** 原始文件名 */ + original_name?: string; + /** MinIO 对象名称 */ + object_name?: string; + /** 标注数量(接口暂未返回,后续补充) */ + annotation_count?: number; + tenant_id?: number; + created_id?: number; + created_by?: CommonType; + updated_id?: number; + updated_by?: CommonType; + created_time?: string; + updated_time?: string; + is_deleted?: boolean; +} + +/** 创建模板表单 */ +export interface ReportTemplateCreateForm { + template_name: string; + template_type?: string; + version?: string; + file_id: number; + status?: ReportTemplateStatus; + order?: number; + description?: string; +} + +/** 修改模板表单 */ +export interface ReportTemplateUpdateForm extends ReportTemplateCreateForm {} + +// ============ 章节标注与变量绑定类型 ============ + +/** 章节规则标注(列表项) */ +export interface ChapterAnnotationItem { + id: number; + template_id: number; + chapter_name: string; + chapter_order?: number; + rule_id: number; + rule_name?: string; + description?: string; +} + +/** 变量绑定中的章节信息 */ +export interface VariableChapterInfo { + chapter_name: string; + annotation_ids: number[]; + rules: { chapter_annotation_id: number; rule_id: number; rule_name: string }[]; +} + +/** 变量绑定项 */ +export interface ChapterVariableItem { + variable_name: string; + chapter_names: string[]; + chapters?: VariableChapterInfo[]; + checked: boolean; +} + +/** 点击标注查看变量绑定的返回结构 */ +export interface ChapterVariableDetail { + chapter_annotation: { + id: number; + chapter_name: string; + rule_id: number; + rule_name?: string; + }; + variables: ChapterVariableItem[]; +} + +/** 创建/更新章节标注的请求体 */ +export interface ChapterConfigForm { + template_id: number; + chapters: { + id?: number; + chapter_name: string; + chapter_order?: number; + rule_id: number; + description?: string; + }[]; + variables: { + variable_name: string; + chapter_names: string[]; + checked?: boolean; + }[]; +} diff --git a/src/views/module_energy_report/promptVars.ts b/src/views/module_energy_report/promptVars.ts new file mode 100644 index 0000000..7bef14f --- /dev/null +++ b/src/views/module_energy_report/promptVars.ts @@ -0,0 +1,26 @@ +// 提示词模板变量解析工具 +// 支持形如 ${variable_name} 或 ${{ variable_name }} 的占位符 + +/** + * 从提示词模板中提取所有变量名。 + * 匹配规则: + * - ${xxx} + * - ${{ xxx }} + * 返回变量名数组(去重,按出现顺序) + */ +export function extractPromptVariables(prompt: string): string[] { + if (!prompt) return []; + const vars: string[] = []; + const set = new Set(); + // 同时匹配 ${var} 和 ${{ var }} + const re = /\$\{\s*([^{}]+?)\s*\}/g; + let m: RegExpExecArray | null; + while ((m = re.exec(prompt)) !== null) { + const name = m[1]?.trim(); + if (name && !set.has(name)) { + set.add(name); + vars.push(name); + } + } + return vars; +} diff --git a/src/views/module_energy_report/template/detail.vue b/src/views/module_energy_report/template/detail.vue new file mode 100644 index 0000000..485a38d --- /dev/null +++ b/src/views/module_energy_report/template/detail.vue @@ -0,0 +1,698 @@ + + + + + + diff --git a/src/views/module_energy_report/template/edit.vue b/src/views/module_energy_report/template/edit.vue new file mode 100644 index 0000000..647fc8f --- /dev/null +++ b/src/views/module_energy_report/template/edit.vue @@ -0,0 +1,1001 @@ + + + + + + diff --git a/src/views/module_energy_report/template/list.vue b/src/views/module_energy_report/template/list.vue new file mode 100644 index 0000000..de9e6e2 --- /dev/null +++ b/src/views/module_energy_report/template/list.vue @@ -0,0 +1,749 @@ + + + + + +