Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

feat: Implement theme management and UI enhancements across the application

wizardchen7a64371603d8
diff --git a/frontend/src/App.vue b/frontend/src/App.vue
index e7d4d2bfc..1854102b7 100644
--- a/frontend/src/App.vue
+++ b/frontend/src/App.vue
@@ -1,4 +1,13 @@
<script setup lang="ts">
+import { onMounted } from 'vue'
+import { useUIStore } from '@/stores/ui'
+
+const uiStore = useUIStore()
+
+// 在应用启动时初始化主题
+onMounted(() => {
+ uiStore.initTheme()
+})
</script>
<template>
<div id="app">
@@ -18,6 +27,104 @@ html,
Microsoft YaHei, SimSun, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
- background: #f8f9fa;
+ background: var(--td-bg-color-page);
+}
+
+/* 暗色模式下的TDesign组件样式增强 */
+:root[theme-mode="dark"] {
+ /* 表格表头 */
+ .t-table thead th {
+ color: var(--td-text-color-primary) !important;
+ background-color: var(--td-bg-color-container) !important;
+ font-weight: 600 !important;
+ }
+
+ /* 表格内容 */
+ .t-table tbody td {
+ color: var(--td-text-color-primary) !important;
+ background-color: var(--td-bg-color-container) !important;
+ }
+
+ /* 表格行hover效果 */
+ .t-table tbody tr:hover td {
+ background-color: var(--td-bg-color-container-hover) !important;
+ }
+
+ /* 表格边框 */
+ .t-table,
+ .t-table th,
+ .t-table td {
+ border-color: var(--td-component-border) !important;
+ }
+
+ /* 滑块标记文字 */
+ .t-slider__mark-text {
+ color: var(--td-text-color-primary) !important;
+ font-weight: 500 !important;
+ }
+
+ /* 滑块刻度 */
+ .t-slider__stops .t-slider__stop {
+ background-color: var(--td-text-color-placeholder) !important;
+ }
+
+ /* 对话框 */
+ .t-dialog {
+ background: var(--td-bg-color-container) !important;
+ color: var(--td-text-color-primary) !important;
+ }
+
+ .t-dialog__header {
+ color: var(--td-text-color-primary) !important;
+ border-bottom-color: var(--td-component-border) !important;
+ }
+
+ .t-dialog__body {
+ color: var(--td-text-color-primary) !important;
+ }
+
+ /* 表单标签 */
+ .t-form__label {
+ color: var(--td-text-color-primary) !important;
+ font-weight: 500 !important;
+ }
+
+ /* 输入框 */
+ .t-input,
+ .t-textarea {
+ background-color: var(--td-bg-color-component) !important;
+ color: var(--td-text-color-primary) !important;
+ border-color: var(--td-component-border) !important;
+ }
+
+ .t-input::placeholder,
+ .t-textarea::placeholder {
+ color: var(--td-text-color-placeholder) !important;
+ }
+
+ /* 下拉选择器 */
+ .t-select-input {
+ background-color: var(--td-bg-color-component) !important;
+ color: var(--td-text-color-primary) !important;
+ border-color: var(--td-component-border) !important;
+ }
+
+ .t-select__placeholder {
+ color: var(--td-text-color-placeholder) !important;
+ }
+
+ /* 开关组件 */
+ .t-switch__label {
+ color: var(--td-text-color-primary) !important;
+ }
+
+ /* 标签页 */
+ .t-tabs__nav-item {
+ color: var(--td-text-color-secondary) !important;
+ }
+
+ .t-tabs__nav-item.t-is-active {
+ color: var(--td-brand-color) !important;
+ }
}
</style>
diff --git a/frontend/src/api/initialization/index.ts b/frontend/src/api/initialization/index.ts
index 90ea608a5..9dd2d18dd 100644
--- a/frontend/src/api/initialization/index.ts
+++ b/frontend/src/api/initialization/index.ts
@@ -1,4 +1,4 @@
-import { get, post } from '../../utils/request';
+import { get, post, put } from '../../utils/request';
// 初始化配置数据类型
export interface InitializationConfig {
@@ -70,7 +70,59 @@ export interface DownloadTask {
endTime?: string;
}
-// 根据知识库ID执行配置更新
+// 简化版知识库配置更新接口(只传模型ID)
+export interface KBModelConfigRequest {
+ llmModelId: string
+ embeddingModelId: string
+ rerankModelId?: string
+ vllmModelId?: string
+ documentSplitting: {
+ chunkSize: number
+ chunkOverlap: number
+ separators: string[]
+ }
+ multimodal: {
+ enabled: boolean
+ storageType?: 'cos' | 'minio'
+ cos?: {
+ secretId: string
+ secretKey: string
+ region: string
+ bucketName: string
+ appId: string
+ pathPrefix: string
+ }
+ minio?: {
+ bucketName: string
+ useSSL: boolean
+ pathPrefix: string
+ }
+ }
+ nodeExtract: {
+ enabled: boolean
+ text: string
+ tags: string[]
+ nodes: Node[]
+ relations: Relation[]
+ }
+}
+
+export function updateKBConfig(kbId: string, config: KBModelConfigRequest): Promise<any> {
+ return new Promise((resolve, reject) => {
+ console.log('开始知识库配置更新(简化版)...', kbId, config);
+ put(`/api/v1/initialization/config/${kbId}`, config)
+ .then((response: any) => {
+ console.log('知识库配置更新完成', response);
+ resolve(response);
+ })
+ .catch((error: any) => {
+ console.error('知识库配置更新失败:', error);
+ reject(error.error || error);
+ });
+ });
+}
+
+// 根据知识库ID执行配置更新(旧版,保留兼容性)
export function initializeSystemByKB(kbId: string, config: InitializationConfig): Promise<any> {
return new Promise((resolve, reject) => {
console.log('开始知识库配置更新...', kbId, config);
diff --git a/frontend/src/components/Input-field.vue b/frontend/src/components/Input-field.vue
index 7b049b1a1..03b9607a7 100644
--- a/frontend/src/components/Input-field.vue
+++ b/frontend/src/components/Input-field.vue
@@ -219,24 +219,24 @@ const getImgSrc = (url: string) => {
max-height: 250px !important;
min-height: 112px !important;
resize: none;
- color: #000000e6;
+ color: var(--td-text-color-primary);
font-size: 16px;
font-weight: 400;
line-height: 24px;
font-family: "PingFang SC";
padding: 16px 12px 52px 16px; /* 增加底部padding为控制栏腾出空间 */
border-radius: 12px;
- border: 1px solid #E7E7E7;
+ border: 1px solid var(--td-component-border);
box-sizing: border-box;
- background: #FFF;
- box-shadow: 0 6px 6px 0 #0000000a, 0 12px 12px -1px #00000014;
+ background: var(--td-bg-color-container);
+ box-shadow: var(--td-shadow-1);
&:focus {
- border: 1px solid #07C05F;
+ border: 1px solid var(--td-brand-color);
}
&::placeholder {
- color: #00000066;
+ color: var(--td-text-color-placeholder);
font-family: "PingFang SC";
font-size: 16px;
font-weight: 400;
@@ -271,14 +271,14 @@ const getImgSrc = (url: string) => {
gap: 4px;
padding: 6px 10px;
border-radius: 6px;
- background: #f5f5f5;
+ background: var(--td-bg-color-component);
cursor: pointer;
transition: all 0.2s ease;
user-select: none;
flex-shrink: 0;
&:hover {
- background: #e6e6e6;
+ background: var(--td-bg-color-component-hover);
transform: scale(1.02);
}
@@ -291,7 +291,7 @@ const getImgSrc = (url: string) => {
cursor: not-allowed;
&:hover {
- background: #f5f5f5;
+ background: var(--td-bg-color-component);
transform: none;
}
}
@@ -303,10 +303,10 @@ const getImgSrc = (url: string) => {
padding: 0;
&.active {
- background: rgba(7, 192, 95, 0.1);
+ background: var(--td-brand-color-light);
&:hover {
- background: rgba(7, 192, 95, 0.15);
+ background: var(--td-brand-color-focus);
}
}
}
@@ -323,24 +323,24 @@ const getImgSrc = (url: string) => {
min-width: auto;
&.active {
- background: rgba(7, 192, 95, 0.1);
- color: #07C05F;
+ background: var(--td-brand-color-light);
+ color: var(--td-brand-color);
&:hover {
- background: rgba(7, 192, 95, 0.15);
+ background: var(--td-brand-color-focus);
}
}
}
.kb-btn-text {
font-size: 13px;
- color: #666;
+ color: var(--td-text-color-secondary);
font-weight: 500;
white-space: nowrap;
}
.kb-btn.active .kb-btn-text {
- color: #07C05F;
+ color: var(--td-brand-color);
}
.dropdown-arrow {
@@ -372,16 +372,16 @@ const getImgSrc = (url: string) => {
align-items: center;
gap: 4px;
padding: 4px 8px;
- background: rgba(7, 192, 95, 0.1);
- border: 1px solid rgba(7, 192, 95, 0.3);
+ background: var(--td-brand-color-light);
+ border: 1px solid var(--td-brand-color-3);
border-radius: 4px;
font-size: 12px;
- color: #07C05F;
+ color: var(--td-brand-color);
white-space: nowrap;
transition: all 0.15s ease;
&:hover {
- background: rgba(7, 192, 95, 0.15);
+ background: var(--td-brand-color-focus);
}
}
@@ -404,12 +404,12 @@ const getImgSrc = (url: string) => {
}
.more-tag {
- background: rgba(0, 0, 0, 0.05);
- border-color: rgba(0, 0, 0, 0.1);
- color: #666;
+ background: var(--td-bg-color-component);
+ border-color: var(--td-component-border);
+ color: var(--td-text-color-secondary);
&:hover {
- background: rgba(0, 0, 0, 0.08);
+ background: var(--td-bg-color-component-hover);
}
}
@@ -417,15 +417,15 @@ const getImgSrc = (url: string) => {
width: 28px;
height: 28px;
padding: 0;
- background-color: #07C05F;
+ background-color: var(--td-brand-color);
&:hover:not(.disabled) {
- background-color: #00a651;
+ background-color: var(--td-brand-color-hover);
transform: scale(1.05);
}
&.disabled {
- background-color: #b5eccf;
+ background-color: var(--td-brand-color-disabled);
}
img {
diff --git a/frontend/src/components/ModelSelector.vue b/frontend/src/components/ModelSelector.vue
new file mode 100644
index 000000000..3375cd880
--- /dev/null
+++ b/frontend/src/components/ModelSelector.vue
@@ -0,0 +1,161 @@
+<template>
+ <div class="model-selector">
+ <t-select
+ :value="selectedModelId"
+ @change="handleModelChange"
+ :placeholder="placeholder"
+ :disabled="disabled"
+ :loading="loading"
+ filterable
+ style="width: 100%;"
+ >
+ <!-- 已有的模型选项 -->
+ <t-option
+ v-for="model in models"
+ :key="model.id"
+ :value="model.id"
+ :label="model.name"
+ >
+ <div class="model-option">
+ <t-icon name="check-circle-filled" class="model-icon" />
+ <span class="model-name">{{ model.name }}</span>
+ <t-tag v-if="model.is_default" size="small" theme="success">默认</t-tag>
+ </div>
+ </t-option>
+
+ <!-- 添加模型选项(在底部) -->
+ <t-option
+ v-if="!disabled"
+ value="__add_model__"
+ class="add-model-option"
+ >
+ <div class="model-option add">
+ <t-icon name="add" class="add-icon" />
+ <span class="model-name">前往全局设置添加模型</span>
+ </div>
+ </t-option>
+ </t-select>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { ref, computed, watch, onMounted } from 'vue'
+import { listModels, type ModelConfig } from '@/api/model'
+import { MessagePlugin } from 'tdesign-vue-next'
+
+interface Props {
+ modelType: 'KnowledgeQA' | 'Embedding' | 'Rerank' | 'VLLM'
+ selectedModelId?: string
+ disabled?: boolean
+ placeholder?: string
+ // 可选:外部传入的所有模型列表,如果提供则不调用API
+ allModels?: ModelConfig[]
+}
+
+const props = withDefaults(defineProps<Props>(), {
+ disabled: false,
+ placeholder: '请选择模型'
+})
+
+const emit = defineEmits<{
+ 'update:selectedModelId': [value: string]
+ 'add-model': []
+}>()
+
+const models = ref<ModelConfig[]>([])
+const loading = ref(false)
+
+// 监听 allModels 变化,自动过滤当前类型的模型
+watch(() => props.allModels, (newModels) => {
+ if (newModels && Array.isArray(newModels)) {
+ models.value = newModels.filter(m => m.type === props.modelType)
+ }
+}, { immediate: true })
+
+const selectedModel = computed(() => {
+ if (!props.selectedModelId) return null
+ return models.value.find(m => m.id === props.selectedModelId)
+})
+
+// 加载模型列表(仅在未提供 allModels 时调用)
+const loadModels = async () => {
+ // 如果外部提供了 allModels,则不需要加载
+ if (props.allModels) {
+ return
+ }
+
+ loading.value = true
+ try {
+ const result = await listModels()
+ // 前端按类型筛选模型
+ if (result && Array.isArray(result)) {
+ models.value = result.filter(m => m.type === props.modelType)
+ } else {
+ models.value = []
+ }
+ } catch (error) {
+ console.error('加载模型列表失败:', error)
+ MessagePlugin.error('加载模型列表失败')
+ models.value = []
+ } finally {
+ loading.value = false
+ }
+}
+
+// 处理模型选择变化
+const handleModelChange = (value: string) => {
+ // 如果选择的是添加模型选项,触发添加事件而不更新选中值
+ if (value === '__add_model__') {
+ emit('add-model')
+ return
+ }
+ emit('update:selectedModelId', value)
+}
+
+// 暴露刷新方法给父组件
+defineExpose({
+ refresh: loadModels
+})
+
+onMounted(() => {
+ // 只有在没有提供 allModels 时才加载
+ if (!props.allModels) {
+ loadModels()
+ }
+})
+</script>
+
+<style lang="less" scoped>
+.model-selector {
+ width: 100%;
+}
+
+.model-option {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+
+ .model-icon {
+ font-size: 14px;
+ color: #07C05F;
+ }
+
+ .add-icon {
+ font-size: 14px;
+ color: #07C05F;
+ }
+
+ .model-name {
+ flex: 1;
+ font-size: 13px;
+ }
+
+ &.add {
+ .model-name {
+ color: #07C05F;
+ font-weight: 500;
+ }
+ }
+}
+</style>
+
diff --git a/frontend/src/components/UserMenu.vue b/frontend/src/components/UserMenu.vue
index 97e626b83..9181764d8 100644
--- a/frontend/src/components/UserMenu.vue
+++ b/frontend/src/components/UserMenu.vue
@@ -161,7 +161,7 @@ onUnmounted(() => {
background: transparent;
&:hover {
- background: #f5f7fa;
+ background: var(--td-bg-color-component-hover);
}
&:active {
@@ -175,7 +175,7 @@ onUnmounted(() => {
border-radius: 50%;
overflow: hidden;
flex-shrink: 0;
- background: linear-gradient(135deg, #07C05F 0%, #05A34E 100%);
+ background: linear-gradient(135deg, var(--td-brand-color) 0%, var(--td-brand-color-active) 100%);
display: flex;
align-items: center;
justify-content: center;
@@ -187,7 +187,7 @@ onUnmounted(() => {
}
.avatar-placeholder {
- color: #ffffff;
+ color: var(--td-text-color-anti);
font-size: 16px;
font-weight: 600;
}
@@ -201,7 +201,7 @@ onUnmounted(() => {
.user-name {
font-size: 14px;
font-weight: 500;
- color: #333333;
+ color: var(--td-text-color-primary);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
@@ -209,7 +209,7 @@ onUnmounted(() => {
.user-email {
font-size: 12px;
- color: #666666;
+ color: var(--td-text-color-secondary);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
@@ -218,7 +218,7 @@ onUnmounted(() => {
.dropdown-icon {
font-size: 16px;
- color: #666666;
+ color: var(--td-text-color-secondary);
flex-shrink: 0;
transition: transform 0.2s;
}
@@ -229,10 +229,10 @@ onUnmounted(() => {
left: 8px;
right: 8px;
margin-bottom: 8px;
- background: #ffffff;
+ background: var(--td-bg-color-container);
border-radius: 8px;
- box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
- border: 1px solid #e5e7eb;
+ box-shadow: var(--td-shadow-2);
+ border: 1px solid var(--td-component-border);
overflow: hidden;
z-index: 1000;
}
@@ -245,33 +245,33 @@ onUnmounted(() => {
cursor: pointer;
transition: all 0.2s;
font-size: 14px;
- color: #333333;
+ color: var(--td-text-color-primary);
&:hover {
- background: #f5f7fa;
+ background: var(--td-bg-color-component-hover);
}
&.danger {
- color: #e34d59;
+ color: var(--td-error-color);
&:hover {
- background: #fef0f0;
+ background: var(--td-error-color-light);
}
.menu-icon {
- color: #e34d59;
+ color: var(--td-error-color);
}
}
.menu-icon {
font-size: 16px;
- color: #666666;
+ color: var(--td-text-color-secondary);
}
}
.menu-divider {
height: 1px;
- background: #e5e7eb;
+ background: var(--td-component-border);
margin: 4px 0;
}
diff --git a/frontend/src/components/menu.vue b/frontend/src/components/menu.vue
index 9c4929c7b..a259b96ba 100644
--- a/frontend/src/components/menu.vue
+++ b/frontend/src/components/menu.vue
@@ -554,14 +554,14 @@ watch(() => route.params.kbId, () => {
</script>
<style lang="less" scoped>
.del_submenu {
- color: #fa5151;
+ color: var(--td-error-color);
cursor: pointer;
}
.aside_box {
min-width: 260px;
padding: 8px;
- background: #fff;
+ background: var(--td-bg-color-container);
box-sizing: border-box;
height: 100vh;
overflow: hidden;
@@ -585,10 +585,19 @@ watch(() => route.params.kbId, () => {
height: 30px;
margin-right: 7.25px;
}
+
+ /* 暗色模式下的Logo滤镜 */
+ :root[theme-mode="dark"] .logo {
+ filter: brightness(0) invert(1);
+ }
+
+ :root[theme-mode="dark"] .logo_img {
+ filter: brightness(0) invert(1);
+ }
.logo_txt {
transform: rotate(0.049deg);
- color: #000000;
+ color: var(--td-text-color-primary);
font-family: "TencentSans";
font-size: 24.12px;
font-style: normal;
@@ -630,28 +639,28 @@ watch(() => route.params.kbId, () => {
}
.upload-file-wrap:hover {
- background-color: #dbede4;
- color: #07C05F;
+ background-color: var(--td-brand-color-light);
+ color: var(--td-brand-color);
}
.upload-file-icon {
width: 20px;
height: 20px;
- color: rgba(0, 0, 0, 0.6);
+ color: var(--td-text-color-secondary);
}
.active-upload {
- color: #07C05F;
+ color: var(--td-brand-color);
}
.menu_item_active {
border-radius: 4px;
- background: #07c05f1a !important;
+ background: var(--td-brand-color-light) !important;
.menu_icon,
.menu_title {
- color: #07c05f !important;
+ color: var(--td-brand-color) !important;
}
}
@@ -659,7 +668,7 @@ watch(() => route.params.kbId, () => {
.menu_icon,
.menu_title {
- color: #000000e6;
+ color: var(--td-text-color-primary);
}
}
@@ -686,12 +695,12 @@ watch(() => route.params.kbId, () => {
&:hover {
border-radius: 4px;
- background: #30323605;
- color: #00000099;
+ background: var(--td-bg-color-container-hover);
+ color: var(--td-text-color-secondary);
.menu_icon,
.menu_title {
- color: #00000099;
+ color: var(--td-text-color-secondary);
}
}
}
@@ -699,7 +708,7 @@ watch(() => route.params.kbId, () => {
.menu_icon {
display: flex;
margin-right: 10px;
- color: #00000099;
+ color: var(--td-text-color-secondary);
.icon {
width: 20px;
@@ -710,7 +719,7 @@ watch(() => route.params.kbId, () => {
}
.menu_title {
- color: #00000099;
+ color: var(--td-text-color-secondary);
text-overflow: ellipsis;
font-family: "PingFang SC";
font-size: 14px;
@@ -745,7 +754,7 @@ watch(() => route.params.kbId, () => {
cursor: pointer;
display: flex;
align-items: center;
- color: #00000099;
+ color: var(--td-text-color-secondary);
font-weight: 400;
line-height: 22px;
height: 36px;
@@ -766,14 +775,14 @@ watch(() => route.params.kbId, () => {
.menu-more {
display: inline-block;
font-weight: bold;
- color: #07C05F;
+ color: var(--td-brand-color);
}
.dot {
width: 4px;
height: 4px;
border-radius: 50%;
- background: #07C05F;
+ background: var(--td-brand-color);
}
.sub_title {
@@ -781,12 +790,12 @@ watch(() => route.params.kbId, () => {
}
&:hover {
- background: #30323605;
- color: #00000099;
+ background: var(--td-bg-color-container-hover);
+ color: var(--td-text-color-secondary);
border-radius: 3px;
.menu-more {
- color: #00000099;
+ color: var(--td-text-color-secondary);
}
.submenu_title {
@@ -797,12 +806,12 @@ watch(() => route.params.kbId, () => {
}
.submenu_item_active {
- background: #07c05f1a !important;
- color: #07c05f !important;
+ background: var(--td-brand-color-light) !important;
+ color: var(--td-brand-color) !important;
border-radius: 3px;
.menu-more {
- color: #07c05f !important;
+ color: var(--td-brand-color) !important;
}
}
}
@@ -810,7 +819,7 @@ watch(() => route.params.kbId, () => {
/* 知识库下拉菜单样式 */
.kb-dropdown-icon {
margin-left: auto;
- color: #666;
+ color: var(--td-text-color-secondary);
transition: transform 0.3s ease, color 0.2s ease;
cursor: pointer;
display: flex;
@@ -824,15 +833,15 @@ watch(() => route.params.kbId, () => {
}
&:hover {
- color: #07c05f;
+ color: var(--td-brand-color);
}
&.active {
- color: #07c05f;
+ color: var(--td-brand-color);
}
&.active:hover {
- color: #05a04f;
+ color: var(--td-brand-color-hover);
}
svg {
@@ -847,10 +856,10 @@ watch(() => route.params.kbId, () => {
top: 100%;
left: 0;
right: 0;
- background: #fff;
- border: 1px solid #e5e7eb;
+ background: var(--td-bg-color-container);
+ border: 1px solid var(--td-component-border);
border-radius: 6px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
+ box-shadow: var(--td-shadow-2);
z-index: 1000;
max-height: 200px;
overflow-y: auto;
@@ -861,15 +870,15 @@ watch(() => route.params.kbId, () => {
cursor: pointer;
transition: background-color 0.2s ease;
font-size: 14px;
- color: #333;
+ color: var(--td-text-color-primary);
&:hover {
- background-color: #f5f5f5;
+ background-color: var(--td-bg-color-container-hover);
}
&.active {
- background-color: #07c05f1a;
- color: #07c05f;
+ background-color: var(--td-brand-color-light);
+ color: var(--td-brand-color);
font-weight: 500;
}
@@ -895,15 +904,15 @@ watch(() => route.params.kbId, () => {
</style>
<style lang="less">
.upload-popup {
- background-color: rgba(0, 0, 0, 0.9);
- color: #FFFFFF;
- border-color: rgba(0, 0, 0, 0.9) !important;
+ background-color: var(--td-gray-color-13);
+ color: var(--td-text-color-anti);
+ border-color: var(--td-gray-color-13) !important;
box-shadow: none;
margin-bottom: 10px !important;
.t-popup__arrow::before {
- border-color: rgba(0, 0, 0, 0.9) !important;
- background-color: rgba(0, 0, 0, 0.9) !important;
+ border-color: var(--td-gray-color-13) !important;
+ background-color: var(--td-gray-color-13) !important;
box-shadow: none !important;
}
}
@@ -925,22 +934,22 @@ watch(() => route.params.kbId, () => {
// 退出登录确认框样式
:deep(.t-popconfirm) {
.t-popconfirm__content {
- background: #fff;
- border: 1px solid #e7e7e7;
+ background: var(--td-bg-color-container);
+ border: 1px solid var(--td-component-border);
border-radius: 6px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
+ box-shadow: var(--td-shadow-2);
padding: 12px 16px;
font-size: 14px;
- color: #333;
+ color: var(--td-text-color-primary);
max-width: 200px;
}
.t-popconfirm__arrow {
- border-bottom-color: #e7e7e7;
+ border-bottom-color: var(--td-component-border);
}
.t-popconfirm__arrow::after {
- border-bottom-color: #fff;
+ border-bottom-color: var(--td-bg-color-container);
}
.t-popconfirm__buttons {
@@ -951,18 +960,18 @@ watch(() => route.params.kbId, () => {
}
.t-button--variant-outline {
- border-color: #d9d9d9;
- color: #666;
+ border-color: var(--td-component-border);
+ color: var(--td-text-color-secondary);
}
.t-button--theme-danger {
- background-color: #ff4d4f;
- border-color: #ff4d4f;
+ background-color: var(--td-error-color);
+ border-color: var(--td-error-color);
}
.t-button--theme-danger:hover {
- background-color: #ff7875;
- border-color: #ff7875;
+ background-color: var(--td-error-color-hover);
+ border-color: var(--td-error-color-hover);
}
}
</style>
\ No newline at end of file
diff --git a/frontend/src/stores/ui.ts b/frontend/src/stores/ui.ts
index e7d7aabe2..8463e6ac0 100644
--- a/frontend/src/stores/ui.ts
+++ b/frontend/src/stores/ui.ts
@@ -1,21 +1,93 @@
import { defineStore } from 'pinia'
+type Theme = 'light' | 'dark'
+
export const useUIStore = defineStore('ui', {
state: () => ({
- showSettingsModal: false
+ showSettingsModal: false,
+ showKBSettingsModal: false,
+ currentKBId: null as string | null,
+ settingsInitialSection: null as string | null,
+ settingsInitialSubSection: null as string | null,
+ theme: 'light' as Theme
}),
actions: {
- openSettings() {
+ openSettings(section?: string, subSection?: string) {
+ this.settingsInitialSection = section || null
+ this.settingsInitialSubSection = subSection || null
this.showSettingsModal = true
},
closeSettings() {
this.showSettingsModal = false
+ this.settingsInitialSection = null
+ this.settingsInitialSubSection = null
},
toggleSettings() {
this.showSettingsModal = !this.showSettingsModal
+ },
+
+ openKBSettings(kbId: string) {
+ this.currentKBId = kbId
+ this.showKBSettingsModal = true
+ },
+
+ closeKBSettings() {
+ this.showKBSettingsModal = false
+ this.currentKBId = null
+ },
+
+ // 初始化主题(从localStorage加载)
+ initTheme() {
+ const savedSettings = localStorage.getItem('WeKnora_general_settings')
+ if (savedSettings) {
+ try {
+ const parsed = JSON.parse(savedSettings)
+ this.theme = parsed.theme || 'light'
+ } catch (e) {
+ console.error('加载主题设置失败:', e)
+ this.theme = 'light'
+ }
+ }
+ this.applyTheme()
+ },
+
+ // 设置主题
+ setTheme(theme: Theme) {
+ this.theme = theme
+ this.applyTheme()
+ this.saveThemeToStorage()
+ },
+
+ // 切换主题
+ toggleTheme() {
+ this.theme = this.theme === 'light' ? 'dark' : 'light'
+ this.applyTheme()
+ this.saveThemeToStorage()
+ },
+
+ // 应用主题到DOM
+ applyTheme() {
+ document.documentElement.setAttribute('theme-mode', this.theme)
+ },
+
+ // 保存主题到localStorage
+ saveThemeToStorage() {
+ const savedSettings = localStorage.getItem('WeKnora_general_settings')
+ let settings = { language: 'zh-CN', theme: this.theme }
+
+ if (savedSettings) {
+ try {
+ const parsed = JSON.parse(savedSettings)
+ settings = { ...parsed, theme: this.theme }
+ } catch (e) {
+ console.error('解析现有设置失败:', e)
+ }
+ }
+
+ localStorage.setItem('WeKnora_general_settings', JSON.stringify(settings))
}
}
})
diff --git a/frontend/src/views/chat/components/AgentStreamDisplay.vue b/frontend/src/views/chat/components/AgentStreamDisplay.vue
index 45c3805ce..2d027c6e7 100644
--- a/frontend/src/views/chat/components/AgentStreamDisplay.vue
+++ b/frontend/src/views/chat/components/AgentStreamDisplay.vue
@@ -480,7 +480,7 @@ const formatJSON = (obj: any): string => {
.collapse-text {
font-size: 13px;
- color: #333333;
+ color: var(--td-text-color-primary);
font-weight: 500;
letter-spacing: -0.01em;
}
@@ -495,15 +495,15 @@ const formatJSON = (obj: any): string => {
animation: fadeInUp 0.3s ease-out;
.thinking-phase {
- background: #ffffff;
+ background: var(--td-bg-color-container);
border-radius: 8px;
padding: 1px 14px;
- border-left: 3px solid #d1d5db;
- box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
+ border-left: 3px solid var(--td-component-border);
+ box-shadow: var(--td-shadow-1);
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
&.thinking-active {
- border-left-color: #07c05f;
+ border-left-color: var(--td-brand-color);
box-shadow: 0 2px 4px rgba(7, 192, 95, 0.08);
animation: pulseBorder 2s ease-in-out infinite;
}
@@ -511,7 +511,7 @@ const formatJSON = (obj: any): string => {
.thinking-content {
font-size: 14px;
- color: #333333;
+ color: var(--td-text-color-primary);
line-height: 1.6;
&.markdown-content {
@@ -551,16 +551,16 @@ const formatJSON = (obj: any): string => {
}
:deep(blockquote) {
- border-left: 3px solid #07c05f;
+ border-left: 3px solid var(--td-brand-color);
padding-left: 12px;
margin: 8px 0;
- color: #666;
+ color: var(--td-text-color-secondary);
}
:deep(h1), :deep(h2), :deep(h3), :deep(h4), :deep(h5), :deep(h6) {
margin: 12px 0 8px 0;
font-weight: 600;
- color: #333;
+ color: var(--td-text-color-primary);
}
:deep(a) {
@@ -623,9 +623,9 @@ const formatJSON = (obj: any): string => {
.tool-summary {
padding: 8px 14px;
font-size: 13px;
- color: #333333;
- background: #ffffff;
- border-top: 1px solid #f0f0f0;
+ color: var(--td-text-color-primary);
+ background: var(--td-bg-color-container);
+ border-top: 1px solid var(--td-component-border);
line-height: 1.6;
font-weight: 500;
animation: slideIn 0.25s ease-out;
@@ -633,11 +633,11 @@ const formatJSON = (obj: any): string => {
.tool-summary-markdown {
font-weight: 400;
line-height: 1.6;
- color: #333333;
+ color: var(--td-text-color-primary);
:deep(p) {
margin: 4px 0;
- color: #333333;
+ color: var(--td-text-color-primary);
}
:deep(ul), :deep(ol) {
@@ -646,17 +646,17 @@ const formatJSON = (obj: any): string => {
}
:deep(code) {
- background: #f5f5f5;
+ background: var(--td-bg-color-component);
padding: 2px 6px;
border-radius: 4px;
font-size: 12px;
- color: #07c05f;
+ color: var(--td-brand-color);
font-weight: 500;
}
:deep(strong) {
font-weight: 600;
- color: #333333;
+ color: var(--td-text-color-primary);
}
}
}
@@ -708,8 +708,8 @@ const formatJSON = (obj: any): string => {
}
&.pending {
- color: #666666;
- background: rgba(102, 102, 102, 0.1);
+ color: var(--td-text-color-secondary);
+ background: var(--td-bg-color-component);
animation: pulse 1.5s ease-in-out infinite;
}
}
@@ -782,12 +782,12 @@ const formatJSON = (obj: any): string => {
.action-name {
font-size: 14px;
font-weight: 500;
- color: #333;
+ color: var(--td-text-color-primary);
}
.expand-icon {
font-size: 12px;
- color: #07c05f;
+ color: var(--td-brand-color);
transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
font-weight: 600;
opacity: 0.8;
@@ -804,8 +804,8 @@ const formatJSON = (obj: any): string => {
.action-details {
padding: 0 12px 12px 12px;
- border-top: 1px solid #e5e7eb;
- background: #fff;
+ border-top: 1px solid var(--td-component-border);
+ background: var(--td-bg-color-container);
}
.detail-row {
@@ -818,15 +818,15 @@ const formatJSON = (obj: any): string => {
.detail-label {
font-size: 12px;
font-weight: 600;
- color: #666;
+ color: var(--td-text-color-secondary);
text-transform: uppercase;
letter-spacing: 0.5px;
}
.detail-value {
font-size: 13px;
- color: #07c05f;
- background: rgba(7, 192, 95, 0.05);
+ color: var(--td-brand-color);
+ background: var(--td-brand-color-light);
padding: 2px 6px;
border-radius: 3px;
font-family: 'Monaco', 'Courier New', monospace;
@@ -835,25 +835,25 @@ const formatJSON = (obj: any): string => {
.detail-code {
font-size: 12px;
- background: #f5f5f5;
+ background: var(--td-bg-color-component);
padding: 8px;
border-radius: 4px;
font-family: 'Monaco', 'Courier New', monospace;
- color: #333;
+ color: var(--td-text-color-primary);
margin: 0;
overflow-x: auto;
- border: 1px solid #e5e7eb;
+ border: 1px solid var(--td-component-border);
}
.detail-output {
font-size: 13px;
- color: #333;
- background: #f5f5f5;
+ color: var(--td-text-color-primary);
+ background: var(--td-bg-color-component);
padding: 8px;
border-radius: 4px;
white-space: pre-wrap;
word-break: break-word;
- border: 1px solid #e5e7eb;
+ border: 1px solid var(--td-component-border);
}
.loading-indicator {
diff --git a/frontend/src/views/chat/components/botmsg.vue b/frontend/src/views/chat/components/botmsg.vue
index 7e59b9f65..e46b818ca 100644
--- a/frontend/src/views/chat/components/botmsg.vue
+++ b/frontend/src/views/chat/components/botmsg.vue
@@ -229,10 +229,10 @@ onMounted(async () => {
}
.img_loading {
- background: #3032360f;
+ background: var(--td-bg-color-component);
height: 230px;
width: 230px;
- color: #00000042;
+ color: var(--td-text-color-placeholder);
display: flex;
align-items: center;
justify-content: center;
diff --git a/frontend/src/views/chat/components/tool-results/tool-results.less b/frontend/src/views/chat/components/tool-results/tool-results.less
index 7188fcef9..aae7b563b 100644
--- a/frontend/src/views/chat/components/tool-results/tool-results.less
+++ b/frontend/src/views/chat/components/tool-results/tool-results.less
@@ -9,13 +9,13 @@
@relevance-low: #757575;
@relevance-weak: #bdbdbd;
-// Card colors
-@card-bg: #f8f9fa;
-@card-border: #e7e7e7;
-@card-hover-border: #07c05f;
+// Card colors - use CSS variables for theme support
+@card-bg: var(--td-bg-color-secondarycontainer);
+@card-border: var(--td-component-border);
+@card-hover-border: var(--td-brand-color);
@card-radius: 8px;
-@card-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
-@card-shadow-hover: 0 4px 8px rgba(0, 0, 0, 0.1);
+@card-shadow: var(--td-shadow-1);
+@card-shadow-hover: var(--td-shadow-2);
// Animation timing
@transition-time: 0.3s;
@@ -52,7 +52,7 @@
&.weak {
background-color: @relevance-weak;
- color: #333;
+ color: var(--td-text-color-primary);
}
}
@@ -63,8 +63,8 @@
padding: 2px 6px;
border-radius: 3px;
font-size: 11px;
- background-color: #e7e7e7;
- color: #666;
+ background-color: var(--td-bg-color-component);
+ color: var(--td-text-color-secondary);
gap: 2px;
}
@@ -111,13 +111,13 @@
align-items: center;
gap: 6px;
font-size: 12px;
- color: #8b8b8b;
+ color: var(--td-text-color-placeholder);
}
.result-content {
padding: 0 12px 12px 12px;
border-top: 1px solid @card-border;
- background: white;
+ background: var(--td-bg-color-container);
max-height: 0;
opacity: 0;
overflow: hidden;
@@ -132,7 +132,7 @@
.expand-icon {
font-size: 12px;
- color: #8b8b8b;
+ color: var(--td-text-color-placeholder);
transition: transform 0.2s ease;
&.expanded {
@@ -152,7 +152,7 @@
.info-section-title {
font-size: 12px;
font-weight: 600;
- color: #666;
+ color: var(--td-text-color-secondary);
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 6px;
@@ -165,20 +165,20 @@
font-size: 13px;
.field-label {
- color: #8b8b8b;
+ color: var(--td-text-color-placeholder);
min-width: 80px;
}
.field-value {
- color: #333;
+ color: var(--td-text-color-primary);
flex: 1;
}
}
// Statistics card (for KB counts, etc.)
.stats-card {
- background: #f0f7ff;
- border: 1px solid #d6e4ff;
+ background: var(--td-brand-color-light);
+ border: 1px solid var(--td-brand-color-3);
border-radius: 6px;
padding: 10px 12px;
margin-bottom: 12px;
@@ -187,7 +187,7 @@
.stats-title {
font-size: 13px;
font-weight: 600;
- color: #333;
+ color: var(--td-text-color-primary);
margin-bottom: 6px;
}
@@ -199,7 +199,7 @@
.stats-item {
font-size: 12px;
- color: #666;
+ color: var(--td-text-color-secondary);
display: flex;
justify-content: space-between;
}
@@ -218,7 +218,7 @@
flex-direction: column;
gap: 4px;
padding: 8px 0;
- border-bottom: 1px solid #f0f0f0;
+ border-bottom: 1px solid var(--td-component-border);
&:last-child {
border-bottom: none;
@@ -228,7 +228,7 @@
// Content preview (truncated)
.content-preview {
font-size: 13px;
- color: #333;
+ color: var(--td-text-color-primary);
line-height: 1.5;
max-height: 60px;
overflow: hidden;
@@ -241,12 +241,12 @@
// Full content
.full-content {
font-size: 13px;
- color: #333;
+ color: var(--td-text-color-primary);
line-height: 1.6;
white-space: pre-wrap;
word-break: break-word;
padding: 8px;
- background: #f5f5f5;
+ background: var(--td-bg-color-component);
border-radius: 4px;
border: 1px solid @card-border;
}
@@ -257,8 +257,8 @@
font-size: 12px;
border-radius: 4px;
border: 1px solid @card-border;
- background: white;
- color: #666;
+ background: var(--td-bg-color-container);
+ color: var(--td-text-color-secondary);
cursor: pointer;
transition: all 0.2s ease;
@@ -272,7 +272,7 @@
.empty-state {
padding: 24px;
text-align: center;
- color: #8b8b8b;
+ color: var(--td-text-color-placeholder);
font-size: 14px;
}
@@ -280,7 +280,7 @@
.code-block {
font-family: 'Monaco', 'Courier New', monospace;
font-size: 12px;
- background: #f5f5f5;
+ background: var(--td-bg-color-component);
padding: 8px;
border-radius: 4px;
border: 1px solid @card-border;
diff --git a/frontend/src/views/chat/components/usermsg.vue b/frontend/src/views/chat/components/usermsg.vue
index fed5d6b67..24b58bdb8 100644
--- a/frontend/src/views/chat/components/usermsg.vue
+++ b/frontend/src/views/chat/components/usermsg.vue
@@ -26,9 +26,9 @@ const props = defineProps({
gap: 4px;
flex: 1 0 0;
border-radius: 4px;
- background: #8CE97F;
+ background: var(--td-brand-color-light);
margin-left: auto;
- color: #000000e6;
+ color: var(--td-text-color-primary);
font-size: 16px;
text-align: justify;
word-break: break-all;
diff --git a/frontend/src/views/chat/index.vue b/frontend/src/views/chat/index.vue
index b29d9e44f..2d179ebf0 100644
--- a/frontend/src/views/chat/index.vue
+++ b/frontend/src/views/chat/index.vue
@@ -12,7 +12,7 @@
</div>
</div>
<div v-if="loading"
- style="height: 41px;display: flex;align-items: center;background: #fff;width: 58px;">
+ style="height: 41px;display: flex;align-items: center;background: var(--td-bg-color-container);width: 58px;">
<img class="botanswer_laoding_gif" src="@/assets/img/botanswer_loading.gif" alt="正在等待答案……">
</div>
</div>
@@ -561,8 +561,8 @@ onBeforeRouteUpdate((to, from, next) => {
align-items: center;
gap: 8px;
padding: 8px 16px;
- background: linear-gradient(135deg, #e6f7ff 0%, #bae7ff 100%);
- border: 1px solid #91d5ff;
+ background: var(--td-brand-color-light);
+ border: 1px solid var(--td-brand-color-3);
border-radius: 6px;
margin-bottom: 12px;
max-width: 800px;
@@ -575,7 +575,7 @@ onBeforeRouteUpdate((to, from, next) => {
.agent-text {
font-size: 14px;
font-weight: 500;
- color: #0050b3;
+ color: var(--td-brand-color);
flex: 1;
}
}
diff --git a/frontend/src/views/knowledge/KnowledgeBaseList.vue b/frontend/src/views/knowledge/KnowledgeBaseList.vue
index cb8ecc98a..d8a7e8c2d 100644
--- a/frontend/src/views/knowledge/KnowledgeBaseList.vue
+++ b/frontend/src/views/knowledge/KnowledgeBaseList.vue
@@ -67,17 +67,27 @@
</t-form-item>
</t-form>
</t-dialog>
+
+ <!-- 知识库设置模态框 -->
+ <KnowledgeBaseSettingsModal />
+
+ <!-- 全局设置模态框 -->
+ <Settings />
</div>
</template>
<script setup lang="ts">
-import { onMounted, reactive, ref, computed } from 'vue'
+import { onMounted, reactive, ref, computed, watch } from 'vue'
import { useRouter } from 'vue-router'
import { MessagePlugin } from 'tdesign-vue-next'
import { listKnowledgeBases, createKnowledgeBase, deleteKnowledgeBase } from '@/api/knowledge-base'
import { formatStringDate } from '@/utils/index'
+import { useUIStore } from '@/stores/ui'
+import KnowledgeBaseSettingsModal from './KnowledgeBaseSettingsModal.vue'
+import Settings from '@/views/settings/Settings.vue'
const router = useRouter()
+const uiStore = useUIStore()
interface KB {
id: string;
@@ -167,14 +177,23 @@ const goDetail = (id: string) => {
router.push(`/platform/knowledge-bases/${id}`)
}
const goSettings = (id: string) => {
- router.push(`/platform/knowledge-bases/${id}/settings`)
+ // 使用模态框打开设置,而不是路由导航
+ uiStore.openKBSettings(id)
}
+
+// 监听知识库设置模态框关闭,刷新列表
+watch(() => uiStore.showKBSettingsModal, (newVal, oldVal) => {
+ // 当模态框从打开变为关闭时,刷新列表
+ if (oldVal && !newVal) {
+ fetchList()
+ }
+})
</script>
<style scoped lang="less">
.kb-list-container {
padding: 20px;
- background: #fff;
+ background: var(--td-bg-color-container);
margin: 0 20px 0 20px;
height: calc(100vh);
overflow-y: auto;
@@ -186,7 +205,7 @@ const goSettings = (id: string) => {
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
- h2 { margin: 0; font-size: 20px; font-weight: 600; }
+ h2 { margin: 0; font-size: 20px; font-weight: 600; color: var(--td-text-color-primary); }
}
.warning-banner {
@@ -195,14 +214,14 @@ const goSettings = (id: string) => {
gap: 8px;
padding: 12px 16px;
margin-bottom: 16px;
- background: #fff7e6;
- border: 1px solid #ffd591;
+ background: var(--td-warning-color-light);
+ border: 1px solid var(--td-warning-color-3);
border-radius: 6px;
- color: #d46b08;
+ color: var(--td-warning-color);
font-size: 14px;
.t-icon {
- color: #d46b08;
+ color: var(--td-warning-color);
flex-shrink: 0;
}
}
@@ -213,21 +232,21 @@ const goSettings = (id: string) => {
gap: 8px;
.warning-icon {
- color: #ff8800;
+ color: var(--td-warning-color);
cursor: pointer;
font-size: 16px;
font-weight: bold;
transition: color 0.2s;
&:hover {
- color: #d46b08;
+ color: var(--td-warning-color-hover);
}
}
}
.description-cell {
.description-text {
- color: #000000e6;
+ color: var(--td-text-color-primary);
font-size: 14px;
}
}
diff --git a/frontend/src/views/knowledge/KnowledgeBaseSettingsModal.vue b/frontend/src/views/knowledge/KnowledgeBaseSettingsModal.vue
new file mode 100644
index 000000000..63a431d70
--- /dev/null
+++ b/frontend/src/views/knowledge/KnowledgeBaseSettingsModal.vue
@@ -0,0 +1,668 @@
+<template>
+ <Teleport to="body">
+ <Transition name="modal">
+ <div v-if="visible" class="settings-overlay" @click.self="handleClose">
+ <div class="settings-modal">
+ <!-- 关闭按钮 -->
+ <button class="close-btn" @click="handleClose" aria-label="关闭设置">
+ <svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor">
+ <path d="M15 5L5 15M5 5L15 15" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
+ </svg>
+ </button>
+
+ <div class="settings-container">
+ <!-- 左侧导航 -->
+ <div class="settings-sidebar">
+ <div class="sidebar-header">
+ <h2 class="sidebar-title">知识库设置</h2>
+ </div>
+ <div class="settings-nav">
+ <div
+ v-for="(item, index) in navItems"
+ :key="index"
+ :class="['nav-item', { 'active': currentSection === item.key }]"
+ @click="currentSection = item.key"
+ >
+ <span class="nav-icon">{{ item.icon }}</span>
+ <span class="nav-label">{{ item.label }}</span>
+ </div>
+ </div>
+ </div>
+
+ <!-- 右侧内容区域 -->
+ <div class="settings-content">
+ <div class="content-wrapper">
+ <!-- 基本信息 -->
+ <div v-show="currentSection === 'basic'" class="section">
+ <KBBasicInfo
+ v-if="kbData"
+ :kb-id="kbId"
+ :name="kbData.name"
+ :description="kbData.description"
+ @update:name="kbData.name = $event"
+ @update:description="kbData.description = $event"
+ />
+ </div>
+
+ <!-- 模型配置 -->
+ <div v-show="currentSection === 'models'" class="section">
+ <KBModelConfig
+ ref="modelConfigRef"
+ v-if="configData"
+ :config="modelConfig"
+ :has-files="configData.hasFiles"
+ :all-models="allModels"
+ @update:config="handleModelConfigUpdate"
+ />
+ </div>
+
+ <!-- 分块设置 -->
+ <div v-show="currentSection === 'chunking'" class="section">
+ <KBChunkingSettings
+ v-if="configData"
+ :config="chunkingConfig"
+ @update:config="handleChunkingConfigUpdate"
+ />
+ </div>
+
+ <!-- 高级设置 -->
+ <div v-show="currentSection === 'advanced'" class="section">
+ <KBAdvancedSettings
+ ref="advancedSettingsRef"
+ v-if="configData"
+ :multimodal="multimodalConfig"
+ :node-extract="nodeExtractConfig"
+ :all-models="allModels"
+ @update:multimodal="handleMultimodalUpdate"
+ @update:nodeExtract="handleNodeExtractUpdate"
+ />
+ </div>
+ </div>
+
+ <!-- 保存按钮 -->
+ <div class="settings-footer">
+ <t-button theme="default" variant="outline" @click="handleClose">
+ 取消
+ </t-button>
+ <t-button theme="primary" @click="handleSave" :loading="saving">
+ 保存配置
+ </t-button>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </Transition>
+ </Teleport>
+</template>
+
+<script setup lang="ts">
+import { ref, computed, watch, onMounted } from 'vue'
+import { useUIStore } from '@/stores/ui'
+import { MessagePlugin } from 'tdesign-vue-next'
+import { getKnowledgeBaseById, listKnowledgeFiles } from '@/api/knowledge-base'
+import { updateKBConfig, type KBModelConfigRequest } from '@/api/initialization'
+import { listModels } from '@/api/model'
+import KBBasicInfo from './settings/KBBasicInfo.vue'
+import KBModelConfig from './settings/KBModelConfig.vue'
+import KBChunkingSettings from './settings/KBChunkingSettings.vue'
+import KBAdvancedSettings from './settings/KBAdvancedSettings.vue'
+
+const uiStore = useUIStore()
+
+const visible = computed(() => uiStore.showKBSettingsModal)
+const kbId = computed(() => uiStore.currentKBId || '')
+
+const currentSection = ref<string>('basic')
+const saving = ref(false)
+const loading = ref(false)
+const allModels = ref<any[]>([])
+
+const navItems = [
+ { key: 'basic', icon: 'ℹ️', label: '基本信息' },
+ { key: 'models', icon: '🤖', label: '模型配置' },
+ { key: 'chunking', icon: '📄', label: '分块设置' },
+ { key: 'advanced', icon: '⚙️', label: '高级设置' }
+]
+
+// 知识库基本数据
+const kbData = ref<{
+ name: string
+ description?: string
+} | null>(null)
+
+// 配置数据(简化为只需要 hasFiles 标记)
+const configData = ref<{ hasFiles: boolean } | null>(null)
+
+// 模型配置引用
+const modelConfigRef = ref<InstanceType<typeof KBModelConfig>>()
+const advancedSettingsRef = ref<InstanceType<typeof KBAdvancedSettings>>()
+
+// 模型配置
+const modelConfig = ref({
+ llmModelId: '',
+ embeddingModelId: '',
+ rerankModelId: ''
+})
+
+// 分块配置
+const chunkingConfig = ref({
+ chunkSize: 512,
+ chunkOverlap: 100,
+ separators: ['\n\n', '\n', '。', '!', '?', ';', ';']
+})
+
+// 多模态配置
+const multimodalConfig = ref({
+ enabled: false,
+ storageType: 'minio' as 'minio' | 'cos',
+ vllmModelId: '',
+ minio: {
+ bucketName: '',
+ useSSL: false,
+ pathPrefix: ''
+ },
+ cos: {
+ secretId: '',
+ secretKey: '',
+ region: '',
+ bucketName: '',
+ appId: '',
+ pathPrefix: ''
+ }
+})
+
+// 知识图谱配置
+const nodeExtractConfig = ref({
+ enabled: false,
+ text: '',
+ tags: [] as string[]
+})
+
+// 加载所有模型(统一加载,避免重复调用)
+const loadAllModels = async () => {
+ try {
+ const models = await listModels()
+ allModels.value = models || []
+ return models || []
+ } catch (error) {
+ console.error('加载模型列表失败:', error)
+ MessagePlugin.error('加载模型列表失败')
+ allModels.value = []
+ return []
+ }
+}
+
+// 加载知识库数据
+const loadKBData = async () => {
+ if (!kbId.value) return
+
+ loading.value = true
+ try {
+ // 并行加载知识库信息和所有模型(只需要一个接口!)
+ const [kbInfo, models] = await Promise.all([
+ getKnowledgeBaseById(kbId.value),
+ loadAllModels()
+ ])
+
+ if (!kbInfo || !kbInfo.data) {
+ throw new Error('知识库不存在')
+ }
+
+ const kb = kbInfo.data
+
+ // 设置基本信息
+ kbData.value = {
+ name: kb.name || '',
+ description: kb.description || ''
+ }
+
+ // 设置模型ID(直接从知识库数据中获取)
+ modelConfig.value = {
+ llmModelId: kb.summary_model_id || '',
+ embeddingModelId: kb.embedding_model_id || '',
+ rerankModelId: kb.rerank_model_id || ''
+ }
+
+ // 设置分块配置
+ chunkingConfig.value = {
+ chunkSize: kb.chunking_config?.chunk_size || 512,
+ chunkOverlap: kb.chunking_config?.chunk_overlap || 100,
+ separators: kb.chunking_config?.separators || ['\n\n', '\n', '。', '!', '?', ';', ';']
+ }
+
+ // 设置多模态配置
+ // 判断是否真的有存储配置:provider 不为空且有实际的存储信息
+ const hasStorage = kb.cos_config?.provider && (
+ (kb.cos_config.provider === 'minio' && kb.cos_config.bucket_name) ||
+ (kb.cos_config.provider === 'cos' && kb.cos_config.bucket_name)
+ )
+ const hasVLM = !!kb.vlm_model_id
+
+ multimodalConfig.value = {
+ enabled: !!(hasStorage || hasVLM),
+ storageType: (kb.cos_config?.provider || 'minio') as 'minio' | 'cos',
+ vllmModelId: kb.vlm_model_id || '',
+ minio: {
+ bucketName: kb.cos_config?.bucket_name || '',
+ useSSL: false,
+ pathPrefix: kb.cos_config?.path_prefix || ''
+ },
+ cos: {
+ secretId: kb.cos_config?.secret_id || '',
+ secretKey: kb.cos_config?.secret_key || '',
+ region: kb.cos_config?.region || '',
+ bucketName: kb.cos_config?.bucket_name || '',
+ appId: kb.cos_config?.app_id || '',
+ pathPrefix: kb.cos_config?.path_prefix || ''
+ }
+ }
+
+ // 设置知识图谱配置
+ if (kb.extract_config) {
+ nodeExtractConfig.value = {
+ enabled: true,
+ text: kb.extract_config.text || '',
+ tags: kb.extract_config.tags || []
+ }
+ } else {
+ nodeExtractConfig.value = {
+ enabled: false,
+ text: '',
+ tags: []
+ }
+ }
+
+ // 检查是否有文件(用于判断是否可以修改Embedding模型)
+ const knowledgeList = await listKnowledgeFiles(kbId.value, { page: 1, page_size: 1 })
+ const hasFiles = knowledgeList && knowledgeList.data && knowledgeList.data.items && knowledgeList.data.items.length > 0
+
+ // 设置 configData(用于传递 hasFiles 状态)
+ configData.value = { hasFiles } as any
+
+ } catch (error) {
+ console.error('加载知识库数据失败:', error)
+ MessagePlugin.error('加载知识库数据失败')
+ } finally {
+ loading.value = false
+ }
+}
+
+// 不再需要 mapModelIds,直接使用知识库返回的模型ID
+
+// 处理模型配置更新
+const handleModelConfigUpdate = (newConfig: typeof modelConfig.value) => {
+ modelConfig.value = newConfig
+}
+
+// 处理分块配置更新
+const handleChunkingConfigUpdate = (newConfig: typeof chunkingConfig.value) => {
+ chunkingConfig.value = newConfig
+}
+
+// 处理多模态配置更新
+const handleMultimodalUpdate = (newConfig: typeof multimodalConfig.value) => {
+ multimodalConfig.value = newConfig
+}
+
+// 处理知识图谱配置更新
+const handleNodeExtractUpdate = (newConfig: typeof nodeExtractConfig.value) => {
+ nodeExtractConfig.value = newConfig
+}
+
+// 保存配置
+const handleSave = async () => {
+ if (saving.value || !kbId.value) return
+
+ // 验证必填项 - 模型配置
+ if (!modelConfig.value.llmModelId) {
+ MessagePlugin.warning('请选择LLM模型')
+ currentSection.value = 'models'
+ return
+ }
+
+ if (!modelConfig.value.embeddingModelId) {
+ MessagePlugin.warning('请选择Embedding模型')
+ currentSection.value = 'models'
+ return
+ }
+
+ // 验证多模态配置
+ if (multimodalConfig.value.enabled) {
+ // 验证VLLM模型(必选)
+ if (!multimodalConfig.value.vllmModelId) {
+ MessagePlugin.warning('多模态功能已启用,请选择VLLM视觉模型')
+ currentSection.value = 'advanced'
+ return
+ }
+
+ // 验证存储配置
+ if (multimodalConfig.value.storageType === 'minio') {
+ if (!multimodalConfig.value.minio.bucketName) {
+ MessagePlugin.warning('使用MinIO存储时,Bucket名称为必填项')
+ currentSection.value = 'advanced'
+ return
+ }
+ } else if (multimodalConfig.value.storageType === 'cos') {
+ const cos = multimodalConfig.value.cos
+ if (!cos.secretId) {
+ MessagePlugin.warning('使用腾讯云COS时,SecretId为必填项')
+ currentSection.value = 'advanced'
+ return
+ }
+ if (!cos.secretKey) {
+ MessagePlugin.warning('使用腾讯云COS时,SecretKey为必填项')
+ currentSection.value = 'advanced'
+ return
+ }
+ if (!cos.region) {
+ MessagePlugin.warning('使用腾讯云COS时,地域为必填项')
+ currentSection.value = 'advanced'
+ return
+ }
+ if (!cos.bucketName) {
+ MessagePlugin.warning('使用腾讯云COS时,Bucket名称为必填项')
+ currentSection.value = 'advanced'
+ return
+ }
+ if (!cos.appId) {
+ MessagePlugin.warning('使用腾讯云COS时,AppId为必填项')
+ currentSection.value = 'advanced'
+ return
+ }
+ }
+ }
+
+ saving.value = true
+ try {
+ // 构建配置对象(简化版,只传模型ID)
+ const config: KBModelConfigRequest = {
+ llmModelId: modelConfig.value.llmModelId,
+ embeddingModelId: modelConfig.value.embeddingModelId,
+ rerankModelId: modelConfig.value.rerankModelId || '',
+ vllmModelId: multimodalConfig.value.vllmModelId || '',
+ documentSplitting: {
+ chunkSize: chunkingConfig.value.chunkSize,
+ chunkOverlap: chunkingConfig.value.chunkOverlap,
+ separators: chunkingConfig.value.separators
+ },
+ multimodal: {
+ enabled: multimodalConfig.value.enabled,
+ storageType: multimodalConfig.value.enabled ? multimodalConfig.value.storageType : 'minio',
+ cos: multimodalConfig.value.enabled && multimodalConfig.value.storageType === 'cos' ? multimodalConfig.value.cos : undefined,
+ minio: multimodalConfig.value.enabled && multimodalConfig.value.storageType === 'minio' ? multimodalConfig.value.minio : undefined
+ },
+ nodeExtract: {
+ enabled: nodeExtractConfig.value.enabled,
+ text: nodeExtractConfig.value.text,
+ tags: nodeExtractConfig.value.tags,
+ nodes: [],
+ relations: []
+ }
+ }
+
+ // 保存配置
+ await updateKBConfig(kbId.value, config)
+ MessagePlugin.success('配置保存成功')
+ handleClose()
+ } catch (error) {
+ console.error('保存配置失败:', error)
+ MessagePlugin.error('保存配置失败')
+ } finally {
+ saving.value = false
+ }
+}
+
+// 处理关闭
+const handleClose = () => {
+ uiStore.closeKBSettings()
+ // 重置当前选中的section
+ setTimeout(() => {
+ currentSection.value = 'basic'
+ }, 300)
+}
+
+// 监听visible变化,当打开时加载数据
+watch(visible, (newVal) => {
+ if (newVal && kbId.value) {
+ loadKBData()
+ }
+})
+
+// 监听全局设置关闭事件,刷新模型列表
+watch(() => uiStore.showSettingsModal, (newVal, oldVal) => {
+ // 当全局设置从打开变为关闭,且知识库设置仍然打开时,刷新模型列表
+ if (oldVal && !newVal && visible.value) {
+ // 统一刷新所有模型列表(只调用一次API)
+ loadAllModels()
+ }
+})
+
+onMounted(() => {
+ if (visible.value && kbId.value) {
+ loadKBData()
+ }
+})
+</script>
+
+<style lang="less" scoped>
+/* 遮罩层 */
+.settings-overlay {
+ position: fixed;
+ inset: 0;
+ z-index: 999;
+ background: rgba(0, 0, 0, 0.4);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ padding: 20px;
+}
+
+/* 弹窗容器 */
+.settings-modal {
+ position: relative;
+ width: 100%;
+ max-width: 900px;
+ height: 700px;
+ background: var(--td-bg-color-container);
+ border-radius: 12px;
+ box-shadow: var(--td-shadow-3);
+ overflow: hidden;
+ display: flex;
+ flex-direction: column;
+}
+
+/* 关闭按钮 */
+.close-btn {
+ position: absolute;
+ top: 16px;
+ right: 16px;
+ width: 32px;
+ height: 32px;
+ border: none;
+ background: transparent;
+ color: var(--td-text-color-secondary);
+ cursor: pointer;
+ border-radius: 6px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ transition: all 0.2s ease;
+ z-index: 10;
+
+ &:hover {
+ background: var(--td-bg-color-container-hover);
+ color: var(--td-text-color-primary);
+ }
+}
+
+.settings-container {
+ display: flex;
+ height: 100%;
+ width: 100%;
+ overflow: hidden;
+}
+
+/* 左侧导航栏 */
+.settings-sidebar {
+ width: 220px;
+ background-color: var(--td-bg-color-secondarycontainer);
+ border-right: 1px solid var(--td-component-border);
+ flex-shrink: 0;
+ overflow-y: auto;
+ display: flex;
+ flex-direction: column;
+}
+
+.sidebar-header {
+ padding: 24px 16px 16px;
+ border-bottom: 1px solid var(--td-component-border);
+}
+
+.sidebar-title {
+ font-size: 18px;
+ font-weight: 600;
+ color: var(--td-text-color-primary);
+ margin: 0;
+}
+
+.settings-nav {
+ padding: 16px 8px;
+ flex: 1;
+}
+
+.nav-item {
+ display: flex;
+ align-items: center;
+ padding: 10px 16px;
+ margin-bottom: 4px;
+ border-radius: 6px;
+ cursor: pointer;
+ color: var(--td-text-color-secondary);
+ font-size: 14px;
+ transition: all 0.2s ease;
+ user-select: none;
+
+ &:hover {
+ background-color: var(--td-bg-color-container-hover);
+ color: var(--td-text-color-primary);
+ }
+
+ &.active {
+ background-color: var(--td-brand-color-light);
+ color: var(--td-brand-color);
+ font-weight: 500;
+ }
+}
+
+.nav-icon {
+ margin-right: 12px;
+ font-size: 16px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 20px;
+ height: 20px;
+}
+
+.nav-label {
+ flex: 1;
+}
+
+/* 右侧内容区域 */
+.settings-content {
+ flex: 1;
+ overflow-y: auto;
+ background-color: var(--td-bg-color-container);
+ display: flex;
+ flex-direction: column;
+}
+
+.content-wrapper {
+ flex: 1;
+ max-width: 600px;
+ padding: 40px 48px;
+ overflow-y: auto;
+}
+
+.section {
+ animation: fadeIn 0.3s ease;
+}
+
+@keyframes fadeIn {
+ from {
+ opacity: 0;
+ transform: translateY(10px);
+ }
+ to {
+ opacity: 1;
+ transform: translateY(0);
+ }
+}
+
+/* 底部保存按钮 */
+.settings-footer {
+ padding: 16px 48px;
+ border-top: 1px solid var(--td-component-border);
+ display: flex;
+ justify-content: flex-end;
+ gap: 12px;
+ background: var(--td-bg-color-container);
+}
+
+/* 弹窗动画 */
+.modal-enter-active,
+.modal-leave-active {
+ transition: opacity 0.2s ease;
+}
+
+.modal-enter-active .settings-modal,
+.modal-leave-active .settings-modal {
+ transition: transform 0.2s ease, opacity 0.2s ease;
+}
+
+.modal-enter-from,
+.modal-leave-to {
+ opacity: 0;
+}
+
+.modal-enter-from .settings-modal,
+.modal-leave-to .settings-modal {
+ transform: scale(0.95);
+ opacity: 0;
+}
+
+/* 滚动条样式 */
+.settings-sidebar::-webkit-scrollbar,
+.settings-content::-webkit-scrollbar,
+.content-wrapper::-webkit-scrollbar {
+ width: 6px;
+}
+
+.settings-sidebar::-webkit-scrollbar-track {
+ background: var(--td-bg-color-secondarycontainer);
+}
+
+.settings-sidebar::-webkit-scrollbar-thumb {
+ background: var(--td-bg-color-component);
+ border-radius: 3px;
+}
+
+.settings-sidebar::-webkit-scrollbar-thumb:hover {
+ background: var(--td-bg-color-component-hover);
+}
+
+.content-wrapper::-webkit-scrollbar-track {
+ background: var(--td-bg-color-container);
+}
+
+.content-wrapper::-webkit-scrollbar-thumb {
+ background: var(--td-bg-color-component);
+ border-radius: 3px;
+}
+
+.content-wrapper::-webkit-scrollbar-thumb:hover {
+ background: var(--td-bg-color-component-hover);
+}
+</style>
+
diff --git a/frontend/src/views/knowledge/settings/KBAdvancedSettings.vue b/frontend/src/views/knowledge/settings/KBAdvancedSettings.vue
new file mode 100644
index 000000000..90d8bd7eb
--- /dev/null
+++ b/frontend/src/views/knowledge/settings/KBAdvancedSettings.vue
@@ -0,0 +1,482 @@
+<template>
+ <div class="kb-advanced-settings">
+ <div class="section-header">
+ <h2>高级设置</h2>
+ <p class="section-description">配置多模态、知识图谱等高级功能</p>
+ </div>
+
+ <div class="settings-group">
+ <!-- 多模态功能 -->
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>多模态功能</label>
+ <p class="desc">启用图片、视频等多模态内容的理解能力</p>
+ </div>
+ <div class="setting-control">
+ <t-switch
+ v-model="localMultimodal.enabled"
+ @change="handleMultimodalToggle"
+ size="large"
+ />
+ </div>
+ </div>
+
+ <!-- 多模态存储配置 -->
+ <div v-if="localMultimodal.enabled" class="subsection">
+ <!-- VLLM 视觉模型 -->
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>VLLM 视觉模型 <span class="required">*</span></label>
+ <p class="desc">用于多模态理解的视觉语言模型(必选)</p>
+ </div>
+ <div class="setting-control">
+ <ModelSelector
+ ref="vllmSelectorRef"
+ model-type="VLLM"
+ :selected-model-id="localMultimodal.vllmModelId"
+ :all-models="allModels"
+ @update:selected-model-id="handleVLLMChange"
+ @add-model="handleAddModel('vllm')"
+ placeholder="请选择VLLM模型(必选)"
+ />
+ </div>
+ </div>
+
+ <div class="subsection-header">
+ <h4>存储配置 <span class="required">*</span></h4>
+ </div>
+
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>存储类型 <span class="required">*</span></label>
+ <p class="desc">选择多模态文件的存储方式(MinIO或腾讯云COS二选一)</p>
+ </div>
+ <div class="setting-control">
+ <t-radio-group v-model="localMultimodal.storageType" @change="handleStorageTypeChange">
+ <t-radio value="minio">MinIO</t-radio>
+ <t-radio value="cos">腾讯云COS</t-radio>
+ </t-radio-group>
+ </div>
+ </div>
+
+ <!-- MinIO配置 -->
+ <div v-if="localMultimodal.storageType === 'minio'" class="storage-config">
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>Bucket名称 <span class="required">*</span></label>
+ <p class="desc">MinIO存储桶名称(必填)</p>
+ </div>
+ <div class="setting-control">
+ <t-input
+ v-model="localMultimodal.minio.bucketName"
+ placeholder="请输入Bucket名称(必填)"
+ @change="handleConfigChange"
+ style="width: 280px;"
+ />
+ </div>
+ </div>
+
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>使用SSL</label>
+ <p class="desc">是否使用SSL连接</p>
+ </div>
+ <div class="setting-control">
+ <t-switch
+ v-model="localMultimodal.minio.useSSL"
+ @change="handleConfigChange"
+ size="large"
+ />
+ </div>
+ </div>
+
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>路径前缀</label>
+ <p class="desc">文件存储路径前缀(可选)</p>
+ </div>
+ <div class="setting-control">
+ <t-input
+ v-model="localMultimodal.minio.pathPrefix"
+ placeholder="请输入路径前缀"
+ @change="handleConfigChange"
+ style="width: 280px;"
+ />
+ </div>
+ </div>
+ </div>
+
+ <!-- COS配置 -->
+ <div v-if="localMultimodal.storageType === 'cos'" class="storage-config">
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>SecretId <span class="required">*</span></label>
+ <p class="desc">腾讯云API密钥ID(必填)</p>
+ </div>
+ <div class="setting-control">
+ <t-input
+ v-model="localMultimodal.cos.secretId"
+ placeholder="请输入SecretId(必填)"
+ @change="handleConfigChange"
+ style="width: 280px;"
+ />
+ </div>
+ </div>
+
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>SecretKey <span class="required">*</span></label>
+ <p class="desc">腾讯云API密钥Key(必填)</p>
+ </div>
+ <div class="setting-control">
+ <t-input
+ v-model="localMultimodal.cos.secretKey"
+ type="password"
+ placeholder="请输入SecretKey(必填)"
+ @change="handleConfigChange"
+ style="width: 280px;"
+ />
+ </div>
+ </div>
+
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>地域 <span class="required">*</span></label>
+ <p class="desc">COS存储桶所在地域(必填)</p>
+ </div>
+ <div class="setting-control">
+ <t-input
+ v-model="localMultimodal.cos.region"
+ placeholder="如:ap-guangzhou(必填)"
+ @change="handleConfigChange"
+ style="width: 280px;"
+ />
+ </div>
+ </div>
+
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>Bucket名称 <span class="required">*</span></label>
+ <p class="desc">COS存储桶名称(必填)</p>
+ </div>
+ <div class="setting-control">
+ <t-input
+ v-model="localMultimodal.cos.bucketName"
+ placeholder="请输入Bucket名称(必填)"
+ @change="handleConfigChange"
+ style="width: 280px;"
+ />
+ </div>
+ </div>
+
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>AppId <span class="required">*</span></label>
+ <p class="desc">腾讯云应用ID(必填)</p>
+ </div>
+ <div class="setting-control">
+ <t-input
+ v-model="localMultimodal.cos.appId"
+ placeholder="请输入AppId(必填)"
+ @change="handleConfigChange"
+ style="width: 280px;"
+ />
+ </div>
+ </div>
+
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>路径前缀</label>
+ <p class="desc">文件存储路径前缀(可选)</p>
+ </div>
+ <div class="setting-control">
+ <t-input
+ v-model="localMultimodal.cos.pathPrefix"
+ placeholder="请输入路径前缀"
+ @change="handleConfigChange"
+ style="width: 280px;"
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- 知识图谱提取 -->
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>知识图谱提取</label>
+ <p class="desc">从文档中自动提取实体和关系构建知识图谱</p>
+ </div>
+ <div class="setting-control">
+ <t-switch
+ v-model="localNodeExtract.enabled"
+ @change="handleNodeExtractToggle"
+ size="large"
+ />
+ </div>
+ </div>
+
+ <!-- 知识图谱配置 -->
+ <div v-if="localNodeExtract.enabled" class="subsection">
+ <div class="subsection-header">
+ <h4>图谱配置</h4>
+ </div>
+
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>提示文本</label>
+ <p class="desc">用于引导模型提取实体和关系的提示文本</p>
+ </div>
+ <div class="setting-control">
+ <t-textarea
+ v-model="localNodeExtract.text"
+ placeholder="请输入提示文本"
+ :autosize="{ minRows: 3, maxRows: 6 }"
+ @change="handleConfigChange"
+ style="width: 280px;"
+ />
+ </div>
+ </div>
+
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>标签</label>
+ <p class="desc">预定义的实体标签(多个标签用逗号分隔)</p>
+ </div>
+ <div class="setting-control">
+ <t-tag-input
+ v-model="localNodeExtract.tags"
+ placeholder="输入标签后按回车"
+ @change="handleConfigChange"
+ style="width: 280px;"
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { ref, watch } from 'vue'
+import ModelSelector from '@/components/ModelSelector.vue'
+import { useUIStore } from '@/stores/ui'
+
+const uiStore = useUIStore()
+
+interface MultimodalConfig {
+ enabled: boolean
+ storageType: 'minio' | 'cos'
+ vllmModelId?: string
+ minio: {
+ bucketName: string
+ useSSL: boolean
+ pathPrefix: string
+ }
+ cos: {
+ secretId: string
+ secretKey: string
+ region: string
+ bucketName: string
+ appId: string
+ pathPrefix: string
+ }
+}
+
+interface NodeExtractConfig {
+ enabled: boolean
+ text: string
+ tags: string[]
+}
+
+interface Props {
+ multimodal: MultimodalConfig
+ nodeExtract: NodeExtractConfig
+ allModels?: any[]
+}
+
+const props = defineProps<Props>()
+
+const emit = defineEmits<{
+ 'update:multimodal': [value: MultimodalConfig]
+ 'update:nodeExtract': [value: NodeExtractConfig]
+}>()
+
+const localMultimodal = ref<MultimodalConfig>({ ...props.multimodal })
+const localNodeExtract = ref<NodeExtractConfig>({ ...props.nodeExtract })
+
+const vllmSelectorRef = ref()
+
+// 监听props变化
+watch(() => props.multimodal, (newVal) => {
+ localMultimodal.value = { ...newVal }
+}, { deep: true })
+
+watch(() => props.nodeExtract, (newVal) => {
+ localNodeExtract.value = { ...newVal }
+}, { deep: true })
+
+// 处理多模态开关
+const handleMultimodalToggle = () => {
+ // 如果关闭多模态,清空相关配置
+ if (!localMultimodal.value.enabled) {
+ localMultimodal.value.vllmModelId = ''
+ localMultimodal.value.minio = {
+ bucketName: '',
+ useSSL: false,
+ pathPrefix: ''
+ }
+ localMultimodal.value.cos = {
+ secretId: '',
+ secretKey: '',
+ region: '',
+ bucketName: '',
+ appId: '',
+ pathPrefix: ''
+ }
+ }
+ emit('update:multimodal', localMultimodal.value)
+}
+
+// 处理存储类型变化
+const handleStorageTypeChange = () => {
+ emit('update:multimodal', localMultimodal.value)
+}
+
+// 处理VLLM模型变化
+const handleVLLMChange = (modelId: string) => {
+ localMultimodal.value.vllmModelId = modelId
+ emit('update:multimodal', localMultimodal.value)
+}
+
+// 处理添加模型
+const handleAddModel = (subSection: string) => {
+ uiStore.openSettings('models', subSection)
+}
+
+// 处理知识图谱开关
+const handleNodeExtractToggle = () => {
+ emit('update:nodeExtract', localNodeExtract.value)
+}
+
+// 处理配置变化
+const handleConfigChange = () => {
+ emit('update:multimodal', localMultimodal.value)
+ emit('update:nodeExtract', localNodeExtract.value)
+}
+
+// 由于使用了 allModels prop,不再需要单独刷新
+</script>
+
+<style lang="less" scoped>
+.kb-advanced-settings {
+ width: 100%;
+}
+
+.section-header {
+ margin-bottom: 32px;
+
+ h2 {
+ font-size: 20px;
+ font-weight: 600;
+ color: var(--td-text-color-primary);
+ margin: 0 0 8px 0;
+ }
+
+ .section-description {
+ font-size: 14px;
+ color: var(--td-text-color-secondary);
+ margin: 0;
+ line-height: 1.5;
+ }
+}
+
+.settings-group {
+ display: flex;
+ flex-direction: column;
+ gap: 0;
+}
+
+.setting-row {
+ display: flex;
+ align-items: flex-start;
+ justify-content: space-between;
+ padding: 20px 0;
+ border-bottom: 1px solid var(--td-component-border);
+
+ &:last-child {
+ border-bottom: none;
+ }
+}
+
+.setting-info {
+ flex: 1;
+ max-width: 65%;
+ padding-right: 24px;
+
+ label {
+ font-size: 15px;
+ font-weight: 500;
+ color: var(--td-text-color-primary);
+ display: block;
+ margin-bottom: 4px;
+ }
+
+ .desc {
+ font-size: 13px;
+ color: var(--td-text-color-secondary);
+ margin: 0;
+ line-height: 1.5;
+ }
+}
+
+.setting-control {
+ flex-shrink: 0;
+ min-width: 280px;
+ display: flex;
+ justify-content: flex-end;
+ align-items: center;
+}
+
+.subsection {
+ padding: 16px 20px;
+ margin: 12px 0 0 0;
+ background: var(--td-bg-color-secondarycontainer);
+ border-radius: 8px;
+ border-left: 3px solid var(--td-brand-color);
+ position: relative;
+}
+
+.subsection-header {
+ margin: 16px 0 8px 0;
+
+ &:first-child {
+ margin-top: 0;
+ }
+
+ h4 {
+ font-size: 15px;
+ font-weight: 600;
+ color: var(--td-text-color-primary);
+ margin: 0;
+ padding-left: 8px;
+ border-left: 2px solid var(--td-brand-color);
+
+ .required {
+ color: var(--td-error-color);
+ margin-left: 4px;
+ }
+ }
+}
+
+.required {
+ color: var(--td-error-color);
+ margin-left: 2px;
+ font-weight: 500;
+}
+
+.storage-config {
+ margin-top: 8px;
+}
+</style>
+
diff --git a/frontend/src/views/knowledge/settings/KBBasicInfo.vue b/frontend/src/views/knowledge/settings/KBBasicInfo.vue
new file mode 100644
index 000000000..1610061cd
--- /dev/null
+++ b/frontend/src/views/knowledge/settings/KBBasicInfo.vue
@@ -0,0 +1,198 @@
+<template>
+ <div class="kb-basic-info">
+ <div class="section-header">
+ <h2>基本信息</h2>
+ <p class="section-description">配置知识库的基本信息</p>
+ </div>
+
+ <div class="settings-group">
+ <!-- 知识库名称 -->
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>知识库名称 <span class="required">*</span></label>
+ <p class="desc">知识库的显示名称(最多50个字符)</p>
+ </div>
+ <div class="setting-control">
+ <t-input
+ v-model="localName"
+ placeholder="请输入知识库名称"
+ maxlength="50"
+ show-word-limit
+ @blur="handleNameChange"
+ style="width: 280px;"
+ />
+ </div>
+ </div>
+
+ <!-- 知识库描述 -->
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>知识库描述</label>
+ <p class="desc">知识库的详细描述信息(最多200个字符)</p>
+ </div>
+ <div class="setting-control">
+ <t-textarea
+ v-model="localDescription"
+ placeholder="请输入知识库描述"
+ maxlength="200"
+ show-word-limit
+ :autosize="{ minRows: 3, maxRows: 6 }"
+ @blur="handleDescriptionChange"
+ style="width: 280px;"
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { ref, watch } from 'vue'
+import { MessagePlugin } from 'tdesign-vue-next'
+import { updateKnowledgeBase } from '@/api/knowledge-base'
+
+interface Props {
+ kbId: string
+ name: string
+ description?: string
+}
+
+const props = defineProps<Props>()
+
+const emit = defineEmits<{
+ 'update:name': [value: string]
+ 'update:description': [value: string]
+}>()
+
+const localName = ref(props.name)
+const localDescription = ref(props.description || '')
+const saving = ref(false)
+
+// 监听props变化
+watch(() => props.name, (newVal) => {
+ localName.value = newVal
+})
+
+watch(() => props.description, (newVal) => {
+ localDescription.value = newVal || ''
+})
+
+// 保存基本信息
+const saveBasicInfo = async () => {
+ if (saving.value) return
+
+ if (!localName.value.trim()) {
+ MessagePlugin.warning('知识库名称不能为空')
+ return
+ }
+
+ saving.value = true
+ try {
+ await updateKnowledgeBase(props.kbId, {
+ name: localName.value,
+ description: localDescription.value,
+ config: {} // 这里只更新基本信息,不更新配置
+ })
+
+ emit('update:name', localName.value)
+ emit('update:description', localDescription.value)
+ MessagePlugin.success('保存成功')
+ } catch (error) {
+ console.error('保存知识库基本信息失败:', error)
+ MessagePlugin.error('保存失败')
+ } finally {
+ saving.value = false
+ }
+}
+
+// 处理名称变化
+const handleNameChange = () => {
+ if (localName.value !== props.name) {
+ saveBasicInfo()
+ }
+}
+
+// 处理描述变化
+const handleDescriptionChange = () => {
+ if (localDescription.value !== props.description) {
+ saveBasicInfo()
+ }
+}
+</script>
+
+<style lang="less" scoped>
+.kb-basic-info {
+ width: 100%;
+}
+
+.section-header {
+ margin-bottom: 32px;
+
+ h2 {
+ font-size: 20px;
+ font-weight: 600;
+ color: var(--td-text-color-primary);
+ margin: 0 0 8px 0;
+ }
+
+ .section-description {
+ font-size: 14px;
+ color: var(--td-text-color-secondary);
+ margin: 0;
+ line-height: 1.5;
+ }
+}
+
+.settings-group {
+ display: flex;
+ flex-direction: column;
+ gap: 0;
+}
+
+.setting-row {
+ display: flex;
+ align-items: flex-start;
+ justify-content: space-between;
+ padding: 20px 0;
+ border-bottom: 1px solid var(--td-component-border);
+
+ &:last-child {
+ border-bottom: none;
+ }
+}
+
+.setting-info {
+ flex: 1;
+ max-width: 65%;
+ padding-right: 24px;
+
+ label {
+ font-size: 15px;
+ font-weight: 500;
+ color: var(--td-text-color-primary);
+ display: block;
+ margin-bottom: 4px;
+
+ .required {
+ color: var(--td-error-color);
+ margin-left: 2px;
+ }
+ }
+
+ .desc {
+ font-size: 13px;
+ color: var(--td-text-color-secondary);
+ margin: 0;
+ line-height: 1.5;
+ }
+}
+
+.setting-control {
+ flex-shrink: 0;
+ min-width: 280px;
+ display: flex;
+ justify-content: flex-end;
+ align-items: center;
+}
+</style>
+
diff --git a/frontend/src/views/knowledge/settings/KBChunkingSettings.vue b/frontend/src/views/knowledge/settings/KBChunkingSettings.vue
new file mode 100644
index 000000000..7a7e978e3
--- /dev/null
+++ b/frontend/src/views/knowledge/settings/KBChunkingSettings.vue
@@ -0,0 +1,227 @@
+<template>
+ <div class="kb-chunking-settings">
+ <div class="section-header">
+ <h2>分块设置</h2>
+ <p class="section-description">配置文档分块参数,优化检索效果</p>
+ </div>
+
+ <div class="settings-group">
+ <!-- Chunk Size -->
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>分块大小</label>
+ <p class="desc">控制每个文档分块的字符数(100-4000)</p>
+ </div>
+ <div class="setting-control">
+ <div class="slider-container">
+ <t-slider
+ v-model="localChunkSize"
+ :min="100"
+ :max="4000"
+ :step="50"
+ :marks="{ 100: '100', 1000: '1000', 2000: '2000', 4000: '4000' }"
+ @change="handleChunkSizeChange"
+ style="width: 200px;"
+ />
+ <span class="value-display">{{ localChunkSize }} 字符</span>
+ </div>
+ </div>
+ </div>
+
+ <!-- Chunk Overlap -->
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>分块重叠</label>
+ <p class="desc">相邻文档块之间的重叠字符数(0-500)</p>
+ </div>
+ <div class="setting-control">
+ <div class="slider-container">
+ <t-slider
+ v-model="localChunkOverlap"
+ :min="0"
+ :max="500"
+ :step="20"
+ :marks="{ 0: '0', 250: '250', 500: '500' }"
+ @change="handleChunkOverlapChange"
+ style="width: 200px;"
+ />
+ <span class="value-display">{{ localChunkOverlap }} 字符</span>
+ </div>
+ </div>
+ </div>
+
+ <!-- 分隔符 -->
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>分隔符</label>
+ <p class="desc">文档分块时使用的分隔符</p>
+ </div>
+ <div class="setting-control">
+ <t-select
+ v-model="localSeparators"
+ :options="separatorOptions"
+ multiple
+ placeholder="选择分隔符"
+ @change="handleSeparatorsChange"
+ style="width: 280px;"
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { ref, watch } from 'vue'
+
+interface ChunkingConfig {
+ chunkSize: number
+ chunkOverlap: number
+ separators: string[]
+}
+
+interface Props {
+ config: ChunkingConfig
+}
+
+const props = defineProps<Props>()
+
+const emit = defineEmits<{
+ 'update:config': [value: ChunkingConfig]
+}>()
+
+const localChunkSize = ref(props.config.chunkSize)
+const localChunkOverlap = ref(props.config.chunkOverlap)
+const localSeparators = ref([...props.config.separators])
+
+// 分隔符选项
+const separatorOptions = [
+ { label: '双换行 (\\n\\n)', value: '\n\n' },
+ { label: '单换行 (\\n)', value: '\n' },
+ { label: '中文句号 (。)', value: '。' },
+ { label: '感叹号 (!)', value: '!' },
+ { label: '问号 (?)', value: '?' },
+ { label: '中文分号 (;)', value: ';' },
+ { label: '英文分号 (;)', value: ';' },
+ { label: '空格 ( )', value: ' ' }
+]
+
+// 监听props变化
+watch(() => props.config, (newConfig) => {
+ localChunkSize.value = newConfig.chunkSize
+ localChunkOverlap.value = newConfig.chunkOverlap
+ localSeparators.value = [...newConfig.separators]
+}, { deep: true })
+
+// 处理分块大小变化
+const handleChunkSizeChange = () => {
+ emitUpdate()
+}
+
+// 处理分块重叠变化
+const handleChunkOverlapChange = () => {
+ emitUpdate()
+}
+
+// 处理分隔符变化
+const handleSeparatorsChange = () => {
+ emitUpdate()
+}
+
+// 发出更新事件
+const emitUpdate = () => {
+ emit('update:config', {
+ chunkSize: localChunkSize.value,
+ chunkOverlap: localChunkOverlap.value,
+ separators: localSeparators.value
+ })
+}
+</script>
+
+<style lang="less" scoped>
+.kb-chunking-settings {
+ width: 100%;
+}
+
+.section-header {
+ margin-bottom: 32px;
+
+ h2 {
+ font-size: 20px;
+ font-weight: 600;
+ color: var(--td-text-color-primary);
+ margin: 0 0 8px 0;
+ }
+
+ .section-description {
+ font-size: 14px;
+ color: var(--td-text-color-secondary);
+ margin: 0;
+ line-height: 1.5;
+ }
+}
+
+.settings-group {
+ display: flex;
+ flex-direction: column;
+ gap: 0;
+}
+
+.setting-row {
+ display: flex;
+ align-items: flex-start;
+ justify-content: space-between;
+ padding: 20px 0;
+ border-bottom: 1px solid var(--td-component-border);
+
+ &:last-child {
+ border-bottom: none;
+ }
+}
+
+.setting-info {
+ flex: 1;
+ max-width: 65%;
+ padding-right: 24px;
+
+ label {
+ font-size: 15px;
+ font-weight: 500;
+ color: var(--td-text-color-primary);
+ display: block;
+ margin-bottom: 4px;
+ }
+
+ .desc {
+ font-size: 13px;
+ color: var(--td-text-color-secondary);
+ margin: 0;
+ line-height: 1.5;
+ }
+}
+
+.setting-control {
+ flex-shrink: 0;
+ min-width: 280px;
+ display: flex;
+ justify-content: flex-end;
+ align-items: center;
+}
+
+.slider-container {
+ display: flex;
+ align-items: center;
+ gap: 16px;
+ width: 100%;
+ justify-content: flex-end;
+}
+
+.value-display {
+ font-size: 14px;
+ color: var(--td-text-color-primary);
+ font-weight: 500;
+ min-width: 80px;
+ text-align: right;
+}
+</style>
+
diff --git a/frontend/src/views/knowledge/settings/KBModelConfig.vue b/frontend/src/views/knowledge/settings/KBModelConfig.vue
new file mode 100644
index 000000000..e81ae1780
--- /dev/null
+++ b/frontend/src/views/knowledge/settings/KBModelConfig.vue
@@ -0,0 +1,217 @@
+<template>
+ <div class="kb-model-config">
+ <div class="section-header">
+ <h2>模型配置</h2>
+ <p class="section-description">为知识库选择合适的AI模型</p>
+ </div>
+
+ <div class="settings-group">
+ <!-- LLM 大语言模型 -->
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>LLM 大语言模型 <span class="required">*</span></label>
+ <p class="desc">用于对话和问答的大语言模型</p>
+ </div>
+ <div class="setting-control">
+ <ModelSelector
+ ref="llmSelectorRef"
+ model-type="KnowledgeQA"
+ :selected-model-id="config.llmModelId"
+ :all-models="allModels"
+ @update:selected-model-id="handleLLMChange"
+ @add-model="handleAddModel('chat')"
+ placeholder="请选择LLM模型"
+ />
+ </div>
+ </div>
+
+ <!-- Embedding 嵌入模型 -->
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>Embedding 嵌入模型 <span class="required">*</span></label>
+ <p class="desc">用于文本向量化的嵌入模型</p>
+ <t-alert
+ v-if="hasFiles"
+ theme="warning"
+ message="知识库中已有文件,无法修改Embedding模型"
+ style="margin-top: 8px;"
+ />
+ </div>
+ <div class="setting-control">
+ <ModelSelector
+ ref="embeddingSelectorRef"
+ model-type="Embedding"
+ :selected-model-id="config.embeddingModelId"
+ :all-models="allModels"
+ :disabled="hasFiles"
+ @update:selected-model-id="handleEmbeddingChange"
+ @add-model="handleAddModel('embedding')"
+ placeholder="请选择Embedding模型"
+ />
+ </div>
+ </div>
+
+ <!-- ReRank 重排序模型 -->
+ <div class="setting-row">
+ <div class="setting-info">
+ <label>ReRank 重排序模型</label>
+ <p class="desc">用于搜索结果重排序的模型(可选)</p>
+ </div>
+ <div class="setting-control">
+ <ModelSelector
+ ref="rerankSelectorRef"
+ model-type="Rerank"
+ :selected-model-id="config.rerankModelId"
+ :all-models="allModels"
+ @update:selected-model-id="handleRerankChange"
+ @add-model="handleAddModel('rerank')"
+ placeholder="请选择ReRank模型(可选)"
+ />
+ </div>
+ </div>
+
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { ref } from 'vue'
+import { MessagePlugin } from 'tdesign-vue-next'
+import { useUIStore } from '@/stores/ui'
+import ModelSelector from '@/components/ModelSelector.vue'
+
+interface ModelConfig {
+ llmModelId?: string
+ embeddingModelId?: string
+ rerankModelId?: string
+ vllmModelId?: string
+}
+
+interface Props {
+ config: ModelConfig
+ hasFiles: boolean
+ allModels?: any[]
+}
+
+const props = defineProps<Props>()
+
+const emit = defineEmits<{
+ 'update:config': [value: ModelConfig]
+}>()
+
+const uiStore = useUIStore()
+
+// 引用各个模型选择器
+const llmSelectorRef = ref<InstanceType<typeof ModelSelector>>()
+const embeddingSelectorRef = ref<InstanceType<typeof ModelSelector>>()
+const rerankSelectorRef = ref<InstanceType<typeof ModelSelector>>()
+
+// 处理LLM模型变化
+const handleLLMChange = (modelId: string) => {
+ emit('update:config', {
+ ...props.config,
+ llmModelId: modelId
+ })
+}
+
+// 处理Embedding模型变化
+const handleEmbeddingChange = (modelId: string) => {
+ emit('update:config', {
+ ...props.config,
+ embeddingModelId: modelId
+ })
+}
+
+// 处理ReRank模型变化
+const handleRerankChange = (modelId: string) => {
+ emit('update:config', {
+ ...props.config,
+ rerankModelId: modelId
+ })
+}
+
+// 处理添加模型按钮点击
+const handleAddModel = (subSection: string) => {
+ // 打开全局设置对话框,并导航到对应的模型子页面
+ uiStore.openSettings('models', subSection)
+}
+
+// 由于使用了 allModels prop,不再需要单独刷新各个选择器
+</script>
+
+<style lang="less" scoped>
+.kb-model-config {
+ width: 100%;
+}
+
+.section-header {
+ margin-bottom: 32px;
+
+ h2 {
+ font-size: 20px;
+ font-weight: 600;
+ color: var(--td-text-color-primary);
+ margin: 0 0 8px 0;
+ }
+
+ .section-description {
+ font-size: 14px;
+ color: var(--td-text-color-secondary);
+ margin: 0;
+ line-height: 1.5;
+ }
+}
+
+.settings-group {
+ display: flex;
+ flex-direction: column;
+ gap: 0;
+}
+
+.setting-row {
+ display: flex;
+ align-items: flex-start;
+ justify-content: space-between;
+ padding: 20px 0;
+ border-bottom: 1px solid var(--td-component-border);
+
+ &:last-child {
+ border-bottom: none;
+ }
+}
+
+.setting-info {
+ flex: 1;
+ max-width: 65%;
+ padding-right: 24px;
+
+ label {
+ font-size: 15px;
+ font-weight: 500;
+ color: var(--td-text-color-primary);
+ display: block;
+ margin-bottom: 4px;
+
+ .required {
+ color: var(--td-error-color);
+ margin-left: 2px;
+ }
+ }
+
+ .desc {
+ font-size: 13px;
+ color: var(--td-text-color-secondary);
+ margin: 0;
+ line-height: 1.5;
+ }
+}
+
+.setting-control {
+ flex-shrink: 0;
+ min-width: 280px;
+ display: flex;
+ justify-content: flex-end;
+ align-items: flex-start;
+}
+</style>
+
diff --git a/frontend/src/views/settings/AgentSettings.vue b/frontend/src/views/settings/AgentSettings.vue
index 63402b561..c9793136b 100644
--- a/frontend/src/views/settings/AgentSettings.vue
+++ b/frontend/src/views/settings/AgentSettings.vue
@@ -57,7 +57,7 @@
filterable
placeholder="搜索模型..."
@change="handleThinkingModelChange"
- @focus="loadChatModels"
+ @focus="loadAllModels"
style="width: 280px;"
>
<!-- 已有的对话模型 -->
@@ -98,7 +98,7 @@
filterable
placeholder="搜索模型..."
@change="handleRerankModelChange"
- @focus="loadRerankModels"
+ @focus="loadAllModels"
style="width: 280px;"
>
<!-- 已有的 Rerank 模型 -->
@@ -209,16 +209,24 @@ const availableTools = ref<ToolDefinition[]>([])
// 配置加载状态
const loadingConfig = ref(false)
+const configLoaded = ref(false) // 防止重复加载
+const isInitializing = ref(true) // 标记是否正在初始化,防止初始化时触发保存
// 初始化加载
onMounted(async () => {
+ // 防止重复加载
+ if (configLoaded.value) return
+
loadingConfig.value = true
+ configLoaded.value = true
+ isInitializing.value = true
+
try {
// 从后台加载配置
const res = await getAgentConfig()
const config = res.data
- // 更新本地状态
+ // 更新本地状态(在初始化期间,不会触发保存)
localAgentEnabled.value = config.enabled
localMaxIterations.value = config.max_iterations
localTemperature.value = config.temperature
@@ -227,17 +235,12 @@ onMounted(async () => {
localAllowedTools.value = config.allowed_tools || []
availableTools.value = config.available_tools || []
- // 如果配置了思考模型,立即加载模型列表以显示模型名称
- if (config.thinking_model_id) {
- await loadChatModels()
- }
-
- // 如果配置了 rerank 模型,立即加载模型列表以显示模型名称
- if (config.rerank_model_id) {
- await loadRerankModels()
+ // 统一加载所有模型(只调用一次API)
+ if (config.thinking_model_id || config.rerank_model_id) {
+ await loadAllModels()
}
- // 同步到store
+ // 同步到store(只更新本地存储,不触发API保存)
settingsStore.toggleAgent(config.enabled)
settingsStore.updateAgentConfig({
maxIterations: config.max_iterations,
@@ -245,9 +248,13 @@ onMounted(async () => {
thinkingModelId: config.thinking_model_id,
rerankModelId: config.rerank_model_id
})
+
+ // 初始化完成
+ isInitializing.value = false
} catch (error) {
console.error('加载Agent配置失败:', error)
MessagePlugin.error('加载Agent配置失败')
+ configLoaded.value = false // 加载失败时重置标记,允许重试
// 失败时从store加载
localAgentEnabled.value = settingsStore.isAgentEnabled
@@ -257,6 +264,7 @@ onMounted(async () => {
localRerankModelId.value = settingsStore.agentConfig.rerankModelId
} finally {
loadingConfig.value = false
+ isInitializing.value = false // 确保初始化完成,即使失败也要允许后续操作
}
})
@@ -283,6 +291,11 @@ const getErrorMessage = (error: any): string => {
// 处理 Agent 开关
const handleAgentToggle = async (value: boolean) => {
+ // 如果正在初始化,不触发保存(但用户手动切换开关应该允许)
+ // 注意:这个可能不需要检查,因为用户手动切换开关应该保存
+ // 但为了安全,如果初始化时开关状态变化,也不保存
+ if (isInitializing.value) return
+
try {
// 构建完整配置
const config: AgentConfig = {
@@ -308,6 +321,9 @@ const handleAgentToggle = async (value: boolean) => {
// 处理最大迭代次数变化
const handleMaxIterationsChange = async (value: number) => {
+ // 如果正在初始化,不触发保存
+ if (isInitializing.value) return
+
try {
const config: AgentConfig = {
enabled: localAgentEnabled.value,
@@ -328,40 +344,39 @@ const handleMaxIterationsChange = async (value: number) => {
}
}
-// 加载对话模型列表
-const loadChatModels = async () => {
- if (chatModels.value.length > 0) return // 已经加载过
+// 统一加载所有模型(只调用一次API)
+const loadAllModels = async () => {
+ if (chatModels.value.length > 0 && rerankModels.value.length > 0) return // 已经加载过
loadingModels.value = true
try {
const allModels = await listModels()
- // 只获取对话模型(KnowledgeQA 类型)
+ // 按类型过滤,避免重复调用
chatModels.value = allModels.filter(m => m.type === 'KnowledgeQA')
+ rerankModels.value = allModels.filter(m => m.type === 'Rerank')
} catch (error) {
+ console.error('加载模型列表失败:', error)
MessagePlugin.error('加载模型列表失败')
} finally {
loadingModels.value = false
}
}
-// 加载 Rerank 模型列表
+// 加载对话模型列表(已废弃,使用 loadAllModels)
+const loadChatModels = async () => {
+ await loadAllModels()
+}
+
+// 加载 Rerank 模型列表(已废弃,使用 loadAllModels)
const loadRerankModels = async () => {
- if (rerankModels.value.length > 0) return // 已经加载过
-
- loadingModels.value = true
- try {
- const allModels = await listModels()
- rerankModels.value = allModels.filter(m => m.type === 'Rerank')
- } catch (error) {
- console.error('加载 Rerank 模型列表失败:', error)
- MessagePlugin.error('加载 Rerank 模型列表失败')
- } finally {
- loadingModels.value = false
- }
+ await loadAllModels()
}
// 处理思考模型变化
const handleThinkingModelChange = async (value: string) => {
+ // 如果正在初始化,不触发保存
+ if (isInitializing.value) return
+
// 如果选择添加新模型,跳转到模型配置页
if (value === '__add_model__') {
router.push('/settings?section=models')
@@ -391,6 +406,9 @@ const handleThinkingModelChange = async (value: string) => {
// 监听模型选择,处理"添加模型"跳转
// 处理 Rerank 模型变化
const handleRerankModelChange = async (value: string) => {
+ // 如果正在初始化,不触发保存
+ if (isInitializing.value) return
+
// 如果选择添加新模型,跳转到模型配置页
if (value === '__add_model__') {
router.push('/settings?section=models&subsection=rerank')
@@ -474,6 +492,9 @@ watch(() => localRerankModelId.value, (newValue) => {
// 处理温度参数变化
const handleTemperatureChange = async (value: number) => {
+ // 如果正在初始化,不触发保存
+ if (isInitializing.value) return
+
try {
const config: AgentConfig = {
enabled: localAgentEnabled.value,
@@ -496,6 +517,9 @@ const handleTemperatureChange = async (value: number) => {
// 处理允许工具变化
const handleAllowedToolsChange = async (value: string[]) => {
+ // 如果正在初始化,不触发保存
+ if (isInitializing.value) return
+
try {
const config: AgentConfig = {
enabled: localAgentEnabled.value,
@@ -530,13 +554,13 @@ const handleAllowedToolsChange = async (value: string[]) => {
h2 {
font-size: 20px;
font-weight: 600;
- color: #333333;
+ color: var(--td-text-color-primary);
margin: 0 0 8px 0;
}
.section-description {
font-size: 14px;
- color: #666666;
+ color: var(--td-text-color-secondary);
margin: 0;
line-height: 1.5;
}
@@ -553,7 +577,7 @@ const handleAllowedToolsChange = async (value: string[]) => {
align-items: flex-start;
justify-content: space-between;
padding: 20px 0;
- border-bottom: 1px solid #e5e7eb;
+ border-bottom: 1px solid var(--td-component-border);
&:last-child {
border-bottom: none;
@@ -582,14 +606,14 @@ const handleAllowedToolsChange = async (value: string[]) => {
label {
font-size: 15px;
font-weight: 500;
- color: #333333;
+ color: var(--td-text-color-primary);
display: block;
margin-bottom: 4px;
}
.desc {
font-size: 13px;
- color: #666666;
+ color: var(--td-text-color-secondary);
margin: 0;
line-height: 1.5;
}
@@ -613,7 +637,7 @@ const handleAllowedToolsChange = async (value: string[]) => {
.value-display {
font-size: 14px;
font-weight: 500;
- color: #333333;
+ color: var(--td-text-color-primary);
min-width: 40px;
text-align: right;
}
@@ -627,12 +651,12 @@ const handleAllowedToolsChange = async (value: string[]) => {
.model-icon {
font-size: 14px;
- color: #07C05F;
+ color: var(--td-brand-color);
}
.add-icon {
font-size: 14px;
- color: #07C05F;
+ color: var(--td-brand-color);
}
.model-name {
@@ -642,7 +666,7 @@ const handleAllowedToolsChange = async (value: string[]) => {
&.add {
.model-name {
- color: #07C05F;
+ color: var(--td-brand-color);
font-weight: 500;
}
}
diff --git a/frontend/src/views/settings/GeneralSettings.vue b/frontend/src/views/settings/GeneralSettings.vue
index c2330b15f..757b8ff33 100644
--- a/frontend/src/views/settings/GeneralSettings.vue
+++ b/frontend/src/views/settings/GeneralSettings.vue
@@ -48,8 +48,11 @@
</template>
<script setup lang="ts">
-import { ref, onMounted } from 'vue'
+import { ref, onMounted, watch } from 'vue'
import { MessagePlugin } from 'tdesign-vue-next'
+import { useUIStore } from '@/stores/ui'
+
+const uiStore = useUIStore()
// 本地状态
const localLanguage = ref('zh-CN')
@@ -68,6 +71,13 @@ onMounted(() => {
console.error('加载常规设置失败:', e)
}
}
+ // 同步 store 的主题状态
+ localTheme.value = uiStore.theme
+})
+
+// 监听 store 的主题变化,同步到本地状态
+watch(() => uiStore.theme, (newTheme) => {
+ localTheme.value = newTheme
})
// 保存设置到 localStorage
@@ -88,9 +98,8 @@ const handleLanguageChange = () => {
// 处理主题变化
const handleThemeChange = () => {
- saveSettings()
+ uiStore.setTheme(localTheme.value as 'light' | 'dark')
MessagePlugin.success('主题设置已保存')
- // TODO: 实际的主题切换逻辑可后续添加
}
</script>
@@ -105,13 +114,13 @@ const handleThemeChange = () => {
h2 {
font-size: 20px;
font-weight: 600;
- color: #333333;
+ color: var(--td-text-color-primary);
margin: 0 0 8px 0;
}
.section-description {
font-size: 14px;
- color: #666666;
+ color: var(--td-text-color-secondary);
margin: 0;
line-height: 1.5;
}
@@ -128,7 +137,7 @@ const handleThemeChange = () => {
align-items: flex-start;
justify-content: space-between;
padding: 20px 0;
- border-bottom: 1px solid #e5e7eb;
+ border-bottom: 1px solid var(--td-component-border);
&:last-child {
border-bottom: none;
@@ -143,14 +152,14 @@ const handleThemeChange = () => {
label {
font-size: 15px;
font-weight: 500;
- color: #333333;
+ color: var(--td-text-color-primary);
display: block;
margin-bottom: 4px;
}
.desc {
font-size: 13px;
- color: #666666;
+ color: var(--td-text-color-secondary);
margin: 0;
line-height: 1.5;
}
diff --git a/frontend/src/views/settings/KnowledgeBaseSettings.vue b/frontend/src/views/settings/KnowledgeBaseSettings.vue
index f2043863c..3c355328e 100644
--- a/frontend/src/views/settings/KnowledgeBaseSettings.vue
+++ b/frontend/src/views/settings/KnowledgeBaseSettings.vue
@@ -138,13 +138,13 @@ const handleLanguageDetectionChange = () => {
h2 {
font-size: 20px;
font-weight: 600;
- color: #333333;
+ color: var(--td-text-color-primary);
margin: 0 0 8px 0;
}
.section-description {
font-size: 14px;
- color: #666666;
+ color: var(--td-text-color-secondary);
margin: 0;
line-height: 1.5;
}
@@ -161,7 +161,7 @@ const handleLanguageDetectionChange = () => {
align-items: flex-start;
justify-content: space-between;
padding: 20px 0;
- border-bottom: 1px solid #e5e7eb;
+ border-bottom: 1px solid var(--td-component-border);
&:last-child {
border-bottom: none;
@@ -176,14 +176,14 @@ const handleLanguageDetectionChange = () => {
label {
font-size: 15px;
font-weight: 500;
- color: #333333;
+ color: var(--td-text-color-primary);
display: block;
margin-bottom: 4px;
}
.desc {
font-size: 13px;
- color: #666666;
+ color: var(--td-text-color-secondary);
margin: 0;
line-height: 1.5;
}
@@ -207,7 +207,7 @@ const handleLanguageDetectionChange = () => {
.value-display {
font-size: 14px;
font-weight: 500;
- color: #333333;
+ color: var(--td-text-color-primary);
min-width: 40px;
text-align: right;
}
diff --git a/frontend/src/views/settings/ModelSettings.vue b/frontend/src/views/settings/ModelSettings.vue
index 309244550..8945465c0 100644
--- a/frontend/src/views/settings/ModelSettings.vue
+++ b/frontend/src/views/settings/ModelSettings.vue
@@ -466,13 +466,13 @@ onMounted(() => {
h2 {
font-size: 20px;
font-weight: 600;
- color: #333333;
+ color: var(--td-text-color-primary);
margin: 0 0 8px 0;
}
.section-description {
font-size: 14px;
- color: #666666;
+ color: var(--td-text-color-secondary);
margin: 0;
line-height: 1.5;
}
@@ -480,10 +480,10 @@ onMounted(() => {
.model-category-section {
margin-bottom: 24px;
- border: 1px solid #e5e7eb;
+ border: 1px solid var(--td-component-border);
border-radius: 8px;
padding: 24px;
- background: #ffffff;
+ background: var(--td-bg-color-container);
&:last-child {
margin-bottom: 0;
@@ -502,13 +502,13 @@ onMounted(() => {
h3 {
font-size: 16px;
font-weight: 600;
- color: #333333;
+ color: var(--td-text-color-primary);
margin: 0 0 4px 0;
}
p {
font-size: 14px;
- color: #666666;
+ color: var(--td-text-color-secondary);
margin: 0;
line-height: 1.5;
}
@@ -543,16 +543,16 @@ onMounted(() => {
align-items: center;
justify-content: space-between;
padding: 10px 12px;
- border: 1px solid #e5e7eb;
+ border: 1px solid var(--td-component-border);
border-radius: 6px;
- background: #fafafa;
+ background: var(--td-bg-color-secondarycontainer);
transition: all 0.2s;
position: relative;
overflow: visible;
&:hover {
- border-color: #07C05F;
- background: #ffffff;
+ border-color: var(--td-brand-color);
+ background: var(--td-bg-color-container);
}
}
@@ -563,7 +563,7 @@ onMounted(() => {
.model-name {
font-size: 14px;
font-weight: 500;
- color: #333333;
+ color: var(--td-text-color-primary);
margin-bottom: 4px;
display: flex;
align-items: center;
@@ -575,22 +575,22 @@ onMounted(() => {
align-items: center;
gap: 10px;
font-size: 12px;
- color: #666666;
+ color: var(--td-text-color-secondary);
.source-tag {
padding: 1px 6px;
- background: #e5e7eb;
+ background: var(--td-bg-color-component);
border-radius: 3px;
font-size: 11px;
}
.model-id {
font-family: monospace;
- color: #666666;
+ color: var(--td-text-color-secondary);
}
.dimension {
- color: #999999;
+ color: var(--td-text-color-placeholder);
}
}
}
@@ -606,12 +606,12 @@ onMounted(() => {
z-index: 1001; // 确保高于设置窗口的z-index (9999)
.more-btn {
- color: #666666;
+ color: var(--td-text-color-secondary);
padding: 4px;
&:hover {
- background: #f5f7fa;
- color: #333333;
+ background: var(--td-bg-color-component-hover);
+ color: var(--td-text-color-primary);
}
}
}
@@ -626,7 +626,7 @@ onMounted(() => {
.empty-text {
font-size: 14px;
- color: #999999;
+ color: var(--td-text-color-placeholder);
margin: 0 0 16px 0;
}
}
diff --git a/frontend/src/views/settings/OllamaSettings.vue b/frontend/src/views/settings/OllamaSettings.vue
index 7d3bfe54a..b99e36b55 100644
--- a/frontend/src/views/settings/OllamaSettings.vue
+++ b/frontend/src/views/settings/OllamaSettings.vue
@@ -355,23 +355,30 @@ const initOllamaBaseUrl = async () => {
// 如果接口没返回且 store 中也没有,使用默认值
localBaseUrl.value = 'http://localhost:11434'
}
+
+ // 如果启用了,直接使用初始化时获取的状态,避免重复调用
+ if (localEnabled.value) {
+ connectionStatus.value = result.available
+ if (result.available) {
+ refreshModels()
+ }
+ }
+
+ return result
} catch (error) {
console.error('初始化 Ollama 地址失败:', error)
// 如果获取失败,使用默认值或 store 中的值
if (!localBaseUrl.value) {
localBaseUrl.value = 'http://localhost:11434'
}
+ return null
}
}
// 组件挂载时自动检查连接
onMounted(async () => {
- // 先初始化服务地址
+ // 初始化服务地址,如果启用则直接使用返回的状态,避免重复调用
await initOllamaBaseUrl()
-
- if (localEnabled.value) {
- testConnection()
- }
})
</script>
@@ -386,13 +393,13 @@ onMounted(async () => {
h2 {
font-size: 20px;
font-weight: 600;
- color: #333333;
+ color: var(--td-text-color-primary);
margin: 0 0 8px 0;
}
.section-description {
font-size: 14px;
- color: #666666;
+ color: var(--td-text-color-secondary);
margin: 0;
line-height: 1.5;
}
@@ -409,7 +416,7 @@ onMounted(async () => {
align-items: flex-start;
justify-content: space-between;
padding: 20px 0;
- border-bottom: 1px solid #e5e7eb;
+ border-bottom: 1px solid var(--td-component-border);
&:last-child {
border-bottom: none;
@@ -424,14 +431,14 @@ onMounted(async () => {
label {
font-size: 15px;
font-weight: 500;
- color: #333333;
+ color: var(--td-text-color-primary);
display: block;
margin-bottom: 4px;
}
.desc {
font-size: 13px;
- color: #666666;
+ color: var(--td-text-color-secondary);
margin: 0;
line-height: 1.5;
}
@@ -460,11 +467,11 @@ onMounted(async () => {
font-size: 18px;
&.success {
- color: #07C05F;
+ color: var(--td-success-color);
}
&.error {
- color: #e34d59;
+ color: var(--td-error-color);
}
&.spinning {
@@ -476,10 +483,10 @@ onMounted(async () => {
.model-category-section {
margin-bottom: 24px;
- border: 1px solid #e5e7eb;
+ border: 1px solid var(--td-component-border);
border-radius: 8px;
padding: 24px;
- background: #ffffff;
+ background: var(--td-bg-color-container);
&:last-child {
margin-bottom: 0;
@@ -498,13 +505,13 @@ onMounted(async () => {
h3 {
font-size: 16px;
font-weight: 600;
- color: #333333;
+ color: var(--td-text-color-primary);
margin: 0 0 4px 0;
}
p {
font-size: 14px;
- color: #666666;
+ color: var(--td-text-color-secondary);
margin: 0;
line-height: 1.5;
}
@@ -517,7 +524,7 @@ onMounted(async () => {
justify-content: center;
gap: 8px;
padding: 60px;
- color: #666666;
+ color: var(--td-text-color-secondary);
font-size: 14px;
}
@@ -536,14 +543,14 @@ onMounted(async () => {
align-items: center;
justify-content: space-between;
padding: 10px 12px;
- border: 1px solid #e5e7eb;
+ border: 1px solid var(--td-component-border);
border-radius: 6px;
- background: #fafafa;
+ background: var(--td-bg-color-secondarycontainer);
transition: all 0.2s;
&:hover {
- border-color: #07C05F;
- background: #ffffff;
+ border-color: var(--td-brand-color);
+ background: var(--td-bg-color-container);
}
}
@@ -554,7 +561,7 @@ onMounted(async () => {
.model-name {
font-size: 14px;
font-weight: 500;
- color: #333333;
+ color: var(--td-text-color-primary);
margin-bottom: 4px;
font-family: monospace;
}
@@ -563,7 +570,7 @@ onMounted(async () => {
display: flex;
gap: 12px;
font-size: 12px;
- color: #666666;
+ color: var(--td-text-color-secondary);
}
}
@@ -579,7 +586,7 @@ onMounted(async () => {
.download-progress {
padding: 12px;
- background: #f5f7fa;
+ background: var(--td-bg-color-component);
border-radius: 6px;
.progress-info {
@@ -587,14 +594,14 @@ onMounted(async () => {
justify-content: space-between;
margin-bottom: 8px;
font-size: 13px;
- color: #333333;
+ color: var(--td-text-color-primary);
}
}
.recommended-models {
.recommended-label {
font-size: 13px;
- color: #666666;
+ color: var(--td-text-color-secondary);
margin: 0 0 10px 0;
font-weight: 500;
}
@@ -610,9 +617,9 @@ onMounted(async () => {
font-size: 12px;
&:hover {
- background: #07C05F;
- color: #ffffff;
- border-color: #07C05F;
+ background: var(--td-brand-color);
+ color: var(--td-text-color-anti);
+ border-color: var(--td-brand-color);
}
}
}
@@ -625,7 +632,7 @@ onMounted(async () => {
.empty-text {
font-size: 14px;
- color: #999999;
+ color: var(--td-text-color-placeholder);
margin: 0;
}
}
diff --git a/frontend/src/views/settings/Settings.vue b/frontend/src/views/settings/Settings.vue
index fe5116724..f706310e3 100644
--- a/frontend/src/views/settings/Settings.vue
+++ b/frontend/src/views/settings/Settings.vue
@@ -59,32 +59,32 @@
<div class="settings-content">
<div class="content-wrapper">
<!-- 常规设置 -->
- <div v-show="currentSection === 'general'" class="section">
+ <div v-if="currentSection === 'general'" class="section">
<GeneralSettings />
</div>
<!-- 模型配置 -->
- <div v-show="currentSection === 'models'" class="section">
+ <div v-if="currentSection === 'models'" class="section">
<ModelSettings />
</div>
<!-- Ollama 设置 -->
- <div v-show="currentSection === 'ollama'" class="section">
+ <div v-if="currentSection === 'ollama'" class="section">
<OllamaSettings />
</div>
<!-- 知识库设置 -->
- <div v-show="currentSection === 'knowledge'" class="section">
+ <div v-if="currentSection === 'knowledge'" class="section">
<KnowledgeBaseSettings />
</div>
<!-- Agent 配置 -->
- <div v-show="currentSection === 'agent'" class="section">
+ <div v-if="currentSection === 'agent'" class="section">
<AgentSettings />
</div>
<!-- 系统信息 -->
- <div v-show="currentSection === 'system'" class="section">
+ <div v-if="currentSection === 'system'" class="section">
<SystemInfo />
</div>
</div>
@@ -179,6 +179,27 @@ const handleClose = () => {
}
}
+// 监听初始导航设置
+watch(() => uiStore.settingsInitialSection, (section) => {
+ if (section && visible.value) {
+ currentSection.value = section
+ if (uiStore.settingsInitialSubSection) {
+ currentSubSection.value = uiStore.settingsInitialSubSection
+ // 展开对应的父菜单
+ if (!expandedMenus.value.includes(section)) {
+ expandedMenus.value.push(section)
+ }
+ // 滚动到对应区域
+ setTimeout(() => {
+ const element = document.querySelector(`[data-model-type="${uiStore.settingsInitialSubSection}"]`)
+ if (element) {
+ element.scrollIntoView({ behavior: 'smooth', block: 'start' })
+ }
+ }, 300)
+ }
+ }
+}, { immediate: true })
+
// ESC 键关闭
const handleEscape = (e: KeyboardEvent) => {
if (e.key === 'Escape' && visible.value) {
@@ -221,7 +242,7 @@ onUnmounted(() => {
.settings-overlay {
position: fixed;
inset: 0;
- z-index: 999;
+ z-index: 1000;
background: transparent;
display: flex;
align-items: center;
@@ -235,9 +256,9 @@ onUnmounted(() => {
width: 100%;
max-width: 900px;
height: 700px;
- background: #ffffff;
+ background: var(--td-bg-color-container);
border-radius: 12px;
- box-shadow: 0 6px 28px rgba(15, 23, 42, 0.08);
+ box-shadow: var(--td-shadow-3);
overflow: hidden;
display: flex;
flex-direction: column;
@@ -252,7 +273,7 @@ onUnmounted(() => {
height: 32px;
border: none;
background: transparent;
- color: #666666;
+ color: var(--td-text-color-secondary);
cursor: pointer;
border-radius: 6px;
display: flex;
@@ -262,8 +283,8 @@ onUnmounted(() => {
z-index: 10;
&:hover {
- background: #f5f5f5;
- color: #333333;
+ background: var(--td-bg-color-container-hover);
+ color: var(--td-text-color-primary);
}
}
@@ -277,8 +298,8 @@ onUnmounted(() => {
/* 左侧导航栏 */
.settings-sidebar {
width: 220px;
- background-color: #f8f9fa;
- border-right: 1px solid #e5e7eb;
+ background-color: var(--td-bg-color-secondarycontainer);
+ border-right: 1px solid var(--td-component-border);
flex-shrink: 0;
overflow-y: auto;
display: flex;
@@ -287,13 +308,13 @@ onUnmounted(() => {
.sidebar-header {
padding: 24px 16px 16px;
- border-bottom: 1px solid #e5e7eb;
+ border-bottom: 1px solid var(--td-component-border);
}
.sidebar-title {
font-size: 18px;
font-weight: 600;
- color: #333333;
+ color: var(--td-text-color-primary);
margin: 0;
}
@@ -309,19 +330,19 @@ onUnmounted(() => {
margin-bottom: 4px;
border-radius: 6px;
cursor: pointer;
- color: #666666;
+ color: var(--td-text-color-secondary);
font-size: 14px;
transition: all 0.2s ease;
user-select: none;
&:hover {
- background-color: #e8f5ed;
- color: #333333;
+ background-color: var(--td-bg-color-container-hover);
+ color: var(--td-text-color-primary);
}
&.active {
- background-color: rgba(7, 192, 95, 0.1);
- color: #07C05F;
+ background-color: var(--td-brand-color-light);
+ color: var(--td-brand-color);
font-weight: 500;
}
}
@@ -358,19 +379,19 @@ onUnmounted(() => {
margin-bottom: 2px;
border-radius: 4px;
cursor: pointer;
- color: #666666;
+ color: var(--td-text-color-secondary);
font-size: 13px;
transition: all 0.2s ease;
user-select: none;
&:hover {
- background-color: #f5f7fa;
- color: #333333;
+ background-color: var(--td-bg-color-component-hover);
+ color: var(--td-text-color-primary);
}
&.active {
- background-color: rgba(7, 192, 95, 0.08);
- color: #07C05F;
+ background-color: var(--td-brand-color-light);
+ color: var(--td-brand-color);
font-weight: 500;
}
}
@@ -409,7 +430,7 @@ onUnmounted(() => {
.settings-content {
flex: 1;
overflow-y: auto;
- background-color: #ffffff;
+ background-color: var(--td-bg-color-container);
}
.content-wrapper {
@@ -461,29 +482,29 @@ onUnmounted(() => {
}
.settings-sidebar::-webkit-scrollbar-track {
- background: #f8f9fa;
+ background: var(--td-bg-color-secondarycontainer);
}
.settings-sidebar::-webkit-scrollbar-thumb {
- background: #d0d0d0;
+ background: var(--td-bg-color-component);
border-radius: 3px;
}
.settings-sidebar::-webkit-scrollbar-thumb:hover {
- background: #b0b0b0;
+ background: var(--td-bg-color-component-hover);
}
.settings-content::-webkit-scrollbar-track {
- background: #ffffff;
+ background: var(--td-bg-color-container);
}
.settings-content::-webkit-scrollbar-thumb {
- background: #d0d0d0;
+ background: var(--td-bg-color-component);
border-radius: 3px;
}
.settings-content::-webkit-scrollbar-thumb:hover {
- background: #b0b0b0;
+ background: var(--td-bg-color-component-hover);
}
</style>
diff --git a/frontend/src/views/settings/SystemInfo.vue b/frontend/src/views/settings/SystemInfo.vue
index 258e9b962..0b4878f70 100644
--- a/frontend/src/views/settings/SystemInfo.vue
+++ b/frontend/src/views/settings/SystemInfo.vue
@@ -411,13 +411,13 @@ onMounted(() => {
h2 {
font-size: 20px;
font-weight: 600;
- color: #333333;
+ color: var(--td-text-color-primary);
margin: 0 0 8px 0;
}
.section-description {
font-size: 14px;
- color: #666666;
+ color: var(--td-text-color-secondary);
margin: 0;
line-height: 1.5;
}
@@ -429,7 +429,7 @@ onMounted(() => {
gap: 12px;
padding: 40px 0;
justify-content: center;
- color: #666666;
+ color: var(--td-text-color-secondary);
font-size: 14px;
}
@@ -448,7 +448,7 @@ onMounted(() => {
align-items: flex-start;
justify-content: space-between;
padding: 20px 0;
- border-bottom: 1px solid #e5e7eb;
+ border-bottom: 1px solid var(--td-component-border);
&:last-child {
border-bottom: none;
@@ -463,14 +463,14 @@ onMounted(() => {
label {
font-size: 15px;
font-weight: 500;
- color: #333333;
+ color: var(--td-text-color-primary);
display: block;
margin-bottom: 4px;
}
.desc {
font-size: 13px;
- color: #666666;
+ color: var(--td-text-color-secondary);
margin: 0;
line-height: 1.5;
}
@@ -485,12 +485,12 @@ onMounted(() => {
.info-value {
font-size: 14px;
- color: #333333;
+ color: var(--td-text-color-primary);
text-align: right;
word-break: break-word;
.commit-info {
- color: #999999;
+ color: var(--td-text-color-placeholder);
font-size: 12px;
margin-left: 6px;
}
@@ -512,8 +512,8 @@ onMounted(() => {
.usage-text {
font-size: 14px;
- font-weight: 500;
- color: #333333;
+ font-weight: 500;
+ color: var(--td-text-color-primary);
min-width: 50px;
text-align: right;
}
@@ -522,7 +522,7 @@ onMounted(() => {
.info-section-title {
font-size: 14px;
font-weight: 600;
- color: #333333;
+ color: var(--td-text-color-primary);
margin-top: 24px;
margin-bottom: 12px;
diff --git a/internal/handler/initialization.go b/internal/handler/initialization.go
index a78bef0c9..22471df3d 100644
--- a/internal/handler/initialization.go
+++ b/internal/handler/initialization.go
@@ -83,6 +83,49 @@ func NewInitializationHandler(
}
}
+// KBModelConfigRequest 知识库模型配置请求(简化版,只传模型ID)
+type KBModelConfigRequest struct {
+ LLMModelID string `json:"llmModelId" binding:"required"`
+ EmbeddingModelID string `json:"embeddingModelId" binding:"required"`
+ RerankModelID string `json:"rerankModelId"` // 可选
+ VLLMModelID string `json:"vllmModelId"` // 可选
+
+ // 文档分块配置
+ DocumentSplitting struct {
+ ChunkSize int `json:"chunkSize"`
+ ChunkOverlap int `json:"chunkOverlap"`
+ Separators []string `json:"separators"`
+ } `json:"documentSplitting"`
+
+ // 多模态配置
+ Multimodal struct {
+ Enabled bool `json:"enabled"`
+ StorageType string `json:"storageType"` // "cos" or "minio"
+ COS *struct {
+ SecretID string `json:"secretId"`
+ SecretKey string `json:"secretKey"`
+ Region string `json:"region"`
+ BucketName string `json:"bucketName"`
+ AppID string `json:"appId"`
+ PathPrefix string `json:"pathPrefix"`
+ } `json:"cos"`
+ Minio *struct {
+ BucketName string `json:"bucketName"`
+ UseSSL bool `json:"useSSL"`
+ PathPrefix string `json:"pathPrefix"`
+ } `json:"minio"`
+ } `json:"multimodal"`
+
+ // 知识图谱配置
+ NodeExtract struct {
+ Enabled bool `json:"enabled"`
+ Text string `json:"text"`
+ Tags []string `json:"tags"`
+ Nodes []types.GraphNode `json:"nodes"`
+ Relations []types.GraphRelation `json:"relations"`
+ } `json:"nodeExtract"`
+}
+
// InitializationRequest 初始化请求结构
type InitializationRequest struct {
LLM struct {
@@ -152,6 +195,164 @@ type InitializationRequest struct {
} `json:"nodeExtract"`
}
+// UpdateKBConfig 根据知识库ID和模型ID更新配置(简化版)
+func (h *InitializationHandler) UpdateKBConfig(c *gin.Context) {
+ ctx := c.Request.Context()
+ kbIdStr := c.Param("kbId")
+
+ var req KBModelConfigRequest
+ if err := c.ShouldBindJSON(&req); err != nil {
+ logger.Error(ctx, "Failed to parse KB config request", err)
+ c.Error(errors.NewBadRequestError(err.Error()))
+ return
+ }
+ logger.Infof(ctx, "Starting KB configuration update with model IDs, kbId: %s", kbIdStr)
+
+ // 获取知识库信息
+ kb, err := h.kbService.GetKnowledgeBaseByID(ctx, kbIdStr)
+ if err != nil || kb == nil {
+ logger.ErrorWithFields(ctx, err, map[string]interface{}{"kbId": kbIdStr})
+ c.Error(errors.NewNotFoundError("知识库不存在"))
+ return
+ }
+
+ // 检查Embedding模型是否可以修改
+ if kb.EmbeddingModelID != "" && kb.EmbeddingModelID != req.EmbeddingModelID {
+ // 检查是否已有文件
+ knowledgeList, err := h.knowledgeService.ListPagedKnowledgeByKnowledgeBaseID(ctx,
+ kbIdStr, &types.Pagination{
+ Page: 1,
+ PageSize: 1,
+ })
+ if err == nil && knowledgeList != nil && knowledgeList.Total > 0 {
+ logger.Error(ctx, "Cannot change embedding model when files exist")
+ c.Error(errors.NewBadRequestError("知识库中已有文件,无法修改Embedding模型"))
+ return
+ }
+ }
+
+ // 从数据库获取模型详情并验证
+ llmModel, err := h.modelService.GetModelByID(ctx, req.LLMModelID)
+ if err != nil || llmModel == nil {
+ logger.Error(ctx, "LLM model not found", "modelId", req.LLMModelID)
+ c.Error(errors.NewBadRequestError("LLM模型不存在"))
+ return
+ }
+
+ embeddingModel, err := h.modelService.GetModelByID(ctx, req.EmbeddingModelID)
+ if err != nil || embeddingModel == nil {
+ logger.Error(ctx, "Embedding model not found", "modelId", req.EmbeddingModelID)
+ c.Error(errors.NewBadRequestError("Embedding模型不存在"))
+ return
+ }
+
+ // 更新知识库的模型ID
+ kb.SummaryModelID = req.LLMModelID
+ kb.EmbeddingModelID = req.EmbeddingModelID
+
+ // 处理可选的Rerank模型
+ if req.RerankModelID != "" {
+ rerankModel, err := h.modelService.GetModelByID(ctx, req.RerankModelID)
+ if err != nil || rerankModel == nil {
+ logger.Warn(ctx, "Rerank model not found", "modelId", req.RerankModelID)
+ } else {
+ kb.RerankModelID = req.RerankModelID
+ }
+ } else {
+ kb.RerankModelID = ""
+ }
+
+ // 处理可选的VLLM模型
+ if req.VLLMModelID != "" {
+ vllmModel, err := h.modelService.GetModelByID(ctx, req.VLLMModelID)
+ if err != nil || vllmModel == nil {
+ logger.Warn(ctx, "VLLM model not found", "modelId", req.VLLMModelID)
+ } else {
+ // 只存储模型ID
+ kb.VLMModelID = req.VLLMModelID
+ }
+ } else {
+ kb.VLMModelID = ""
+ }
+
+ // 更新文档分块配置
+ if req.DocumentSplitting.ChunkSize > 0 {
+ kb.ChunkingConfig.ChunkSize = req.DocumentSplitting.ChunkSize
+ }
+ if req.DocumentSplitting.ChunkOverlap >= 0 {
+ kb.ChunkingConfig.ChunkOverlap = req.DocumentSplitting.ChunkOverlap
+ }
+ if len(req.DocumentSplitting.Separators) > 0 {
+ kb.ChunkingConfig.Separators = req.DocumentSplitting.Separators
+ }
+
+ // 更新多模态配置
+ if req.Multimodal.Enabled {
+ switch strings.ToLower(req.Multimodal.StorageType) {
+ case "cos":
+ if req.Multimodal.COS != nil {
+ kb.StorageConfig = types.StorageConfig{
+ SecretID: req.Multimodal.COS.SecretID,
+ SecretKey: req.Multimodal.COS.SecretKey,
+ Region: req.Multimodal.COS.Region,
+ BucketName: req.Multimodal.COS.BucketName,
+ AppID: req.Multimodal.COS.AppID,
+ PathPrefix: req.Multimodal.COS.PathPrefix,
+ Provider: "cos",
+ }
+ }
+ case "minio":
+ if req.Multimodal.Minio != nil {
+ kb.StorageConfig = types.StorageConfig{
+ BucketName: req.Multimodal.Minio.BucketName,
+ PathPrefix: req.Multimodal.Minio.PathPrefix,
+ Provider: "minio",
+ SecretID: os.Getenv("MINIO_ACCESS_KEY_ID"),
+ SecretKey: os.Getenv("MINIO_SECRET_ACCESS_KEY"),
+ }
+ }
+ }
+ } else {
+ // 多模态未启用时,清空存储配置
+ kb.StorageConfig = types.StorageConfig{}
+ }
+
+ // 更新知识图谱配置
+ if req.NodeExtract.Enabled {
+ // 转换 Nodes 和 Relations 为指针类型
+ nodes := make([]*types.GraphNode, len(req.NodeExtract.Nodes))
+ for i := range req.NodeExtract.Nodes {
+ nodes[i] = &req.NodeExtract.Nodes[i]
+ }
+ relations := make([]*types.GraphRelation, len(req.NodeExtract.Relations))
+ for i := range req.NodeExtract.Relations {
+ relations[i] = &req.NodeExtract.Relations[i]
+ }
+
+ kb.ExtractConfig = &types.ExtractConfig{
+ Text: req.NodeExtract.Text,
+ Tags: req.NodeExtract.Tags,
+ Nodes: nodes,
+ Relations: relations,
+ }
+ } else {
+ kb.ExtractConfig = nil
+ }
+
+ // 保存更新后的知识库
+ if err := h.kbRepository.UpdateKnowledgeBase(ctx, kb); err != nil {
+ logger.Error(ctx, "Failed to update knowledge base", err)
+ c.Error(errors.NewInternalServerError("更新知识库失败: " + err.Error()))
+ return
+ }
+
+ logger.Info(ctx, "KB configuration updated successfully", "kbId", kbIdStr)
+ c.JSON(http.StatusOK, gin.H{
+ "success": true,
+ "message": "配置更新成功",
+ })
+}
+
// InitializeByKB 根据知识库ID执行配置更新
func (h *InitializationHandler) InitializeByKB(c *gin.Context) {
ctx := c.Request.Context()
@@ -989,19 +1190,22 @@ func (h *InitializationHandler) buildConfigResponse(ctx context.Context, models
}
multimodal := config["multimodal"].(map[string]interface{})
multimodal["vlm"] = map[string]interface{}{
- "modelName": model.Name,
- "baseUrl": model.Parameters.BaseURL,
- "apiKey": model.Parameters.APIKey,
- "interfaceType": kb.VLMConfig.InterfaceType,
+ "modelName": model.Name,
+ "baseUrl": model.Parameters.BaseURL,
+ "apiKey": model.Parameters.APIKey,
}
}
}
- // 如果没有VLM模型,设置multimodal为disabled
+ // 判断多模态是否启用:有VLM模型ID或有存储配置
+ hasMultimodal := (kb.VLMModelID != "" || kb.StorageConfig.SecretID != "" || kb.StorageConfig.BucketName != "")
if config["multimodal"] == nil {
config["multimodal"] = map[string]interface{}{
- "enabled": false,
+ "enabled": hasMultimodal,
}
+ } else {
+ // 如果已经设置过 multimodal,更新 enabled 状态
+ config["multimodal"].(map[string]interface{})["enabled"] = hasMultimodal
}
// 如果没有Rerank模型,设置rerank为disabled
diff --git a/internal/handler/tenant.go b/internal/handler/tenant.go
index 8516c9b33..d5b92432b 100644
--- a/internal/handler/tenant.go
+++ b/internal/handler/tenant.go
@@ -334,7 +334,7 @@ func (h *TenantHandler) UpdateTenantAgentConfig(c *gin.Context) {
// Validate configuration
if req.Enabled {
- if req.MaxIterations <= 0 || req.MaxIterations > 20 {
+ if req.MaxIterations <= 0 || req.MaxIterations > 30 {
c.Error(errors.NewAgentInvalidMaxIterationsError())
return
}
diff --git a/internal/router/router.go b/internal/router/router.go
index 35754c638..0365b95fd 100644
--- a/internal/router/router.go
+++ b/internal/router/router.go
@@ -264,6 +264,7 @@ func RegisterInitializationRoutes(r *gin.RouterGroup, handler *handler.Initializ
// 初始化接口
r.GET("/initialization/config/:kbId", handler.GetCurrentConfigByKB)
r.POST("/initialization/initialize/:kbId", handler.InitializeByKB)
+ r.PUT("/initialization/config/:kbId", handler.UpdateKBConfig) // 新的简化版接口,只传模型ID
// Ollama相关接口
r.GET("/initialization/ollama/status", handler.CheckOllamaStatus)