修复: 设置页和 AI 独立窗口渲染崩溃(循环依赖 TDZ)
- ProviderPanel 改静态 import useAiStore 为动态 import,打破循环依赖链 - ErrorBoundary 增强显示具体错误信息和可折叠堆栈详情
This commit is contained in:
@@ -130,14 +130,22 @@
|
||||
import { reactive, ref, onMounted } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { aiApi } from '@/api'
|
||||
import { useAiStore } from '@/stores/ai'
|
||||
import type { AiProviderConfig, ModelConfig } from '@/api/types'
|
||||
|
||||
// ============================================================
|
||||
// AI 提供商域 — 真实后端 CRUD + F-04c 负载均衡池(enabled / weight)
|
||||
// ============================================================
|
||||
const { t } = useI18n()
|
||||
const aiStore = useAiStore()
|
||||
|
||||
// 懒加载 useAiStore 避免静态 import 形成循环依赖:
|
||||
// ProviderPanel → stores/ai → useAiEvents → aiShared → useAppSettingsStore
|
||||
// 在 Settings chunk 首次加载时,stores/ai 模块顶层代码(__bindMessages)可能触发 TDZ。
|
||||
// 改为运行时动态 import,模块加载顺序不再耦合。
|
||||
async function syncAiStoreProviders() {
|
||||
const { useAiStore } = await import('@/stores/ai')
|
||||
const aiStore = useAiStore()
|
||||
await aiStore.loadProviders()
|
||||
}
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'toast', msg: string, type: 'error' | 'warning' | 'info'): void
|
||||
@@ -170,7 +178,8 @@ async function loadProviders() {
|
||||
try {
|
||||
aiProviders.value = await aiApi.listProviders()
|
||||
// 同步刷新全局 store(AiChat 等 AI 面板消费方共享同一 state,避免改完仍提示「未配置」)
|
||||
await aiStore.loadProviders()
|
||||
// 懒加载避免循环依赖(见文件顶部 syncAiStoreProviders 注释)
|
||||
await syncAiStoreProviders()
|
||||
emit('providers-changed')
|
||||
} catch (e) {
|
||||
console.error(t('settings.toastLoadProviderFail'), e)
|
||||
|
||||
Reference in New Issue
Block a user