diff --git a/rsbuild.config.ts b/rsbuild.config.ts index 183a900..ccb0ae8 100644 --- a/rsbuild.config.ts +++ b/rsbuild.config.ts @@ -76,64 +76,64 @@ export default defineConfig(({ envMode }) => { performance: { chunkSplit: { strategy: "split-by-module", - // override: { - // cacheGroups: { - // // ===== 核心框架层 (100+) ===== - // // Vue 生态 - 框架基础,最高优先级 - // vue: { - // test: /[\\/]node_modules[\\/](vue|vue-router|pinia|@vue|@vueuse)[\\/]/, - // name: "vendor-vue", - // priority: 100, - // }, - // // ===== UI 层 (90+) ===== - // // Naive UI 及其依赖 - 核心 UI 框架 - // ui: { - // test: /[\\/]node_modules[\\/](naive-ui|@css-render|css-render|seemly|vooks|vueuc|treemate|vdirs|evtd)[\\/]/, - // name: "vendor-ui", - // priority: 90, - // }, - // // ===== 编辑器层 (70-80) ===== - // // CodeMirror - 代码编辑器(使用最频繁) - // editor: { - // test: /[\\/]node_modules[\\/](codemirror|@codemirror|vue-codemirror|y-codemirror\.next)[\\/]/, - // name: "vendor-editor", - // priority: 80, - // }, - // // Markdown 编辑器 - // mdeditor: { - // test: /[\\/]node_modules[\\/]md-editor-v3[\\/]/, - // name: "vendor-mdeditor", - // priority: 75, - // }, - // // WangEditor - 富文本编辑器 - // wangeditor: { - // test: /[\\/]node_modules[\\/]@wangeditor-next[\\/]/, - // name: "vendor-wangeditor", - // priority: 70, - // }, - // // ===== 功能库层 (50-60) ===== - // // Chart.js - 图表库(按需加载) - // charts: { - // test: /[\\/]node_modules[\\/](chart\.js|vue-chartjs|@kurkle|canvas-confetti)[\\/]/, - // name: "vendor-charts", - // priority: 60, - // }, - // // Mermaid - 流程图库(按需加载) - // mermaid: { - // test: /[\\/]node_modules[\\/]mermaid[\\/]/, - // name: "vendor-mermaid", - // priority: 55, - // }, - // // ===== 通用层 (10) ===== - // // 其他常用库 - 兜底分组 - // common: { - // test: /[\\/]node_modules[\\/]/, - // name: "vendor-common", - // priority: 10, - // minChunks: 2, - // }, - // }, - // }, + override: { + cacheGroups: { + // ===== 核心框架层 (100+) ===== + // Vue 生态 - 框架基础,最高优先级 + vue: { + test: /[\\/]node_modules[\\/](vue|vue-router|pinia|@vue|@vueuse)[\\/]/, + name: "vendor-vue", + priority: 100, + }, + // ===== UI 层 (90+) ===== + // Naive UI 及其依赖 - 核心 UI 框架 + ui: { + test: /[\\/]node_modules[\\/](naive-ui|@css-render|css-render|seemly|vooks|vueuc|treemate|vdirs|evtd)[\\/]/, + name: "vendor-ui", + priority: 90, + }, + // ===== 编辑器层 (70-80) ===== + // CodeMirror - 代码编辑器(使用最频繁) + editor: { + test: /[\\/]node_modules[\\/](codemirror|@codemirror|vue-codemirror|y-codemirror\.next)[\\/]/, + name: "vendor-editor", + priority: 80, + }, + // Markdown 编辑器 + mdeditor: { + test: /[\\/]node_modules[\\/]md-editor-v3[\\/]/, + name: "vendor-mdeditor", + priority: 75, + }, + // WangEditor - 富文本编辑器 + wangeditor: { + test: /[\\/]node_modules[\\/]@wangeditor-next[\\/]/, + name: "vendor-wangeditor", + priority: 70, + }, + // ===== 功能库层 (50-60) ===== + // Chart.js - 图表库(按需加载) + charts: { + test: /[\\/]node_modules[\\/](chart\.js|vue-chartjs|@kurkle|canvas-confetti)[\\/]/, + name: "vendor-charts", + priority: 60, + }, + // Mermaid - 流程图库(按需加载) + mermaid: { + test: /[\\/]node_modules[\\/]mermaid[\\/]/, + name: "vendor-mermaid", + priority: 55, + }, + // ===== 通用层 (10) ===== + // 其他常用库 - 兜底分组 + common: { + test: /[\\/]node_modules[\\/]/, + name: "vendor-common", + priority: 10, + minChunks: 2, + }, + }, + }, }, removeConsole: ["log"], }, diff --git a/src/admin/setting/config.vue b/src/admin/setting/config.vue index 5761362..d07d57e 100644 --- a/src/admin/setting/config.vue +++ b/src/admin/setting/config.vue @@ -20,8 +20,21 @@ interface Testcase { const message = useMessage() const configStore = useConfigStore() +const userStore = useUserStore() const { updateConfig } = useConfigWebSocket() +// 确保只有登录用户才能使用WebSocket +watch( + () => userStore.isAuthed, + (isAuthed) => { + if (!isAuthed) { + // 如果用户未登录,禁用WebSocket功能 + console.warn('用户未登录,WebSocket配置更新功能已禁用') + } + }, + { immediate: true } +) + const testcaseColumns: DataTableColumn[] = [ { title: "测试用例 ID", key: "id" }, { diff --git a/src/shared/composables/configUpdate.ts b/src/shared/composables/configUpdate.ts index 6799158..30ed564 100644 --- a/src/shared/composables/configUpdate.ts +++ b/src/shared/composables/configUpdate.ts @@ -1,4 +1,5 @@ import { useConfigStore } from "shared/store/config" +import { useUserStore } from "shared/store/user" import { useConfigWebSocket, type ConfigUpdate, @@ -6,6 +7,7 @@ import { export function useConfigUpdate() { const configStore = useConfigStore() + const userStore = useUserStore() // 处理 WebSocket 配置更新 const handleConfigUpdate = (data: ConfigUpdate) => { @@ -17,12 +19,23 @@ export function useConfigUpdate() { } // 初始化 WebSocket - handler 会在 onMounted 时自动添加 - const { connect } = useConfigWebSocket(handleConfigUpdate) + const { connect, disconnect } = useConfigWebSocket(handleConfigUpdate) + + // 监听登录状态变化 + watch( + () => userStore.isAuthed, + (isAuthed) => { + if (isAuthed) { + connect() + } else { + disconnect() + } + }, + { immediate: true } + ) - onMounted(() => { - connect() - }) return { connect, + disconnect, } } diff --git a/src/shared/composables/maxkb.ts b/src/shared/composables/maxkb.ts index e80ff50..f506b40 100644 --- a/src/shared/composables/maxkb.ts +++ b/src/shared/composables/maxkb.ts @@ -1,4 +1,5 @@ import { useConfigStore } from "shared/store/config" +import { useUserStore } from "shared/store/user" import { useConfigWebSocket, type ConfigUpdate, @@ -6,6 +7,7 @@ import { export function useMaxKB() { const configStore = useConfigStore() + const userStore = useUserStore() const isLoaded = ref(false) // 处理 WebSocket 配置更新 - 只处理 MaxKB 相关 @@ -20,7 +22,20 @@ export function useMaxKB() { } // 初始化 WebSocket - const { connect } = useConfigWebSocket(handleConfigUpdate) + const { connect, disconnect } = useConfigWebSocket(handleConfigUpdate) + + // 监听登录状态变化 + watch( + () => userStore.isAuthed, + (isAuthed) => { + if (isAuthed) { + connect() + } else { + disconnect() + } + }, + { immediate: true } + ) const loadMaxKBScript = () => { const { enable_maxkb } = configStore.config