2026-07-11 21:50:34 +08:00
< script setup lang = "ts" >
import { computed , ref , watch } from "vue"
import type { CurrentSettings , ExportSettingsResult , ImportSettingsResult , SettingsSchema , SettingsSnapshot , ValidateSettingsResult } from "../../../../shared/types/settings"
import { getJson , postJson } from "../../../../shared/api/client"
import { endpoints } from "../../../../shared/api/endpoints"
import type { CapabilityProfile } from "../../../../shared/types/discovery"
2026-07-11 22:27:35 +08:00
import BackupPage from "./BackupPage.vue"
import StorageMaintenance from "./StorageMaintenance.vue"
import ReviewPolicyPanel from "./ReviewPolicyPanel.vue"
import CapabilityProfilesPanel from "./CapabilityProfilesPanel.vue"
import SystemManagementPanel from "./SystemManagementPanel.vue"
2026-07-11 21:50:34 +08:00
type ConfigValue = string | number | boolean | string [ ] | null
type Adapter = { id : string ; name : string ; provider _type : string ; base _url : string ; image _endpoint : string ; model _id : string ; route _name : string ; api _key _env _var : string ; timeout _seconds : number ; enabled : boolean }
const props = defineProps < { schema : SettingsSchema | null ; current : CurrentSettings | null ; snapshots : readonly SettingsSnapshot [ ] ; validation : ValidateSettingsResult | null ; loading : boolean ; busy : boolean ; error : string ; message : string ; backendConnected : boolean ; canManage : boolean ; pluginVersion : string ; modelCount : number } > ( )
const emit = defineEmits < { refresh : [ ] ; validate : [ config : Record < string , unknown > ] ; save : [ config : Record < string , unknown > ] ; reload : [ ] } > ( )
const previewSchema : SettingsSchema = { schema _version : "3.0-preview" , sections : [
{ key : "generation" , title : "生成服务" , fields : [ ] } ,
{ key : "features" , title : "功能开关" , fields : [
{ key : "quick_profile" , label : "快速角色" , type : "bool" , options : [ ] , sensitive : false , readonly : false } , { key : "workspace" , label : "角色工作流" , type : "bool" , options : [ ] , sensitive : false , readonly : false } , { key : "material_library" , label : "素材库" , type : "bool" , options : [ ] , sensitive : false , readonly : false } , { key : "wardrobe" , label : "角色衣橱" , type : "bool" , options : [ ] , sensitive : false , readonly : false } , { key : "api_discovery" , label : "能力探测" , type : "bool" , options : [ ] , sensitive : false , readonly : false } , { key : "private_companion_integration" , label : "私伴插件集成" , type : "bool" , options : [ ] , sensitive : false , readonly : false } ,
] } ,
{ key : "storage" , title : "存储" , fields : [
{ key : "images_path" , label : "生成图片目录" , type : "path" , options : [ ] , sensitive : false , readonly : false } , { key : "thumbnails_path" , label : "缩略图目录" , type : "path" , options : [ ] , sensitive : false , readonly : false } , { key : "materials_path" , label : "素材目录" , type : "path" , options : [ ] , sensitive : false , readonly : false } , { key : "styles_path" , label : "风格目录" , type : "path" , options : [ ] , sensitive : false , readonly : false } , { key : "archives_path" , label : "归档目录" , type : "path" , options : [ ] , sensitive : false , readonly : false } , { key : "temp_path" , label : "临时文件目录" , type : "path" , options : [ ] , sensitive : false , readonly : false } ,
] } ,
{ key : "database" , title : "数据库" , fields : [
{ key : "backend" , label : "数据库后端" , type : "select" , options : [ "auto" , "sqlite" , "postgresql" ] , sensitive : false , readonly : false } , { key : "sqlite.path" , label : "SQLite 文件路径" , type : "path" , options : [ ] , sensitive : false , readonly : false } , { key : "postgresql.enabled" , label : "启用 PostgreSQL" , type : "bool" , options : [ ] , sensitive : false , readonly : false } , { key : "postgresql.host" , label : "PostgreSQL 主机" , type : "string" , options : [ ] , sensitive : false , readonly : false } , { key : "postgresql.port" , label : "PostgreSQL 端口" , type : "number" , options : [ ] , sensitive : false , readonly : false } , { key : "postgresql.database" , label : "数据库名称" , type : "string" , options : [ ] , sensitive : false , readonly : false } , { key : "postgresql.user" , label : "数据库用户" , type : "string" , options : [ ] , sensitive : true , readonly : false } , { key : "postgresql.password" , label : "数据库密码" , type : "string" , options : [ ] , sensitive : true , readonly : false } ,
] } ,
{ key : "backup" , title : "数据备份" , fields : [ ] } ,
] }
const previewConfig = computed < Record < string , unknown > > ( ( ) => ( { generation : { default _model : "image_default" , provider : { provider _id : "openai-compatible" , base _url : "" , image _endpoint : "/v1/images/generations" , model _id : "" , route _name : "image_default" , api _key _env _var : "IMAGE_API_KEY" , timeout _seconds : 180 } } , features : { quick _profile : true , workspace : true , material _library : true , wardrobe : true , api _discovery : true , private _companion _integration : false } , storage : { images _path : "data/images" , thumbnails _path : "data/thumbnails" , materials _path : "data/materials" , styles _path : "data/styles" , archives _path : "data/archives" , temp _path : "data/temp" } , database : { backend : "auto" , sqlite : { path : "data/imagestudio.db" } , postgresql : { enabled : false , host : "127.0.0.1" , port : 5432 , database : "imagestudio" , user : "" , password : "" } } } ) )
2026-07-11 22:27:35 +08:00
const effectiveSchema = computed ( ( ) => { const schema = clone ( props . schema ? ? previewSchema ) ; for ( const section of [ { key : "review" , title : "审查策略" , fields : [ ] } , { key : "capabilities" , title : "能力档案" , fields : [ ] } , { key : "integration" , title : "私伴集成" , fields : [ ] } , { key : "cost_guard" , title : "成本保护" , fields : [ ] } , { key : "diagnostics" , title : "系统诊断" , fields : [ ] } , { key : "backup" , title : "数据备份" , fields : [ ] } ] ) if ( ! schema . sections . some ( item => item . key === section . key ) ) schema . sections . push ( section ) ; return schema } )
2026-07-11 21:50:34 +08:00
const baseline = computed ( ( ) => props . current ? . config ? ? previewConfig . value )
const draft = ref < Record < string , unknown > > ( { } )
const activeSectionKey = ref ( "generation" )
const expandedAdapter = ref ( "" )
const probingAdapter = ref ( "" )
const probeError = ref ( "" )
const probeResults = ref < Record < string , CapabilityProfile > > ( { } )
const backupBusy = ref ( false )
const backupMessage = ref ( "" )
const backupError = ref ( "" )
const importPreview = ref < Record < string , unknown > | null > ( null )
const importFileName = ref ( "" )
const activeSection = computed ( ( ) => effectiveSchema . value . sections . find ( s => s . key === activeSectionKey . value ) ? ? effectiveSchema . value . sections [ 0 ] ? ? null )
const dirty = computed ( ( ) => JSON . stringify ( draft . value ) !== JSON . stringify ( baseline . value ) )
const adapters = computed < Adapter [ ] > ( ( ) => {
const generation = obj ( draft . value . generation ) ; const saved = Array . isArray ( generation . adapters ) ? generation . adapters . map ( normalizeAdapter ) : [ ]
if ( saved . length ) return saved
const provider = obj ( generation . provider )
return [ normalizeAdapter ( { ... provider , id : String ( provider . provider _id || "primary" ) , name : String ( provider . display _name || provider . provider _id || "主生成服务" ) } ) ]
} )
watch ( baseline , v => { draft . value = clone ( v ) ; expandedAdapter . value = "" } , { immediate : true , deep : true } )
watch ( effectiveSchema , s => { if ( ! s . sections . some ( x => x . key === activeSectionKey . value ) ) activeSectionKey . value = s . sections [ 0 ] ? . key || "" } , { immediate : true } )
function clone < T > ( v : T ) : T { return JSON . parse ( JSON . stringify ( v ) ) as T }
function obj ( v : unknown ) : Record < string , unknown > { return v && typeof v === "object" && ! Array . isArray ( v ) ? v as Record < string , unknown > : { } }
function normalizeAdapter ( v : unknown ) : Adapter { const x = obj ( v ) ; return { id : String ( x . id || x . provider _id || ` adapter- ${ Date . now ( ) } ` ) , name : String ( x . name || x . display _name || x . provider _id || "未命名适配器" ) , provider _type : String ( x . provider _type || "openai_compatible" ) , base _url : String ( x . base _url || "" ) , image _endpoint : String ( x . image _endpoint || "/v1/images/generations" ) , model _id : String ( x . model _id || "" ) , route _name : String ( x . route _name || "" ) , api _key _env _var : String ( x . api _key _env _var || "" ) , timeout _seconds : Number ( x . timeout _seconds || 180 ) , enabled : x . enabled !== false } }
function persistAdapters ( list : Adapter [ ] ) { const next = clone ( draft . value ) ; const generation = obj ( next . generation ) ; generation . adapters = list . map ( clone ) ; generation . provider = { ... list [ 0 ] , provider _id : list [ 0 ] ? . id , display _name : list [ 0 ] ? . name } ; generation . default _model = list [ 0 ] ? . route _name || list [ 0 ] ? . model _id || "" ; next . generation = generation ; draft . value = next }
function updateAdapter ( id : string , key : keyof Adapter , value : string | number | boolean ) { persistAdapters ( adapters . value . map ( a => a . id === id ? { ... a , [ key ] : value } : a ) ) }
function addAdapter ( ) { const id = ` adapter- ${ Date . now ( ) } ` ; persistAdapters ( [ ... adapters . value , { id , name : "新生成服务" , provider _type : "openai_compatible" , base _url : "" , image _endpoint : "/v1/images/generations" , model _id : "" , route _name : ` image_ ${ adapters . value . length + 1 } ` , api _key _env _var : "" , timeout _seconds : 180 , enabled : true } ] ) ; expandedAdapter . value = id }
function removeAdapter ( id : string ) { if ( adapters . value . length <= 1 ) return ; persistAdapters ( adapters . value . filter ( a => a . id !== id ) ) ; expandedAdapter . value = adapters . value [ 0 ] ? . id || "" }
async function probeAdapter ( a : Adapter , lightweight = false ) { probingAdapter . value = a . id ; probeError . value = "" ; try { const result = await postJson < CapabilityProfile > ( endpoints . apiDiscoveryProbeProvider , { provider _id : a . id , model _id : a . model _id || "auto-discovery" , dialect : "openai_images" , live _probe : true , allow _lightweight _test : lightweight , base _url : a . base _url , image _endpoint : a . image _endpoint , api _key _env _var : a . api _key _env _var , timeout _seconds : Math . min ( a . timeout _seconds , 60 ) } ) ; probeResults . value = { ... probeResults . value , [ a . id ] : result } ; const detectedEndpoint = result . probe _result . image _endpoint ; if ( typeof detectedEndpoint === "string" && detectedEndpoint ) updateAdapter ( a . id , "image_endpoint" , detectedEndpoint ) ; const models = probeModelsFromResult ( result ) ; if ( ! a . model _id && models . length ) updateAdapter ( a . id , "model_id" , models [ 0 ] ) } catch ( e ) { probeError . value = e instanceof Error ? e . message : String ( e ) } finally { probingAdapter . value = "" } }
function probeModelsFromResult ( result : CapabilityProfile ) : string [ ] { const value = result . probe _result . models ; return Array . isArray ( value ) ? value . map ( String ) : [ ] }
function probeConnected ( id : string ) { return probeResults . value [ id ] ? . probe _result . connected === true }
function probeModels ( id : string ) : string [ ] { const value = probeResults . value [ id ] ? . probe _result . models ; return Array . isArray ( value ) ? value . map ( String ) : [ ] }
function probeMaxSize ( id : string ) { const value = probeResults . value [ id ] ? . capabilities . max _tested _size ; return typeof value === "string" ? value : "未测试" }
function probeSizeLabel ( id : string ) { const size = probeMaxSize ( id ) ; return size === "1920x1080" ? "1K · 1920× 1080" : size === "2560x1440" ? "2K · 2560× 1440" : size === "3840x2160" ? "4K · 3840× 2160" : size }
function sectionDescription ( key : string ) { return key === "features" ? "控制角色、素材和集成功能是否在工作台中启用。" : key === "storage" ? "规划图片、素材、缩略图、归档和临时文件的保存位置。" : key === "database" ? "选择本地 SQLite 或 PostgreSQL,并管理数据库连接参数。" : key === "backup" ? "导出脱敏配置备份,或从本地备份文件恢复设置。" : "管理当前分区的运行配置。" }
function featureDescription ( key : string ) { return ( { quick _profile : "从文本快速建立角色档案" , workspace : "启用详细角色工作流与节点生成" , material _library : "管理生成所需的参考素材" , wardrobe : "为角色维护分类衣橱" , api _discovery : "检测生成服务模型与分辨率能力" , private _companion _integration : "与 AstrBot 私伴插件共享角色能力" } as Record < string , string > ) [ key ] || "控制此功能模块是否可用" }
async function exportBackup ( ) { backupBusy . value = true ; backupError . value = "" ; backupMessage . value = "" ; try { const data = await getJson < ExportSettingsResult > ( endpoints . settingsExport ) ; const blob = new Blob ( [ JSON . stringify ( { format : "imagestudio-settings-backup" , version : 1 , exported _at : new Date ( ) . toISOString ( ) , ... data } , null , 2 ) ] , { type : "application/json" } ) ; const url = URL . createObjectURL ( blob ) ; const link = document . createElement ( "a" ) ; link . href = url ; link . download = ` imagestudio-backup- ${ new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) } .json ` ; link . click ( ) ; URL . revokeObjectURL ( url ) ; backupMessage . value = "脱敏配置备份已导出。" } catch ( e ) { backupError . value = e instanceof Error ? e . message : String ( e ) } finally { backupBusy . value = false } }
async function selectImportFile ( event : Event ) { backupError . value = "" ; backupMessage . value = "" ; const file = ( event . target as HTMLInputElement ) . files ? . [ 0 ] ; if ( ! file ) return ; try { const parsed = JSON . parse ( await file . text ( ) ) as Record < string , unknown > ; const config = obj ( parsed . config ? ? parsed ) ; if ( ! Object . keys ( config ) . length ) throw new Error ( "备份文件中没有有效配置" ) ; importPreview . value = config ; importFileName . value = file . name ; backupMessage . value = "文件读取成功,请确认后执行导入。" } catch ( e ) { importPreview . value = null ; importFileName . value = "" ; backupError . value = e instanceof Error ? e . message : "无法读取备份文件" } }
async function importBackup ( ) { if ( ! importPreview . value ) return ; backupBusy . value = true ; backupError . value = "" ; try { await postJson < ImportSettingsResult > ( endpoints . settingsImport , { config : importPreview . value } ) ; backupMessage . value = "备份已导入并生成配置快照。" ; importPreview . value = null ; importFileName . value = "" ; emit ( "refresh" ) } catch ( e ) { backupError . value = e instanceof Error ? e . message : String ( e ) } finally { backupBusy . value = false } }
function resetDraft ( ) { draft . value = clone ( baseline . value ) }
function fieldPath ( k : string ) { return activeSection . value ? ` ${ activeSection . value . key } . ${ k } ` : k }
function fieldValue ( path : string ) : ConfigValue { let c : unknown = draft . value ; for ( const p of path . split ( "." ) ) { if ( ! c || typeof c !== "object" || Array . isArray ( c ) ) return "" ; c = ( c as Record < string , unknown > ) [ p ] } return Array . isArray ( c ) ? c as string [ ] : typeof c === "string" || typeof c === "number" || typeof c === "boolean" || c === null ? c : "" }
function updateField ( path : string , value : ConfigValue ) { const next = clone ( draft . value ) ; const parts = path . split ( "." ) ; let c = next ; for ( const p of parts . slice ( 0 , - 1 ) ) { if ( ! c [ p ] || typeof c [ p ] !== "object" || Array . isArray ( c [ p ] ) ) c [ p ] = { } ; c = c [ p ] as Record < string , unknown > } c [ parts . at ( - 1 ) ! ] = value ; draft . value = next }
function inputValue ( e : Event , type : string ) : ConfigValue { const t = e . target as HTMLInputElement | HTMLSelectElement ; if ( type === "bool" || type === "boolean" ) return t . value === "true" ; if ( type === "number" ) return t . value === "" ? null : Number ( t . value ) ; return t . value }
< / script >
< template > < section class = "settings-page" >
< header class = "hero" > < div > < span > 系统设置 < / span > < h2 > 插件与生成服务 < / h2 > < p > 集中管理 ImageStudio 的生成适配器 、 运行参数与功能配置 。 < / p > < / div > < div class = "actions" > < button @click ="emit('refresh')" > 刷新配置 < / button > < button :disabled = "busy||!backendConnected||!canManage" @click ="emit('reload')" > 重载配置 < / button > < / div > < / header >
< section v-if = "error||message" :class="['notice',{error:!!error}]" > {{ error | | message }} < / section >
2026-07-11 22:27:35 +08:00
< section class = "workspace" > < aside class = "nav" > < header > < span > 设置导航 < / span > < strong > { { effectiveSchema . sections . length } } < / strong > < / header > < button v-for = "s in effectiveSchema.sections" :key="s.key" :class="{active:activeSection?.key===s.key}" @click="activeSectionKey=s.key" > < span > { { s . title } } < / span > < small > { { s . key === 'generation' ? ` ${ adapters . length } 个适配器 ` : s . key === 'backup' ? '导入 / 导出' : s . key === 'review' ? '规则管理' : s . key === 'capabilities' ? '模型档案' : s . key === 'integration' ? '凭据管理' : s . key === 'cost_guard' ? '预算预检' : s . key === 'diagnostics' ? '运行检查' : ` ${ s . fields . length } 项 ` } } < / small > < / button > < / aside >
2026-07-11 21:50:34 +08:00
< main class = "editor" >
< template v-if = "activeSection?.key==='generation'"><header class="section-head" > < div > < span > 生成服务 < / span > < h3 > API 适配器 < / h3 > < p > 每个服务独立配置 , 展开卡片后填写 API 信息 。 首张卡片作为当前默认生成路由 。 < / p > < / div > < / header >
< div class = "adapter-list" > < article v-for = "(a,index) in adapters" :key="a.id" class="adapter-card" :class="{connected:a.enabled&&!!a.base_url,disabled:!a.enabled}"><button class="adapter-summary" @click="expandedAdapter=a.id"><span class="adapter-icon">{{a.name.slice(0,1).toUpperCase()}}</span><span class="adapter-title"><strong>{{a.name}}</strong><small>{{a.enabled?(a.base_url?'链接已配置':'等待配置'):'已停用'}}</small></span><em v-if="index===0">默认</em><span class="corner" aria-hidden="true" > < / span > < / button > < / article > < / div >
< div v-if = "expandedAdapter" class="adapter-overlay" @click.self="expandedAdapter=''" >
< article v-for = "a in adapters.filter(item=>item.id===expandedAdapter)" :key="a.id" class="adapter-dialog" role="dialog" aria-modal="true" :aria-label="`${a.name} 配置`" >
< header > < div > < span > 生成服务适配器 < / span > < h3 > { { a . name } } < / h3 > < p > 填写连接信息与模型路由参数 。 < / p > < / div > < button class = "close" aria -label = " 关闭配置 " @click ="expandedAdapter=''" > × < / button > < / header >
< div class = "adapter-body" > < div class = "fields" > < label > < span > 适配器名称 < / span > < input :value = "a.name" @ input = "updateAdapter(a.id,'name',($event.target as HTMLInputElement).value)" > < / label > < label > < span > 适配器类型 < / span > < select :value = "a.provider_type" @ change = "updateAdapter(a.id,'provider_type',($event.target as HTMLSelectElement).value)" > < option value = "openai_compatible" > OpenAI Compatible < / option > < option value = "custom" > 自定义 HTTP < / option > < / select > < / label > < label class = "wide" > < span > API 根地址 < / span > < input placeholder = "https://api.example.com 或 https://api.example.com/v1" :value = "a.base_url" @ input = "updateAdapter(a.id,'base_url',($event.target as HTMLInputElement).value)" > < small > 可直接填写到 / v1 , 探测时会自动识别 API 层级 。 < / small > < / label > < label > < span > 生图 Endpoint < / span > < input :value = "a.image_endpoint" @ input = "updateAdapter(a.id,'image_endpoint',($event.target as HTMLInputElement).value)" > < small > 连接测试成功后自动回填 。 < / small > < / label > < label > < span > 模型 ID < / span > < input :list = "`models-${a.id}`" placeholder = "测试后选择或手动输入" :value = "a.model_id" @ input = "updateAdapter(a.id,'model_id',($event.target as HTMLInputElement).value)" > < datalist :id = "`models-${a.id}`" > < option v-for ="model in probeModels(a.id)" :key="model" :value ="model" > < / option > < / datalist > < small > { { probeModels ( a . id ) . length ? ` 已发现 ${ probeModels ( a . id ) . length } 个模型,可展开选择。 ` : '测试连接后自动获取模型。' } } < / small > < / label > < label > < span > 路由名称 < / span > < input :value = "a.route_name" @ input = "updateAdapter(a.id,'route_name',($event.target as HTMLInputElement).value)" > < / label > < label > < span > API Key 环境变量 < / span > < input placeholder = "IMAGE_API_KEY" :value = "a.api_key_env_var" @ input = "updateAdapter(a.id,'api_key_env_var',($event.target as HTMLInputElement).value)" > < small > 密钥不直接写入配置文件 , 填写保存密钥的环境变量名 。 < / small > < / label > < label > < span > 超时 ( 秒 ) < / span > < input type = "number" min = "1" :value = "a.timeout_seconds" @ input = "updateAdapter(a.id,'timeout_seconds',Number(($event.target as HTMLInputElement).value))" > < / label > < / div >
< section class = "probe-panel" > < header > < div > < span > 能力探测 < / span > < strong > 连接 、 模型与分辨率 < / strong > < / div > < div class = "actions" > < button :disabled = "!a.base_url||probingAdapter===a.id" @click ="probeAdapter(a,false)" > {{ probingAdapter = = = a.id ? ' 探测中 … ' : ' 测试连接与模型 ' }} < / button > < button class = "probe-live" :disabled = "!a.base_url||!a.model_id||probingAdapter===a.id" @click ="probeAdapter(a,true)" > 1K / 2K / 4K 测试 < / button > < / div > < / header > < p > 轻量测试会依次申请 1920 × 1080 、 2560 × 1440 、 3840 × 2160 横图 , 用于判断已验证的最大分辨率 , 可能产生少量 API 费用 。 < / p > < div v-if = "probeError" class="probe-error">{{probeError}}</div><div v-if="probeResults[a.id]" class="probe-result"><span :class="{ok:probeConnected(a.id)}">{{probeConnected(a.id)?'连接成功':'连接失败'}}</span><span>发现模型 {{probeModels(a.id).length}} 个</span><span>最大已验证 {{probeSizeLabel(a.id)}}</span><small v-if="probeModels(a.id).length" > {{ probeModels ( a.id ) .slice ( 0 , 8 ) .join ( ' 、 ' ) }} < / small > < / div > < / section >
< footer > < label class = "switch" > < input type = "checkbox" :checked = "a.enabled" @ change = "updateAdapter(a.id,'enabled',($event.target as HTMLInputElement).checked)" > < span > 启用此适配器 < / span > < / label > < div class = "actions" > < button class = "danger" :disabled = "adapters.length<=1" @click ="removeAdapter(a.id)" > 删除适配器 < / button > < button class = "primary" @click ="expandedAdapter=''" > 完成 < / button > < / div > < / footer > < / div >
< / article >
< / div >
< / template >
< template v-else > < header class = "section-head" > < div > < span > 系统配置 < / span > < h3 > { { activeSection ? . title || '暂无配置' } } < / h3 > < p > { { sectionDescription ( activeSection ? . key || '' ) } } < / p > < / div > < span class = "section-count" > { { activeSection ? . fields . length || 0 } } 项配置 < / span > < / header >
2026-07-11 22:27:35 +08:00
< BackupPage v-if = "activeSection?.key==='backup'" :snapshots="snapshots" :backend-connected="backendConnected" :can-manage="canManage" @refresh="emit('refresh')" / >
< ReviewPolicyPanel v -else -if = " activeSection ? .key = = = ' review ' " :backend-connected = "backendConnected" :can-manage = "canManage" / >
< CapabilityProfilesPanel v -else -if = " activeSection ? .key = = = ' capabilities ' " :backend-connected = "backendConnected" :can-manage = "canManage" / >
< SystemManagementPanel v -else -if = " activeSection ? .key = = = ' integration ' " mode = "integration" :backend-connected = "backendConnected" :can-manage = "canManage" / >
< SystemManagementPanel v -else -if = " activeSection ? .key = = = ' cost_guard ' " mode = "cost" :backend-connected = "backendConnected" :can-manage = "canManage" / >
< SystemManagementPanel v -else -if = " activeSection ? .key = = = ' diagnostics ' " mode = "diagnostics" :backend-connected = "backendConnected" :can-manage = "canManage" / >
2026-07-11 21:50:34 +08:00
< div v -else -if = " activeSection ? .key = = = ' features ' " class = "feature-grid" > < article v-for = "f in activeSection.fields" :key="f.key" class="feature-card" :class="{enabled:fieldValue(fieldPath(f.key))===true}"><div class="feature-mark">{{f.label.slice(0,1)}}</div><div><strong>{{f.label}}</strong><p>{{featureDescription(f.key)}}</p></div><label class="toggle"><input type="checkbox" :checked="fieldValue(fieldPath(f.key))===true" @change="updateField(fieldPath(f.key),($event.target as HTMLInputElement).checked)" > < span > < / span > < / label > < / article > < / div >
2026-07-11 22:27:35 +08:00
< div v -else class = "config-panel" > < div class = "config-banner" > < div class = "config-symbol" > { { activeSection ? . key === 'storage' ? '▣' : 'DB' } } < / div > < div > < strong > { { activeSection ? . key === 'storage' ? '存储目录规划' : '数据库连接' } } < / strong > < p > { { activeSection ? . key === 'storage' ? '支持相对插件数据目录或绝对路径,保存前请确保 AstrBot 进程具备写入权限。' : 'auto 会优先使用已配置的 PostgreSQL,否则回退到本地 SQLite。' } } < / p > < / div > < / div > < div class = "fields" > < label v-for ="f in activeSection?.fields||[]" :key="f.key"><span>{{f.label}}</span><select v-if="f.options.length||f.type==='bool'||f.type==='boolean'" :value="String(fieldValue(fieldPath(f.key)))" @change="updateField(fieldPath(f.key),inputValue($event,f.type))"><option v-if="f.type==='bool'||f.type==='boolean'" value="true">开启</option><option v-if="f.type==='bool'||f.type==='boolean'" value="false">关闭</option><option v-for="o in f.options" :key="o" :value ="o" > {{ o }} < / option > < / select > < input v -else :type = "f.type==='number'?'number':f.sensitive?'password':'text'" :placeholder = "f.type==='path'?'输入目录或文件路径':''" : value = "fieldValue(fieldPath(f.key)) as any" @input ="updateField(fieldPath(f.key),inputValue($event,f.type))" > < small > { { fieldPath ( f . key ) } } < / small > < / label > < / div > < StorageMaintenance v-if = "activeSection?.key==='storage'" :can-manage="canManage" :backend-connected="backendConnected" / > < / div >
2026-07-11 21:50:34 +08:00
< / template >
< footer class = "savebar" > < span > { { dirty ? '有未保存修改' : '配置已同步' } } < / span > < div class = "actions" > < button v-if = "activeSection?.key==='generation'" class="add-adapter-bottom" @click="addAdapter">+ 添加适配器</button><button :disabled="!dirty||busy" @click="resetDraft">撤销</button><button :disabled="busy||!backendConnected" @click="emit('validate',draft)">校验</button><button class="primary" :disabled="busy||!dirty||!backendConnected||!canManage" @click="emit('save',draft)" > {{ busy ? ' 处理中 … ' : ' 保存配置 ' }} < / button > < / div > < / footer >
< / main >
< aside class = "side" > < section > < span > 连接状态 < / span > < strong > { { backendConnected ? '后端已连接' : '预览模式' } } < / strong > < p > { { canManage ? '当前账号可管理配置。' : '当前账号只有只读权限。' } } < / p > < / section > < section > < span > 配置快照 < / span > < strong > { { snapshots . length } } 条 < / strong > < p > 保存前会进行配置校验 , 并由后端保留变更记录 。 < / p > < / section > < / aside >
< / section >
< / section > < / template >
< style scoped >
. settings - page { display : grid ; gap : 14 px ; min - width : 0 } . hero , . nav , . editor , . side section , . notice { border : 1 px solid var ( -- border ) ; border - radius : 10 px ; background : var ( -- panel ) ; box - shadow : var ( -- shadow ) } . hero { display : flex ; justify - content : space - between ; gap : 20 px ; padding : 22 px ; background : linear - gradient ( 115 deg , var ( -- primary - soft ) , transparent 56 % ) , var ( -- panel ) } h2 , h3 , p { margin : 0 } . hero div : first - child { display : grid ; gap : 5 px } . hero span , . section - head span , . side span , . adapter - dialog header span { color : var ( -- text - soft ) ; font - size : 12 px ; font - weight : 800 } . hero p , . section - head p , . side p , . adapter - dialog header p { color : var ( -- text - soft ) } button , input , select { font : inherit } . actions { display : flex ; align - items : center ; gap : 8 px } button { min - height : 36 px ; border : 1 px solid var ( -- border ) ; border - radius : 7 px ; padding : 0 12 px ; color : var ( -- text ) ; background : var ( -- panel - muted ) ; cursor : pointer } button : hover { border - color : var ( -- primary ) } button : disabled { opacity : .5 ; cursor : not - allowed } . primary { border - color : var ( -- primary ) ; color : # fff ; background : var ( -- primary ) } . notice { padding : 12 px } . notice . error { color : var ( -- danger ) ; background : var ( -- danger - soft ) } . workspace { display : grid ; grid - template - columns : 210 px minmax ( 0 , 1 fr ) 250 px ; gap : 14 px ; align - items : start } . nav { display : grid ; gap : 7 px ; padding : 12 px } . nav header , . nav button { display : flex ; align - items : center ; justify - content : space - between } . nav button { text - align : left } . nav button . active { border - color : var ( -- primary ) ; background : var ( -- primary - soft ) } . nav small { color : var ( -- text - soft ) } . editor { display : grid ; gap : 16 px ; min - width : 0 ; padding : 17 px } . section - head { display : flex ; align - items : flex - start ; justify - content : space - between ; gap : 16 px } . section - head > div { display : grid ; gap : 5 px } . adapter - list { display : grid ; grid - template - columns : repeat ( 2 , minmax ( 0 , 1 fr ) ) ; gap : 12 px } . adapter - card { position : relative ; overflow : hidden ; border : 1 px solid var ( -- border ) ; border - radius : 10 px ; background : var ( -- panel - muted ) ; transition : transform .18 s , border - color .18 s , box - shadow .18 s } . adapter - card : hover { transform : translateY ( - 2 px ) ; border - color : var ( -- primary ) ; box - shadow : var ( -- shadow ) } . adapter - card . connected { border - color : color - mix ( in srgb , # 39 aa72 45 % , var ( -- border ) ) } . adapter - card . disabled { opacity : .7 } . adapter - summary { display : grid ; grid - template - columns : 42 px minmax ( 0 , 1 fr ) auto ; align - items : center ; gap : 11 px ; width : 100 % ; min - height : 82 px ; border : 0 ; border - radius : 0 ; padding : 13 px ; text - align : left ; background : transparent } . adapter - icon { display : grid ; place - items : center ; width : 40 px ; height : 40 px ; border - radius : 9 px ; color : # fff ; background : var ( -- primary ) ; font - weight : 900 } . adapter - title { display : grid ; gap : 3 px ; min - width : 0 } . adapter - title small { color : var ( -- text - soft ) ; font - size : 12 px } . adapter - summary em { border - radius : 5 px ; padding : 3 px 7 px ; color : var ( -- primary ) ; background : var ( -- primary - soft ) ; font - size : 11 px ; font - style : normal } . corner { position : absolute ; top : 0 ; right : 0 ; width : 0 ; height : 0 ; border - top : 18 px solid # e1a53a ; border - left : 18 px solid transparent } . connected . corner { border - top - color : # 39 aa72 } . disabled . corner { border - top - color : # 8 a919d } . adapter - overlay { position : fixed ; z - index : 1200 ; inset : 0 ; display : grid ; place - items : center ; padding : 28 px ; background : rgba ( 10 , 14 , 22 , .62 ) ; backdrop - filter : blur ( 5 px ) } . adapter - dialog { width : min ( 760 px , calc ( 100 vw - 36 px ) ) ; max - height : calc ( 100 vh - 56 px ) ; overflow : auto ; border : 1 px solid var ( -- border ) ; border - radius : 14 px ; background : var ( -- panel ) ; box - shadow : 0 24 px 70 px rgba ( 0 , 0 , 0 , .35 ) } . adapter - dialog > header { position : sticky ; z - index : 2 ; top : 0 ; display : flex ; align - items : flex - start ; justify - content : space - between ; gap : 20 px ; border - bottom : 1 px solid var ( -- border ) ; padding : 18 px 20 px ; background : var ( -- panel ) } . adapter - dialog > header > div { display : grid ; gap : 4 px } . close { width : 36 px ; padding : 0 ; font - size : 23 px } . adapter - body { display : grid ; gap : 15 px ; padding : 20 px } . fields { display : grid ; grid - template - columns : repeat ( 2 , minmax ( 0 , 1 fr ) ) ; gap : 14 px } . fields label { display : grid ; gap : 7 px ; min - width : 0 } . fields label . wide { grid - column : 1 / - 1 } . fields label > span { font - size : 13 px ; font - weight : 750 } . fields input , . fields select { width : 100 % ; min - height : 40 px ; box - sizing : border - box ; border : 1 px solid var ( -- border ) ; border - radius : 7 px ; padding : 0 10 px ; color : var ( -- text ) ; background : var ( -- panel - muted ) } . fields small { color : var ( -- text - soft ) ; font - size : 11 px } . adapter - b
. probe - panel { display : grid ; gap : 10 px ; border : 1 px solid var ( -- border ) ; border - radius : 9 px ; padding : 14 px ; background : var ( -- panel - muted ) } . probe - panel header { display : flex ; align - items : center ; justify - content : space - between ; gap : 12 px } . probe - panel header > div : first - child { display : grid ; gap : 3 px } . probe - panel header span { color : var ( -- text - soft ) ; font - size : 11 px ; font - weight : 800 } . probe - panel p { color : var ( -- text - soft ) ; font - size : 12 px ; line - height : 1.5 } . probe - live { border - color : color - mix ( in srgb , # e1a53a 55 % , var ( -- border ) ) } . probe - result { display : flex ; flex - wrap : wrap ; gap : 7 px ; border - top : 1 px solid var ( -- border ) ; padding - top : 10 px } . probe - result > span { border - radius : 5 px ; padding : 4 px 7 px ; color : var ( -- text - soft ) ; background : var ( -- panel ) } . probe - result > span . ok { color : # 26865 a ; background : color - mix ( in srgb , # 39 aa72 14 % , var ( -- panel ) ) } . probe - result small { flex - basis : 100 % ; color : var ( -- text - soft ) ; line - height : 1.5 } . probe - error { border - radius : 6 px ; padding : 8 px ; color : var ( -- danger ) ; background : var ( -- danger - soft ) }
. add - adapter - bottom { border - color : color - mix ( in srgb , var ( -- primary ) 55 % , var ( -- border ) ) ; color : var ( -- primary ) ; background : var ( -- primary - soft ) }
. backup - page { display : grid ; gap : 15 px } . backup - hero { display : flex ; align - items : center ; gap : 13 px ; border : 1 px solid var ( -- border ) ; border - radius : 10 px ; padding : 15 px ; background : linear - gradient ( 105 deg , var ( -- primary - soft ) , var ( -- panel - muted ) ) } . backup - hero > div : last - child { display : grid ; gap : 4 px } . backup - hero p , . backup - grid p { color : var ( -- text - soft ) ; font - size : 12 px ; line - height : 1.5 } . backup - grid { display : grid ; grid - template - columns : repeat ( 2 , minmax ( 0 , 1 fr ) ) ; gap : 13 px } . backup - grid article { display : grid ; align - content : start ; gap : 10 px ; border : 1 px solid var ( -- border ) ; border - radius : 10 px ; padding : 16 px ; background : var ( -- panel - muted ) } . backup - grid article > span { color : var ( -- text - soft ) ; font - size : 11 px ; font - weight : 800 } . backup - grid article > strong { font - size : 17 px } . backup - grid ul { display : grid ; gap : 6 px ; margin : 0 ; padding - left : 18 px ; color : var ( -- text - soft ) ; font - size : 12 px } . file - picker { display : block ! important } . file - picker input { position : absolute ; opacity : 0 ; pointer - events : none } . file - picker span { display : grid ; place - items : center ; min - height : 38 px ; border : 1 px dashed var ( -- primary ) ; border - radius : 7 px ; color : var ( -- primary ) ; background : var ( -- primary - soft ) ; cursor : pointer } . import - preview { display : grid ; gap : 4 px ; border - radius : 7 px ; padding : 9 px ; background : var ( -- panel ) } . import - preview small { overflow : hidden ; color : var ( -- text - soft ) ; text - overflow : ellipsis ; white - space : nowrap } . backup - scope { display : grid ; gap : 9 px ; border : 1 px solid var ( -- border ) ; border - radius : 10 px ; padding : 14 px } . backup - scope > div { display : grid ; grid - template - columns : 1 fr 1 fr ; gap : 12 px } . backup - scope span { color : var ( -- text - soft ) ; font - size : 12 px ; line - height : 1.5 } . backup - scope b { display : block ; color : var ( -- text ) ; margin - bottom : 3 px } . backup - notice { border - radius : 7 px ; padding : 10 px ; color : # 26865 a ; background : color - mix ( in srgb , # 39 aa72 13 % , var ( -- panel ) ) } . backup - notice . error { color : var ( -- danger ) ; background : var ( -- danger - soft ) }
. section - count { border - radius : 6 px ; padding : 6 px 9 px ; color : var ( -- primary ) ! important ; background : var ( -- primary - soft ) } . feature - grid { display : grid ; grid - template - columns : repeat ( 2 , minmax ( 0 , 1 fr ) ) ; gap : 12 px } . feature - card { display : grid ; grid - template - columns : 42 px minmax ( 0 , 1 fr ) auto ; align - items : center ; gap : 12 px ; border : 1 px solid var ( -- border ) ; border - radius : 10 px ; padding : 14 px ; background : var ( -- panel - muted ) } . feature - card . enabled { border - color : color - mix ( in srgb , var ( -- primary ) 45 % , var ( -- border ) ) ; background : color - mix ( in srgb , var ( -- primary - soft ) 42 % , var ( -- panel ) ) } . feature - mark { display : grid ; place - items : center ; width : 40 px ; height : 40 px ; border - radius : 9 px ; color : var ( -- text - soft ) ; background : var ( -- panel ) ; font - weight : 900 } . feature - card . enabled . feature - mark { color : # fff ; background : var ( -- primary ) } . feature - card > div : nth - child ( 2 ) { display : grid ; gap : 4 px } . feature - card p { color : var ( -- text - soft ) ; font - size : 12 px ; line - height : 1.4 } . toggle { display : block ! important } . toggle input { position : absolute ; opacity : 0 ; pointer - events : none } . toggle span { position : relative ; display : block ; width : 42 px ; height : 24 px ; border - radius : 99 px ; background : var ( -- border ) ; cursor : pointer } . toggle span : after { position : absolute ; top : 3 px ; left : 3 px ; width : 18 px ; height : 18 px ; border - radius : 50 % ; background : # fff ; box - shadow : 0 1 px 4 px rgba ( 0 , 0 , 0 , .25 ) ; content : "" ; transition : .18 s } . toggle input : checked + span { background : var ( -- primary ) } . toggle input : checked + span : after { transform : translateX ( 18 px ) } . config - panel { display : grid ; gap : 16 px } . config - banner { display : flex ; align - items : center ; gap : 13 px ; border : 1 px solid var ( -- border ) ; border - radius : 10 px ; padding : 14 px ; background : linear - gradient ( 105 deg , var ( -- primary - soft ) , var ( -- panel - muted ) ) } . config - banner > div : last - child { display : grid ; gap : 4 px } . config - banner p { color : var ( -- text - soft ) ; font - size : 12 px ; line - height : 1.5 } . config - symbol { display : grid ; place - items : center ; flex : 0 0 46 px ; height : 46 px ; border - radius : 10 px ; color : # fff ; background : var ( -- primary ) ; font - weight : 900 }
@ media ( max - width : 1180 px ) { . workspace { grid - template - columns : 190 px minmax ( 0 , 1 fr ) } . side { grid - column : 1 / - 1 ; grid - template - columns : 1 fr 1 fr } } @ media ( max - width : 820 px ) { . workspace { grid - template - columns : 1 fr } . nav { grid - template - columns : 1 fr 1 fr } . nav header { grid - column : 1 / - 1 } . side { grid - column : auto ; grid - template - columns : 1 fr } . hero , . section - head , . savebar { flex - direction : column } . fields , . feature - grid , . backup - grid , . backup - scope > div { grid - template - columns : 1 fr } . fields label . wide { grid - column : auto } } @ media ( max - width : 600 px ) { . adapter - list { grid - template - columns : 1 fr } . nav { grid - template - columns : 1 fr } . nav header { grid - column : auto } . adapter - overlay { padding : 10 px } . adapter - dialog { width : calc ( 100 vw - 20 px ) ; max - height : calc ( 100 vh - 20 px ) } . adapter - dialog > header , . adapter - body { padding : 15 px } . adapter - body footer { align - items : stretch ; flex - direction : column } . actions { align - items : stretch ; flex - direction : column ; width : 100 % } . actions button { width : 100 % } }
< / style >