From 6d164a77fe512ba412bf7dc617a0599e473c3332 Mon Sep 17 00:00:00 2001 From: Nelson <1475262689@qq.com> Date: Fri, 10 Jul 2026 12:16:01 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8B=86=E5=88=86=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E7=B3=BB=E7=BB=9F=E9=85=8D=E7=BD=AE=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apps/admin-web/src/App.vue | 278 +----------------- .../admin-web/src/config/systemSettings.ts | 277 +++++++++++++++++ 2 files changed, 278 insertions(+), 277 deletions(-) create mode 100644 ai_knowledge_base_v2/apps/admin-web/src/config/systemSettings.ts diff --git a/ai_knowledge_base_v2/apps/admin-web/src/App.vue b/ai_knowledge_base_v2/apps/admin-web/src/App.vue index 3c64565..ca63490 100644 --- a/ai_knowledge_base_v2/apps/admin-web/src/App.vue +++ b/ai_knowledge_base_v2/apps/admin-web/src/App.vue @@ -3,6 +3,7 @@ import { ElMessage, ElMessageBox } from "element-plus"; import { computed, onMounted, reactive, ref } from "vue"; import AdminLoginView from "./components/AdminLoginView.vue"; +import { systemSettingDefinitions, systemSettingSections, type SystemSettingValue } from "./config/systemSettings"; import { api, clearToken, getToken, saveToken } from "./services/api"; import type { AdminProfile, @@ -170,283 +171,6 @@ const nullableModelFields = [ "remark", ] as const; -type SystemSettingValue = string | number | boolean; -type SystemSettingType = "number" | "switch" | "text" | "password"; - -interface SystemSettingDefinition { - key: string; - label: string; - type: SystemSettingType; - defaultValue: SystemSettingValue; - min?: number; - max?: number; - placeholder?: string; - description: string; -} - -interface SystemSettingSection { - title: string; - description: string; - settings: SystemSettingDefinition[]; -} - -const systemSettingSections: SystemSettingSection[] = [ - { - title: "用户与登录", - description: "控制学员准入、默认资料、验证码和登录态有效时间。", - settings: [ - { - key: "daily_chat_limit", - label: "默认每日聊天额度", - type: "number", - defaultValue: 100, - min: 0, - max: 100000, - description: "新建或导入学员未单独填写额度时使用。", - }, - { - key: "access_token_expire_minutes", - label: "登录 Token 有效期(分钟)", - type: "number", - defaultValue: 43200, - min: 5, - max: 43200, - description: "用户端和管理端登录后的 Token 有效期。", - }, - { - key: "sms_code_expire_minutes", - label: "验证码有效期(分钟)", - type: "number", - defaultValue: 5, - min: 1, - max: 60, - description: "短信验证码生成后的可使用时间。", - }, - { - key: "mock_sms_enabled", - label: "使用 mock 短信", - type: "switch", - defaultValue: true, - description: "开发和演示环境可开启,生产环境应关闭并接入真实短信。", - }, - { - key: "mock_sms_code", - label: "mock 短信验证码", - type: "text", - defaultValue: "123456", - placeholder: "例如 123456", - description: "mock 短信开启时使用的固定验证码。", - }, - { - key: "aliyun_sms_access_key_id", - label: "阿里云 AccessKey ID", - type: "password", - defaultValue: "", - placeholder: "请输入 RAM 用户 AccessKey ID", - description: "关闭 mock 短信后用于调用阿里云短信服务。", - }, - { - key: "aliyun_sms_access_key_secret", - label: "阿里云 AccessKey Secret", - type: "password", - defaultValue: "", - placeholder: "请输入 RAM 用户 AccessKey Secret", - description: "敏感配置,建议使用最小权限 RAM 用户。", - }, - { - key: "aliyun_sms_sign_name", - label: "阿里云短信签名", - type: "text", - defaultValue: "", - placeholder: "例如 某某课堂", - description: "需与阿里云短信控制台审核通过的签名一致。", - }, - { - key: "aliyun_sms_template_code", - label: "阿里云模板 Code", - type: "text", - defaultValue: "", - placeholder: "例如 SMS_123456789", - description: "验证码短信模板 Code。", - }, - { - key: "aliyun_sms_template_param_key", - label: "验证码变量名", - type: "text", - defaultValue: "code", - placeholder: "默认 code", - description: "模板中验证码变量名,例如模板变量为 ${code} 时填写 code。", - }, - { - key: "aliyun_sms_endpoint", - label: "阿里云短信 Endpoint", - type: "text", - defaultValue: "dysmsapi.aliyuncs.com", - placeholder: "dysmsapi.aliyuncs.com", - description: "一般保持默认值即可。", - }, - { - key: "default_user_name_prefix", - label: "默认用户名前缀", - type: "text", - defaultValue: "用户", - placeholder: "例如 用户", - description: "系统需要生成默认名称时使用的前缀。", - }, - ], - }, - { - title: "AI 问答", - description: "控制 Agent 调用、上下文和用户端回答展示策略。", - settings: [ - { - key: "ai_timeout_seconds", - label: "AI 请求超时(秒)", - type: "number", - defaultValue: 60, - min: 5, - max: 300, - description: "真实模型请求超过该时间应判定为超时。", - }, - { - key: "mock_model_enabled", - label: "使用 mock 大模型", - type: "switch", - defaultValue: true, - description: "开发和演示环境可开启,真实模型验收前应关闭。", - }, - { - key: "chat_context_message_count", - label: "上下文消息数", - type: "number", - defaultValue: 10, - min: 0, - max: 100, - description: "组装 Prompt 时带入的历史消息数量。", - }, - { - key: "show_reference_sources", - label: "用户端展示引用来源", - type: "switch", - defaultValue: true, - description: "后台始终记录引用;此项控制用户端是否展示。", - }, - { - key: "chat_max_active_requests", - label: "问答最大并发数", - type: "number", - defaultValue: 2, - min: 1, - max: 1000, - description: "同一后端进程内同时进入飞书和模型生成链路的最大请求数。", - }, - { - key: "chat_max_queue_size", - label: "问答最大排队数", - type: "number", - defaultValue: 20, - min: 0, - max: 10000, - description: "超过最大并发后允许等待的请求数量,超过后直接提示稍后再试。", - }, - { - key: "chat_queue_timeout_seconds", - label: "问答排队超时(秒)", - type: "number", - defaultValue: 60, - min: 1, - max: 3600, - description: "请求在排队中超过该时间后自动结束并提示用户稍后再试。", - }, - { - key: "chat_active_lease_seconds", - label: "问答执行租约(秒)", - type: "number", - defaultValue: 900, - min: 60, - max: 86400, - description: "Redis 全局队列中执行名额的自动过期时间,防止 worker 异常退出后长期占用并发名额。", - }, - ], - }, - { - title: "外部服务", - description: "控制飞书搜索接口、飞书直读超时和重试策略。", - settings: [ - { - key: "feishu_search_url", - label: "飞书检索服务地址", - type: "text", - defaultValue: "", - placeholder: "例如 https://example.com/search", - description: "如使用独立飞书检索适配服务,在这里填写调用地址。", - }, - { - key: "feishu_app_id", - label: "飞书应用 AppID", - type: "text", - defaultValue: "", - placeholder: "填写飞书开放平台应用 AppID", - description: "用于后端直读飞书知识库;系统设置优先于环境变量。", - }, - { - key: "feishu_app_secret", - label: "飞书应用 AppSecret", - type: "password", - defaultValue: "", - placeholder: "填写飞书开放平台应用 AppSecret", - description: "用于后端获取飞书 tenant_access_token,保存后立即生效。", - }, - { - key: "feishu_timeout_seconds", - label: "飞书请求超时(秒)", - type: "number", - defaultValue: 20, - min: 1, - max: 120, - description: "飞书相关接口调用超过该时间应判定为超时。", - }, - { - key: "feishu_retry_count", - label: "飞书检索重试次数", - type: "number", - defaultValue: 2, - min: 0, - max: 10, - description: "飞书检索失败时的最大重试次数。", - }, - ], - }, - { - title: "系统开关", - description: "控制系统级展示和运行策略,不包含密钥类配置。", - settings: [ - { - key: "show_operation_log_detail", - label: "展示操作日志详情", - type: "switch", - defaultValue: true, - description: "开启后后台审计页可展示更完整的操作上下文。", - }, - { - key: "chat_export_enabled", - label: "允许导出聊天记录", - type: "switch", - defaultValue: true, - description: "关闭后后台不应提供聊天记录导出能力。", - }, - { - key: "maintenance_mode", - label: "维护模式", - type: "switch", - defaultValue: false, - description: "预留给后续停机维护提示和访问控制使用。", - }, - ], - }, -]; - -const systemSettingDefinitions = systemSettingSections.flatMap((section) => section.settings); const systemSettingValues = reactive>({}); systemSettingDefinitions.forEach((setting) => { systemSettingValues[setting.key] = setting.defaultValue; diff --git a/ai_knowledge_base_v2/apps/admin-web/src/config/systemSettings.ts b/ai_knowledge_base_v2/apps/admin-web/src/config/systemSettings.ts new file mode 100644 index 0000000..f7d807d --- /dev/null +++ b/ai_knowledge_base_v2/apps/admin-web/src/config/systemSettings.ts @@ -0,0 +1,277 @@ +export type SystemSettingValue = string | number | boolean; +type SystemSettingType = "number" | "switch" | "text" | "password"; + +export interface SystemSettingDefinition { + key: string; + label: string; + type: SystemSettingType; + defaultValue: SystemSettingValue; + min?: number; + max?: number; + placeholder?: string; + description: string; +} + +export interface SystemSettingSection { + title: string; + description: string; + settings: SystemSettingDefinition[]; +} + +export const systemSettingSections: SystemSettingSection[] = [ + { + title: "用户与登录", + description: "控制学员准入、默认资料、验证码和登录态有效时间。", + settings: [ + { + key: "daily_chat_limit", + label: "默认每日聊天额度", + type: "number", + defaultValue: 100, + min: 0, + max: 100000, + description: "新建或导入学员未单独填写额度时使用。", + }, + { + key: "access_token_expire_minutes", + label: "登录 Token 有效期(分钟)", + type: "number", + defaultValue: 43200, + min: 5, + max: 43200, + description: "用户端和管理端登录后的 Token 有效期。", + }, + { + key: "sms_code_expire_minutes", + label: "验证码有效期(分钟)", + type: "number", + defaultValue: 5, + min: 1, + max: 60, + description: "短信验证码生成后的可使用时间。", + }, + { + key: "mock_sms_enabled", + label: "使用 mock 短信", + type: "switch", + defaultValue: true, + description: "开发和演示环境可开启,生产环境应关闭并接入真实短信。", + }, + { + key: "mock_sms_code", + label: "mock 短信验证码", + type: "text", + defaultValue: "123456", + placeholder: "例如 123456", + description: "mock 短信开启时使用的固定验证码。", + }, + { + key: "aliyun_sms_access_key_id", + label: "阿里云 AccessKey ID", + type: "password", + defaultValue: "", + placeholder: "请输入 RAM 用户 AccessKey ID", + description: "关闭 mock 短信后用于调用阿里云短信服务。", + }, + { + key: "aliyun_sms_access_key_secret", + label: "阿里云 AccessKey Secret", + type: "password", + defaultValue: "", + placeholder: "请输入 RAM 用户 AccessKey Secret", + description: "敏感配置,建议使用最小权限 RAM 用户。", + }, + { + key: "aliyun_sms_sign_name", + label: "阿里云短信签名", + type: "text", + defaultValue: "", + placeholder: "例如 某某课堂", + description: "需与阿里云短信控制台审核通过的签名一致。", + }, + { + key: "aliyun_sms_template_code", + label: "阿里云模板 Code", + type: "text", + defaultValue: "", + placeholder: "例如 SMS_123456789", + description: "验证码短信模板 Code。", + }, + { + key: "aliyun_sms_template_param_key", + label: "验证码变量名", + type: "text", + defaultValue: "code", + placeholder: "默认 code", + description: "模板中验证码变量名,例如模板变量为 ${code} 时填写 code。", + }, + { + key: "aliyun_sms_endpoint", + label: "阿里云短信 Endpoint", + type: "text", + defaultValue: "dysmsapi.aliyuncs.com", + placeholder: "dysmsapi.aliyuncs.com", + description: "一般保持默认值即可。", + }, + { + key: "default_user_name_prefix", + label: "默认用户名前缀", + type: "text", + defaultValue: "用户", + placeholder: "例如 用户", + description: "系统需要生成默认名称时使用的前缀。", + }, + ], + }, + { + title: "AI 问答", + description: "控制 Agent 调用、上下文和用户端回答展示策略。", + settings: [ + { + key: "ai_timeout_seconds", + label: "AI 请求超时(秒)", + type: "number", + defaultValue: 60, + min: 5, + max: 300, + description: "真实模型请求超过该时间应判定为超时。", + }, + { + key: "mock_model_enabled", + label: "使用 mock 大模型", + type: "switch", + defaultValue: true, + description: "开发和演示环境可开启,真实模型验收前应关闭。", + }, + { + key: "chat_context_message_count", + label: "上下文消息数", + type: "number", + defaultValue: 10, + min: 0, + max: 100, + description: "组装 Prompt 时带入的历史消息数量。", + }, + { + key: "show_reference_sources", + label: "用户端展示引用来源", + type: "switch", + defaultValue: true, + description: "后台始终记录引用;此项控制用户端是否展示。", + }, + { + key: "chat_max_active_requests", + label: "问答最大并发数", + type: "number", + defaultValue: 2, + min: 1, + max: 1000, + description: "同一后端进程内同时进入飞书和模型生成链路的最大请求数。", + }, + { + key: "chat_max_queue_size", + label: "问答最大排队数", + type: "number", + defaultValue: 20, + min: 0, + max: 10000, + description: "超过最大并发后允许等待的请求数量,超过后直接提示稍后再试。", + }, + { + key: "chat_queue_timeout_seconds", + label: "问答排队超时(秒)", + type: "number", + defaultValue: 60, + min: 1, + max: 3600, + description: "请求在排队中超过该时间后自动结束并提示用户稍后再试。", + }, + { + key: "chat_active_lease_seconds", + label: "问答执行租约(秒)", + type: "number", + defaultValue: 900, + min: 60, + max: 86400, + description: "Redis 全局队列中执行名额的自动过期时间,防止 worker 异常退出后长期占用并发名额。", + }, + ], + }, + { + title: "外部服务", + description: "控制飞书搜索接口、飞书直读超时和重试策略。", + settings: [ + { + key: "feishu_search_url", + label: "飞书检索服务地址", + type: "text", + defaultValue: "", + placeholder: "例如 https://example.com/search", + description: "如使用独立飞书检索适配服务,在这里填写调用地址。", + }, + { + key: "feishu_app_id", + label: "飞书应用 AppID", + type: "text", + defaultValue: "", + placeholder: "填写飞书开放平台应用 AppID", + description: "用于后端直读飞书知识库;系统设置优先于环境变量。", + }, + { + key: "feishu_app_secret", + label: "飞书应用 AppSecret", + type: "password", + defaultValue: "", + placeholder: "填写飞书开放平台应用 AppSecret", + description: "用于后端获取飞书 tenant_access_token,保存后立即生效。", + }, + { + key: "feishu_timeout_seconds", + label: "飞书请求超时(秒)", + type: "number", + defaultValue: 20, + min: 1, + max: 120, + description: "飞书相关接口调用超过该时间应判定为超时。", + }, + { + key: "feishu_retry_count", + label: "飞书检索重试次数", + type: "number", + defaultValue: 2, + min: 0, + max: 10, + description: "飞书检索失败时的最大重试次数。", + }, + ], + }, + { + title: "系统开关", + description: "控制系统级展示和运行策略,不包含密钥类配置。", + settings: [ + { + key: "show_operation_log_detail", + label: "展示操作日志详情", + type: "switch", + defaultValue: true, + description: "开启后后台审计页可展示更完整的操作上下文。", + }, + { + key: "chat_export_enabled", + label: "允许导出聊天记录", + type: "switch", + defaultValue: true, + description: "关闭后后台不应提供聊天记录导出能力。", + }, + { + key: "maintenance_mode", + label: "维护模式", + type: "switch", + defaultValue: false, + description: "预留给后续停机维护提示和访问控制使用。", + }, + ], + }, +]; + +export const systemSettingDefinitions = systemSettingSections.flatMap((section) => section.settings);