refactor(frontend): unify Model/WebSearch/MCP settings pages with shared card + drawer
Aligns the three list-style settings pages (ModelSettings, WebSearchSettings,
McpSettings) under a consistent visual language, and replaces the modal editors
with right-side drawers for a calmer editing flow.
- Extract shared building blocks under frontend/src/components/settings/:
SettingCard (list-item card), SettingDrawer (500px right drawer with a
pinned footer), and useConfirmDelete (a single DialogPlugin.confirm path
that replaces the mix of window.confirm / t-popconfirm / ad-hoc dialogs).
- Swap the old bespoke overlay / t-dialog shells in ModelEditorDialog and
McpServiceDialog for SettingDrawer. Form logic is untouched.
- Model settings now use a single t-tabs filter (All/Chat/Embedding/ReRank/
Vision/Speech with per-type counts) and decouple "Add model" from the tab
state via a dropdown in the header. Type tags get a 5-color palette so
categories read at a glance. The list is a two-column grid.
- Web search and MCP lists are likewise rendered as two-column grids, with
richer cards: transport type / provider, on-off and default state, plus a
compact meta row showing base URL, proxy or service URL.
- Introduce modelSettings.typeShort.{chat,embedding,rerank,vllm,asr} in all
four locales for the shortened category labels.
This commit is contained in:
@@ -1,24 +1,15 @@
|
|||||||
<template>
|
<template>
|
||||||
<Teleport to="body">
|
<SettingDrawer
|
||||||
<Transition name="modal">
|
:visible="dialogVisible"
|
||||||
<div v-if="dialogVisible" class="model-editor-overlay" @mousedown.self="handleOverlayMouseDown" @mouseup.self="handleOverlayMouseUp">
|
:title="isEdit ? $t('model.editor.editTitle') : $t('model.editor.addTitle')"
|
||||||
<div class="model-editor-modal">
|
:description="getModalDescription()"
|
||||||
<!-- 关闭按钮 -->
|
:confirm-loading="saving"
|
||||||
<button class="close-btn" @click="handleCancel" :aria-label="$t('common.close')">
|
:confirm-disabled="formData.provider === 'weknoracloud' && wkcCredentialState !== 'configured'"
|
||||||
<svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor">
|
@update:visible="(v: boolean) => dialogVisible = v"
|
||||||
<path d="M15 5L5 15M5 5L15 15" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
@confirm="handleConfirm"
|
||||||
</svg>
|
@cancel="handleCancel"
|
||||||
</button>
|
>
|
||||||
|
<t-form ref="formRef" :data="formData" :rules="rules" layout="vertical">
|
||||||
<!-- 标题区域 -->
|
|
||||||
<div class="modal-header">
|
|
||||||
<h2 class="modal-title">{{ isEdit ? $t('model.editor.editTitle') : $t('model.editor.addTitle') }}</h2>
|
|
||||||
<p class="modal-desc">{{ getModalDescription() }}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 表单内容区域 -->
|
|
||||||
<div class="modal-body">
|
|
||||||
<t-form ref="formRef" :data="formData" :rules="rules" layout="vertical">
|
|
||||||
<!-- 模型来源 -->
|
<!-- 模型来源 -->
|
||||||
<div class="form-item">
|
<div class="form-item">
|
||||||
<label class="form-label required">{{ $t('model.editor.sourceLabel') }}</label>
|
<label class="form-label required">{{ $t('model.editor.sourceLabel') }}</label>
|
||||||
@@ -329,21 +320,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
</t-form>
|
</t-form>
|
||||||
</div>
|
</SettingDrawer>
|
||||||
|
|
||||||
<!-- 底部按钮区域 -->
|
|
||||||
<div class="modal-footer">
|
|
||||||
<t-button theme="default" variant="outline" @click="handleCancel">
|
|
||||||
{{ $t('common.cancel') }}
|
|
||||||
</t-button>
|
|
||||||
<t-button theme="primary" @click="handleConfirm" :loading="saving" :disabled="formData.provider === 'weknoracloud' && wkcCredentialState !== 'configured'">
|
|
||||||
{{ $t('common.save') }}
|
|
||||||
</t-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Transition>
|
|
||||||
</Teleport>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -353,6 +330,7 @@ import { checkOllamaModels, checkRemoteModel, testEmbeddingModel, checkRerankMod
|
|||||||
import { getWeKnoraCloudStatus } from '@/api/model'
|
import { getWeKnoraCloudStatus } from '@/api/model'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useUIStore } from '@/stores/ui'
|
import { useUIStore } from '@/stores/ui'
|
||||||
|
import SettingDrawer from '@/components/settings/SettingDrawer.vue'
|
||||||
|
|
||||||
interface CustomHeaderItem {
|
interface CustomHeaderItem {
|
||||||
key: string
|
key: string
|
||||||
@@ -707,6 +685,11 @@ const checkOllamaServiceStatus = async () => {
|
|||||||
} finally {
|
} finally {
|
||||||
checkingOllamaStatus.value = false
|
checkingOllamaStatus.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ollama 不可用时,新增场景下默认切换到 remote
|
||||||
|
if (ollamaServiceStatus.value === false && !isEdit.value && formData.value.source === 'local') {
|
||||||
|
formData.value.source = 'remote'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 打开Ollama设置窗口
|
// 打开Ollama设置窗口
|
||||||
@@ -728,28 +711,46 @@ const goToOllamaSettings = async () => {
|
|||||||
console.log('uiStore.openSettings调用完成')
|
console.log('uiStore.openSettings调用完成')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 上一次打开时的 modelData id:用来判断切换模型/新增 vs. 同一次新增的连续打开
|
||||||
|
const lastOpenedModelId = ref<string | null>(null)
|
||||||
|
|
||||||
// 监听 visible 变化,初始化表单
|
// 监听 visible 变化,初始化表单
|
||||||
watch(() => props.visible, (val) => {
|
watch(() => props.visible, (val) => {
|
||||||
if (val) {
|
if (val) {
|
||||||
// 锁定背景滚动
|
|
||||||
document.body.style.overflow = 'hidden'
|
|
||||||
|
|
||||||
// 检查Ollama服务状态
|
// 检查Ollama服务状态
|
||||||
checkOllamaServiceStatus()
|
checkOllamaServiceStatus()
|
||||||
|
|
||||||
// 从 API 加载 Model Provider 列表
|
// 从 API 加载 Model Provider 列表
|
||||||
loadProviders()
|
loadProviders()
|
||||||
|
|
||||||
|
// 每次打开都清理上一次遗留的校验/检测结果,避免编辑别的模型时
|
||||||
|
// 直接显示上一次的“连接成功”
|
||||||
|
modelChecked.value = false
|
||||||
|
modelAvailable.value = false
|
||||||
|
remoteChecked.value = false
|
||||||
|
remoteAvailable.value = false
|
||||||
|
remoteMessage.value = ''
|
||||||
|
dimensionChecked.value = false
|
||||||
|
dimensionSuccess.value = false
|
||||||
|
dimensionMessage.value = ''
|
||||||
|
|
||||||
|
const currentId = props.modelData?.id ?? null
|
||||||
|
|
||||||
if (props.modelData) {
|
if (props.modelData) {
|
||||||
|
// 编辑:始终用最新的 modelData 覆盖
|
||||||
formData.value = {
|
formData.value = {
|
||||||
...props.modelData,
|
...props.modelData,
|
||||||
customHeaders: Array.isArray(props.modelData.customHeaders)
|
customHeaders: Array.isArray(props.modelData.customHeaders)
|
||||||
? props.modelData.customHeaders.map(h => ({ key: h.key, value: h.value }))
|
? props.modelData.customHeaders.map(h => ({ key: h.key, value: h.value }))
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
} else {
|
} else if (lastOpenedModelId.value !== null || !formData.value.id) {
|
||||||
|
// 上次是编辑某个模型,或第一次新增 → 重置成空白
|
||||||
resetForm()
|
resetForm()
|
||||||
}
|
}
|
||||||
|
// 否则:连续两次"新增"打开(中间是点遮罩/ESC 关闭的)→ 保留上次填写
|
||||||
|
|
||||||
|
lastOpenedModelId.value = currentId
|
||||||
|
|
||||||
// ReRank 模型强制使用 remote 来源(Ollama 不支持 ReRank)
|
// ReRank 模型强制使用 remote 来源(Ollama 不支持 ReRank)
|
||||||
if (props.modelType === 'rerank') {
|
if (props.modelType === 'rerank') {
|
||||||
@@ -760,9 +761,6 @@ watch(() => props.visible, (val) => {
|
|||||||
if (formData.value.provider === 'weknoracloud') {
|
if (formData.value.provider === 'weknoracloud') {
|
||||||
checkWkcCredentialStatus()
|
checkWkcCredentialStatus()
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// 恢复背景滚动
|
|
||||||
document.body.style.overflow = ''
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -1121,6 +1119,9 @@ const handleConfirm = async () => {
|
|||||||
|
|
||||||
emit('confirm', { ...formData.value })
|
emit('confirm', { ...formData.value })
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
|
// 保存成功后重置草稿,下次打开新增模型时是空白
|
||||||
|
resetForm()
|
||||||
|
lastOpenedModelId.value = null
|
||||||
// 移除此处的成功提示,由父组件统一处理
|
// 移除此处的成功提示,由父组件统一处理
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('表单验证失败:', error)
|
console.error('表单验证失败:', error)
|
||||||
@@ -1253,133 +1254,19 @@ watch(() => formData.value.modelName, () => {
|
|||||||
dimensionMessage.value = ''
|
dimensionMessage.value = ''
|
||||||
})
|
})
|
||||||
|
|
||||||
// 取消
|
// 取消(点击底部"取消"按钮触发;点遮罩/ESC 不触发,从而保留草稿)
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
|
resetForm()
|
||||||
|
lastOpenedModelId.value = null
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 遮罩层点击关闭:只有 mousedown 和 mouseup 都发生在遮罩层上才关闭,
|
|
||||||
// 防止在输入框中拖选文字时鼠标滑出弹窗导致误关闭
|
|
||||||
let overlayMouseDownFired = false
|
|
||||||
const handleOverlayMouseDown = () => {
|
|
||||||
overlayMouseDownFired = true
|
|
||||||
}
|
|
||||||
const handleOverlayMouseUp = () => {
|
|
||||||
if (overlayMouseDownFired) {
|
|
||||||
handleCancel()
|
|
||||||
}
|
|
||||||
overlayMouseDownFired = false
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
// 遮罩层
|
// 原生 t-form-item 容器置空(本组件使用自定义 .form-item + 手写 label)
|
||||||
.model-editor-overlay {
|
:deep(.t-form) {
|
||||||
position: fixed;
|
.t-form-item {
|
||||||
top: 0;
|
display: none;
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
background: rgba(0, 0, 0, 0.5);
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
z-index: 1200;
|
|
||||||
backdrop-filter: blur(4px);
|
|
||||||
overflow: hidden;
|
|
||||||
padding: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 弹窗主体
|
|
||||||
.model-editor-modal {
|
|
||||||
position: relative;
|
|
||||||
width: 100%;
|
|
||||||
max-width: 560px;
|
|
||||||
max-height: 90vh;
|
|
||||||
background: var(--td-bg-color-container);
|
|
||||||
border-radius: 12px;
|
|
||||||
box-shadow: 0 6px 28px rgba(15, 23, 42, 0.08);
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 关闭按钮
|
|
||||||
.close-btn {
|
|
||||||
position: absolute;
|
|
||||||
top: 16px;
|
|
||||||
right: 16px;
|
|
||||||
width: 32px;
|
|
||||||
height: 32px;
|
|
||||||
border: none;
|
|
||||||
background: transparent;
|
|
||||||
border-radius: 6px;
|
|
||||||
cursor: pointer;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
color: var(--td-text-color-secondary);
|
|
||||||
transition: all 0.15s ease;
|
|
||||||
z-index: 10;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
color: var(--td-text-color-primary);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 标题区域
|
|
||||||
.modal-header {
|
|
||||||
padding: 24px 24px 16px;
|
|
||||||
border-bottom: 1px solid var(--td-component-stroke);
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.modal-title {
|
|
||||||
margin: 0 0 6px 0;
|
|
||||||
font-size: 18px;
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--td-text-color-primary);
|
|
||||||
}
|
|
||||||
|
|
||||||
.modal-desc {
|
|
||||||
margin: 0;
|
|
||||||
font-size: 13px;
|
|
||||||
color: var(--td-text-color-secondary);
|
|
||||||
line-height: 1.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 内容区域
|
|
||||||
.modal-body {
|
|
||||||
flex: 1;
|
|
||||||
overflow-y: auto;
|
|
||||||
padding: 24px;
|
|
||||||
background: var(--td-bg-color-container);
|
|
||||||
|
|
||||||
// 自定义滚动条
|
|
||||||
&::-webkit-scrollbar {
|
|
||||||
width: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
&::-webkit-scrollbar-track {
|
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
border-radius: 3px;
|
|
||||||
}
|
|
||||||
|
|
||||||
&::-webkit-scrollbar-thumb {
|
|
||||||
background: var(--td-bg-color-component-disabled);
|
|
||||||
border-radius: 3px;
|
|
||||||
transition: background 0.15s;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background: var(--td-bg-color-component-disabled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(.t-form) {
|
|
||||||
.t-form-item {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1407,38 +1294,14 @@ const handleOverlayMouseUp = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 输入框样式
|
// 输入框样式:只在最外层 .t-input 上调字号,避免在内部 wrap/inner 上重复加边
|
||||||
|
// 与 border-radius,造成视觉上"嵌套圆角容器"的错觉
|
||||||
:deep(.t-input),
|
:deep(.t-input),
|
||||||
:deep(.t-select),
|
:deep(.t-select),
|
||||||
:deep(.t-textarea),
|
:deep(.t-textarea),
|
||||||
:deep(.t-input-number) {
|
:deep(.t-input-number) {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
|
|
||||||
.t-input__inner,
|
|
||||||
.t-input__wrap,
|
|
||||||
input,
|
|
||||||
textarea {
|
|
||||||
font-size: 13px;
|
|
||||||
border-radius: 6px;
|
|
||||||
border-color: var(--td-component-stroke);
|
|
||||||
transition: all 0.15s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover .t-input__inner,
|
|
||||||
&:hover .t-input__wrap,
|
|
||||||
&:hover input,
|
|
||||||
&:hover textarea {
|
|
||||||
border-color: var(--td-component-stroke);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.t-is-focused .t-input__inner,
|
|
||||||
&.t-is-focused .t-input__wrap,
|
|
||||||
&.t-is-focused input,
|
|
||||||
&.t-is-focused textarea {
|
|
||||||
border-color: var(--td-brand-color);
|
|
||||||
box-shadow: 0 0 0 2px rgba(7, 192, 95, 0.1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 厂商选择器样式 — 移至非 scoped 块,因为 t-select popup 渲染到 body 下
|
// 厂商选择器样式 — 移至非 scoped 块,因为 t-select popup 渲染到 body 下
|
||||||
@@ -1482,72 +1345,6 @@ const handleOverlayMouseUp = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 底部按钮区域
|
|
||||||
.modal-footer {
|
|
||||||
padding: 16px 24px;
|
|
||||||
border-top: 1px solid var(--td-component-stroke);
|
|
||||||
display: flex;
|
|
||||||
justify-content: flex-end;
|
|
||||||
gap: 12px;
|
|
||||||
flex-shrink: 0;
|
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
|
|
||||||
:deep(.t-button) {
|
|
||||||
min-width: 80px;
|
|
||||||
height: 36px;
|
|
||||||
font-weight: 500;
|
|
||||||
font-size: 14px;
|
|
||||||
border-radius: 6px;
|
|
||||||
transition: all 0.15s ease;
|
|
||||||
|
|
||||||
&.t-button--theme-primary {
|
|
||||||
background: var(--td-brand-color);
|
|
||||||
border-color: var(--td-brand-color);
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background: var(--td-brand-color);
|
|
||||||
border-color: var(--td-brand-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
&:active {
|
|
||||||
background: var(--td-brand-color-active);
|
|
||||||
border-color: var(--td-brand-color-active);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.t-button--variant-outline {
|
|
||||||
color: var(--td-text-color-secondary);
|
|
||||||
border-color: var(--td-component-stroke);
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
border-color: var(--td-brand-color);
|
|
||||||
color: var(--td-brand-color);
|
|
||||||
background: rgba(7, 192, 95, 0.04);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 过渡动画
|
|
||||||
.modal-enter-active,
|
|
||||||
.modal-leave-active {
|
|
||||||
transition: opacity 0.2s ease;
|
|
||||||
|
|
||||||
.model-editor-modal {
|
|
||||||
transition: transform 0.2s ease, opacity 0.2s ease;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.modal-enter-from,
|
|
||||||
.modal-leave-to {
|
|
||||||
opacity: 0;
|
|
||||||
|
|
||||||
.model-editor-modal {
|
|
||||||
transform: scale(0.95);
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// API 测试区域
|
// API 测试区域
|
||||||
.api-test-section {
|
.api-test-section {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -1903,20 +1700,36 @@ const handleOverlayMouseUp = () => {
|
|||||||
// 覆盖 TDesign option 默认固定高度,让两行内容正常展示
|
// 覆盖 TDesign option 默认固定高度,让两行内容正常展示
|
||||||
.t-select-option {
|
.t-select-option {
|
||||||
height: auto !important;
|
height: auto !important;
|
||||||
padding: 0 8px;
|
padding: 6px 12px;
|
||||||
|
border-radius: 6px;
|
||||||
|
margin: 0 4px;
|
||||||
|
outline: none;
|
||||||
|
|
||||||
|
&:focus,
|
||||||
|
&:focus-visible {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 命中态:浅一点的底色,去掉默认的描边/反色
|
||||||
|
.t-select-option.t-is-selected {
|
||||||
|
background-color: var(--td-brand-color-light);
|
||||||
|
color: var(--td-text-color-primary);
|
||||||
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
.provider-option {
|
.provider-option {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 2px;
|
gap: 2px;
|
||||||
padding: 6px 0;
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
|
||||||
.provider-name {
|
.provider-name {
|
||||||
font-size: 14px;
|
font-size: 13px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
color: var(--td-text-color-primary);
|
color: var(--td-text-color-primary);
|
||||||
line-height: 22px;
|
line-height: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.provider-desc {
|
.provider-desc {
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
<template>
|
||||||
|
<div class="setting-card" :class="{ 'setting-card--disabled': disabled }">
|
||||||
|
<div class="setting-card__header">
|
||||||
|
<h3 class="setting-card__title" :title="title">{{ title }}</h3>
|
||||||
|
<div class="setting-card__header-right">
|
||||||
|
<slot name="controls" />
|
||||||
|
<t-dropdown
|
||||||
|
v-if="actions && actions.length > 0"
|
||||||
|
:options="actions"
|
||||||
|
placement="bottom-right"
|
||||||
|
attach="body"
|
||||||
|
@click="(data: any) => emit('action', data.value)"
|
||||||
|
>
|
||||||
|
<t-button variant="text" shape="square" size="small" class="setting-card__more">
|
||||||
|
<t-icon name="more" />
|
||||||
|
</t-button>
|
||||||
|
</t-dropdown>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-if="$slots.tags" class="setting-card__tags">
|
||||||
|
<slot name="tags" />
|
||||||
|
</div>
|
||||||
|
<p v-if="description" class="setting-card__desc">{{ description }}</p>
|
||||||
|
<div v-if="$slots.meta" class="setting-card__meta">
|
||||||
|
<slot name="meta" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
interface DropdownOption {
|
||||||
|
content: string
|
||||||
|
value: string
|
||||||
|
theme?: 'default' | 'success' | 'warning' | 'error' | 'primary'
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
title: string
|
||||||
|
description?: string
|
||||||
|
disabled?: boolean
|
||||||
|
actions?: DropdownOption[]
|
||||||
|
}
|
||||||
|
|
||||||
|
withDefaults(defineProps<Props>(), {
|
||||||
|
description: '',
|
||||||
|
disabled: false,
|
||||||
|
actions: () => []
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'action', value: string): void
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.setting-card {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 16px;
|
||||||
|
border: 1px solid var(--td-component-stroke);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: var(--td-bg-color-container);
|
||||||
|
transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
|
||||||
|
min-width: 0;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
border-color: var(--td-brand-color);
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
&--disabled {
|
||||||
|
background: var(--td-bg-color-secondarycontainer);
|
||||||
|
|
||||||
|
.setting-card__title {
|
||||||
|
color: var(--td-text-color-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
border-color: var(--td-brand-color-light);
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-card__header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 8px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-card__title {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
margin: 0;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.4;
|
||||||
|
color: var(--td-text-color-primary);
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-card__header-right {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-card__more {
|
||||||
|
color: var(--td-text-color-placeholder);
|
||||||
|
padding: 4px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: var(--td-bg-color-secondarycontainer);
|
||||||
|
color: var(--td-text-color-primary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-card__tags {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
min-height: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-card__desc {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: var(--td-text-color-secondary);
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
overflow: hidden;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-card__meta {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--td-text-color-placeholder);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
<template>
|
||||||
|
<t-drawer
|
||||||
|
v-model:visible="drawerVisible"
|
||||||
|
:header="title"
|
||||||
|
:size="width"
|
||||||
|
placement="right"
|
||||||
|
destroy-on-close
|
||||||
|
>
|
||||||
|
<div class="setting-drawer__body">
|
||||||
|
<p v-if="description" class="setting-drawer__desc">{{ description }}</p>
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
<template v-if="!hideFooter" #footer>
|
||||||
|
<div class="setting-drawer__footer">
|
||||||
|
<div class="setting-drawer__footer-left">
|
||||||
|
<slot name="footer-left" />
|
||||||
|
</div>
|
||||||
|
<div class="setting-drawer__footer-right">
|
||||||
|
<t-button theme="default" variant="outline" @click="handleCancel">
|
||||||
|
{{ cancelText || t('common.cancel') }}
|
||||||
|
</t-button>
|
||||||
|
<t-button
|
||||||
|
theme="primary"
|
||||||
|
:loading="confirmLoading"
|
||||||
|
:disabled="confirmDisabled"
|
||||||
|
@click="handleConfirm"
|
||||||
|
>
|
||||||
|
{{ confirmText || t('common.save') }}
|
||||||
|
</t-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</t-drawer>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
visible: boolean
|
||||||
|
title: string
|
||||||
|
description?: string
|
||||||
|
width?: string
|
||||||
|
confirmLoading?: boolean
|
||||||
|
confirmDisabled?: boolean
|
||||||
|
confirmText?: string
|
||||||
|
cancelText?: string
|
||||||
|
hideFooter?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
|
description: '',
|
||||||
|
width: '500px',
|
||||||
|
confirmLoading: false,
|
||||||
|
confirmDisabled: false,
|
||||||
|
confirmText: '',
|
||||||
|
cancelText: '',
|
||||||
|
hideFooter: false
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'update:visible', value: boolean): void
|
||||||
|
(e: 'confirm'): void
|
||||||
|
(e: 'cancel'): void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
const drawerVisible = computed({
|
||||||
|
get: () => props.visible,
|
||||||
|
set: (val) => emit('update:visible', val)
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleConfirm = () => emit('confirm')
|
||||||
|
const handleCancel = () => {
|
||||||
|
emit('cancel')
|
||||||
|
emit('update:visible', false)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.setting-drawer__body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-drawer__desc {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--td-text-color-secondary);
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-drawer__footer {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-drawer__footer-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-drawer__footer-right {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { DialogPlugin } from 'tdesign-vue-next'
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
||||||
|
interface ConfirmDeleteOptions {
|
||||||
|
title?: string
|
||||||
|
body: string
|
||||||
|
confirmText?: string
|
||||||
|
cancelText?: string
|
||||||
|
onConfirm: () => Promise<void> | void
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一的删除确认交互,基于 TDesign DialogPlugin.confirm。
|
||||||
|
* 取代散落在各处的 window.confirm / t-popconfirm / 自定义 Dialog 写法。
|
||||||
|
*/
|
||||||
|
export function useConfirmDelete() {
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
return (opts: ConfirmDeleteOptions) => {
|
||||||
|
const dialog = DialogPlugin.confirm({
|
||||||
|
header: opts.title || (t('common.confirmDelete') as string),
|
||||||
|
body: opts.body,
|
||||||
|
confirmBtn: opts.confirmText || (t('common.delete') as string),
|
||||||
|
cancelBtn: opts.cancelText || (t('common.cancel') as string),
|
||||||
|
theme: 'warning',
|
||||||
|
onConfirm: async () => {
|
||||||
|
try {
|
||||||
|
await opts.onConfirm()
|
||||||
|
} finally {
|
||||||
|
dialog.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return dialog
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2855,6 +2855,13 @@ export default {
|
|||||||
modelSettings: {
|
modelSettings: {
|
||||||
title: 'Model Settings',
|
title: 'Model Settings',
|
||||||
description: 'Manage different types of AI models, including local Ollama and remote APIs',
|
description: 'Manage different types of AI models, including local Ollama and remote APIs',
|
||||||
|
typeShort: {
|
||||||
|
chat: 'Chat',
|
||||||
|
embedding: 'Embedding',
|
||||||
|
rerank: 'ReRank',
|
||||||
|
vllm: 'Vision',
|
||||||
|
asr: 'Speech',
|
||||||
|
},
|
||||||
actions: {
|
actions: {
|
||||||
addModel: 'Add Model',
|
addModel: 'Add Model',
|
||||||
setDefault: 'Set as Default'
|
setDefault: 'Set as Default'
|
||||||
|
|||||||
@@ -2902,6 +2902,13 @@ export default {
|
|||||||
modelSettings: {
|
modelSettings: {
|
||||||
title: "모델 설정",
|
title: "모델 설정",
|
||||||
description: "다양한 유형의 AI 모델을 관리합니다. Ollama 로컬 모델과 원격 API를 지원합니다",
|
description: "다양한 유형의 AI 모델을 관리합니다. Ollama 로컬 모델과 원격 API를 지원합니다",
|
||||||
|
typeShort: {
|
||||||
|
chat: "대화",
|
||||||
|
embedding: "Embedding",
|
||||||
|
rerank: "ReRank",
|
||||||
|
vllm: "비전",
|
||||||
|
asr: "음성",
|
||||||
|
},
|
||||||
actions: {
|
actions: {
|
||||||
addModel: "모델 추가",
|
addModel: "모델 추가",
|
||||||
setDefault: "기본값으로 설정",
|
setDefault: "기본값으로 설정",
|
||||||
|
|||||||
@@ -2660,6 +2660,13 @@ export default {
|
|||||||
modelSettings: {
|
modelSettings: {
|
||||||
title: 'Настройки моделей',
|
title: 'Настройки моделей',
|
||||||
description: 'Управление типами AI‑моделей: локальные (Ollama) и удалённые API',
|
description: 'Управление типами AI‑моделей: локальные (Ollama) и удалённые API',
|
||||||
|
typeShort: {
|
||||||
|
chat: 'Чат',
|
||||||
|
embedding: 'Embedding',
|
||||||
|
rerank: 'ReRank',
|
||||||
|
vllm: 'Зрение',
|
||||||
|
asr: 'Речь',
|
||||||
|
},
|
||||||
actions: {
|
actions: {
|
||||||
addModel: 'Добавить модель',
|
addModel: 'Добавить модель',
|
||||||
setDefault: 'Сделать по умолчанию'
|
setDefault: 'Сделать по умолчанию'
|
||||||
|
|||||||
@@ -2852,6 +2852,13 @@ export default {
|
|||||||
modelSettings: {
|
modelSettings: {
|
||||||
title: "模型配置",
|
title: "模型配置",
|
||||||
description: "管理不同类型的 AI 模型,支持 Ollama 本地模型和远程 API",
|
description: "管理不同类型的 AI 模型,支持 Ollama 本地模型和远程 API",
|
||||||
|
typeShort: {
|
||||||
|
chat: "对话",
|
||||||
|
embedding: "Embedding",
|
||||||
|
rerank: "ReRank",
|
||||||
|
vllm: "视觉",
|
||||||
|
asr: "语音",
|
||||||
|
},
|
||||||
actions: {
|
actions: {
|
||||||
addModel: "添加模型",
|
addModel: "添加模型",
|
||||||
setDefault: "设为默认",
|
setDefault: "设为默认",
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
<t-loading :text="$t('common.loading')" />
|
<t-loading :text="$t('common.loading')" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else class="services-container">
|
<template v-else>
|
||||||
<div class="services-header">
|
<div class="settings-toolbar">
|
||||||
<div class="header-info">
|
<div class="toolbar-info">
|
||||||
<h3>{{ $t('mcpSettings.configuredServices') }}</h3>
|
<h3>{{ $t('mcpSettings.configuredServices') }}</h3>
|
||||||
<p>{{ $t('mcpSettings.manageAndTest') }}</p>
|
<p>{{ $t('mcpSettings.manageAndTest') }}</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -24,73 +24,67 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="services.length === 0" class="empty-state">
|
<div v-if="services.length === 0" class="empty-state">
|
||||||
<t-empty :description="$t('mcpSettings.empty')" >
|
<t-empty :description="$t('mcpSettings.empty')">
|
||||||
<t-button theme="primary" @click="handleAdd">{{ $t('mcpSettings.addFirst') }}</t-button>
|
<t-button theme="primary" size="small" @click="handleAdd">
|
||||||
|
<template #icon><t-icon name="add" /></template>
|
||||||
|
{{ $t('mcpSettings.addFirst') }}
|
||||||
|
</t-button>
|
||||||
</t-empty>
|
</t-empty>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else class="services-list">
|
<div v-else class="services-grid">
|
||||||
<div v-for="service in services" :key="service.id" class="service-card">
|
<SettingCard
|
||||||
<div class="service-info">
|
v-for="service in services"
|
||||||
<div class="service-header">
|
:key="service.id"
|
||||||
<div class="service-name">
|
:title="service.name"
|
||||||
{{ service.name }}
|
:description="service.description || ''"
|
||||||
<t-tag
|
:disabled="service.is_builtin"
|
||||||
v-if="service.is_builtin"
|
:actions="service.is_builtin ? getBuiltinServiceOptions() : getServiceOptions()"
|
||||||
theme="warning"
|
@action="(value: string) => handleMenuAction({ value }, service)"
|
||||||
size="small"
|
>
|
||||||
variant="light"
|
<template #tags>
|
||||||
>
|
<t-tag
|
||||||
{{ $t('mcpSettings.builtin') }}
|
:theme="getTransportTypeTheme(service.transport_type)"
|
||||||
</t-tag>
|
size="small"
|
||||||
<t-tag
|
variant="light"
|
||||||
:theme="getTransportTypeTheme(service.transport_type)"
|
>
|
||||||
size="small"
|
{{ getTransportTypeLabel(service.transport_type) }}
|
||||||
variant="light"
|
</t-tag>
|
||||||
>
|
<t-tag
|
||||||
{{ getTransportTypeLabel(service.transport_type) }}
|
v-if="service.is_builtin"
|
||||||
</t-tag>
|
theme="warning"
|
||||||
</div>
|
size="small"
|
||||||
<div class="service-controls">
|
variant="light"
|
||||||
<t-switch
|
>
|
||||||
v-model="service.enabled"
|
{{ $t('mcpSettings.builtin') }}
|
||||||
@change="() => handleToggleEnabled(service)"
|
</t-tag>
|
||||||
size="medium"
|
<t-tag
|
||||||
:disabled="service.is_builtin"
|
:theme="service.enabled ? 'success' : 'default'"
|
||||||
/>
|
size="small"
|
||||||
<t-dropdown
|
variant="light"
|
||||||
v-if="!service.is_builtin"
|
>
|
||||||
:options="getServiceOptions(service)"
|
{{ service.enabled ? $t('common.on') : $t('common.off') }}
|
||||||
@click="(data: any) => handleMenuAction(data, service)"
|
</t-tag>
|
||||||
placement="bottom-right"
|
</template>
|
||||||
:disabled="testing"
|
<template #controls>
|
||||||
>
|
<t-switch
|
||||||
<t-button variant="text" shape="square" size="small" class="more-btn" :disabled="testing">
|
v-model="service.enabled"
|
||||||
<t-icon name="more" />
|
size="medium"
|
||||||
</t-button>
|
:disabled="service.is_builtin"
|
||||||
</t-dropdown>
|
@change="() => handleToggleEnabled(service)"
|
||||||
<t-dropdown
|
/>
|
||||||
v-else
|
</template>
|
||||||
:options="getBuiltinServiceOptions(service)"
|
<template #meta>
|
||||||
@click="(data: any) => handleMenuAction(data, service)"
|
<span v-if="service.url" class="service-meta-item" :title="service.url">
|
||||||
placement="bottom-right"
|
<t-icon name="link" size="12px" />
|
||||||
:disabled="testing"
|
<span class="service-meta-text">{{ service.url }}</span>
|
||||||
>
|
</span>
|
||||||
<t-button variant="text" shape="square" size="small" class="more-btn" :disabled="testing">
|
</template>
|
||||||
<t-icon name="more" />
|
</SettingCard>
|
||||||
</t-button>
|
|
||||||
</t-dropdown>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-if="service.description" class="service-description">
|
|
||||||
{{ service.description }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</template>
|
||||||
|
|
||||||
<!-- Add/Edit Dialog -->
|
<!-- Add/Edit Drawer -->
|
||||||
<McpServiceDialog
|
<McpServiceDialog
|
||||||
v-model:visible="dialogVisible"
|
v-model:visible="dialogVisible"
|
||||||
:service="currentService"
|
:service="currentService"
|
||||||
@@ -109,7 +103,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
import { MessagePlugin, DialogPlugin } from 'tdesign-vue-next'
|
import { MessagePlugin } from 'tdesign-vue-next'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import {
|
import {
|
||||||
listMCPServices,
|
listMCPServices,
|
||||||
@@ -121,8 +115,11 @@ import {
|
|||||||
} from '@/api/mcp-service'
|
} from '@/api/mcp-service'
|
||||||
import McpServiceDialog from './components/McpServiceDialog.vue'
|
import McpServiceDialog from './components/McpServiceDialog.vue'
|
||||||
import McpTestResult from './components/McpTestResult.vue'
|
import McpTestResult from './components/McpTestResult.vue'
|
||||||
|
import SettingCard from '@/components/settings/SettingCard.vue'
|
||||||
|
import { useConfirmDelete } from '@/components/settings/useConfirmDelete'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
const confirmDelete = useConfirmDelete()
|
||||||
|
|
||||||
const services = ref<MCPService[]>([])
|
const services = ref<MCPService[]>([])
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
@@ -176,7 +173,6 @@ const handleToggleEnabled = async (service: MCPService) => {
|
|||||||
await updateMCPService(service.id, { enabled: service.enabled })
|
await updateMCPService(service.id, { enabled: service.enabled })
|
||||||
MessagePlugin.success(service.enabled ? t('mcpSettings.toasts.enabled') : t('mcpSettings.toasts.disabled'))
|
MessagePlugin.success(service.enabled ? t('mcpSettings.toasts.enabled') : t('mcpSettings.toasts.disabled'))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Revert on error
|
|
||||||
service.enabled = originalState
|
service.enabled = originalState
|
||||||
MessagePlugin.error(t('mcpSettings.toasts.updateStateFailed'))
|
MessagePlugin.error(t('mcpSettings.toasts.updateStateFailed'))
|
||||||
console.error('Failed to update MCP service:', error)
|
console.error('Failed to update MCP service:', error)
|
||||||
@@ -190,24 +186,18 @@ const handleTest = async (service: MCPService) => {
|
|||||||
testingServiceName.value = service.name
|
testingServiceName.value = service.name
|
||||||
testing.value = true
|
testing.value = true
|
||||||
|
|
||||||
// 显示测试开始提示
|
|
||||||
MessagePlugin.info({
|
MessagePlugin.info({
|
||||||
content: t('mcpSettings.toasts.testing', { name: service.name }),
|
content: t('mcpSettings.toasts.testing', { name: service.name }),
|
||||||
duration: 0, // 不自动关闭
|
duration: 0,
|
||||||
closeBtn: false
|
closeBtn: false
|
||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await testMCPService(service.id)
|
const result = await testMCPService(service.id)
|
||||||
|
|
||||||
console.log('Test result received:', result)
|
|
||||||
|
|
||||||
// 关闭所有消息提示
|
|
||||||
MessagePlugin.closeAll()
|
MessagePlugin.closeAll()
|
||||||
|
|
||||||
// 检查结果是否存在
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
// 即使没有结果,也显示错误对话框
|
|
||||||
testResult.value = {
|
testResult.value = {
|
||||||
success: false,
|
success: false,
|
||||||
message: t('mcpSettings.toasts.noResponse')
|
message: t('mcpSettings.toasts.noResponse')
|
||||||
@@ -216,47 +206,34 @@ const handleTest = async (service: MCPService) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置测试结果
|
|
||||||
testResult.value = result
|
testResult.value = result
|
||||||
|
|
||||||
// 显示详细结果对话框
|
|
||||||
console.log('Opening test dialog, result:', testResult.value)
|
|
||||||
testDialogVisible.value = true
|
testDialogVisible.value = true
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
// 关闭所有消息提示
|
|
||||||
MessagePlugin.closeAll()
|
MessagePlugin.closeAll()
|
||||||
|
|
||||||
// 显示错误信息
|
|
||||||
const errorMessage = error?.response?.data?.error?.message || error?.message || t('mcpSettings.toasts.testFailed')
|
const errorMessage = error?.response?.data?.error?.message || error?.message || t('mcpSettings.toasts.testFailed')
|
||||||
console.error('Failed to test MCP service:', error)
|
console.error('Failed to test MCP service:', error)
|
||||||
|
|
||||||
// 即使出错也显示结果对话框,显示错误信息
|
|
||||||
testResult.value = {
|
testResult.value = {
|
||||||
success: false,
|
success: false,
|
||||||
message: errorMessage
|
message: errorMessage
|
||||||
}
|
}
|
||||||
testDialogVisible.value = true
|
testDialogVisible.value = true
|
||||||
} finally {
|
} finally {
|
||||||
// 确保关闭 loading
|
|
||||||
testing.value = false
|
testing.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle delete button click
|
// Handle delete button click
|
||||||
const handleDelete = async (service: MCPService) => {
|
const handleDelete = (service: MCPService) => {
|
||||||
if (!service || !service.id) return
|
if (!service || !service.id) return
|
||||||
|
|
||||||
const confirmDialog = DialogPlugin.confirm({
|
confirmDelete({
|
||||||
header: t('common.confirmDelete'),
|
|
||||||
body: t('mcpSettings.deleteConfirmBody', { name: service.name || t('mcpSettings.unnamed') }),
|
body: t('mcpSettings.deleteConfirmBody', { name: service.name || t('mcpSettings.unnamed') }),
|
||||||
confirmBtn: t('common.delete'),
|
|
||||||
cancelBtn: t('common.cancel'),
|
|
||||||
theme: 'warning',
|
|
||||||
onConfirm: async () => {
|
onConfirm: async () => {
|
||||||
try {
|
try {
|
||||||
await deleteMCPService(service.id)
|
await deleteMCPService(service.id)
|
||||||
MessagePlugin.success(t('mcpSettings.toasts.deleted'))
|
MessagePlugin.success(t('mcpSettings.toasts.deleted'))
|
||||||
confirmDialog.hide()
|
|
||||||
loadServices()
|
loadServices()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
MessagePlugin.error(t('mcpSettings.toasts.deleteFailed'))
|
MessagePlugin.error(t('mcpSettings.toasts.deleteFailed'))
|
||||||
@@ -267,44 +244,34 @@ const handleDelete = async (service: MCPService) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get service options for dropdown menu
|
// Get service options for dropdown menu
|
||||||
const getServiceOptions = (service: MCPService) => {
|
const getServiceOptions = () => {
|
||||||
return [
|
return [
|
||||||
{
|
{ content: t('mcpSettings.actions.test'), value: 'test' },
|
||||||
content: t('mcpSettings.actions.test'),
|
{ content: t('common.edit'), value: 'edit' },
|
||||||
value: `test-${service.id}`
|
{ content: t('common.delete'), value: 'delete', theme: 'error' as const }
|
||||||
},
|
|
||||||
{
|
|
||||||
content: t('common.edit'),
|
|
||||||
value: `edit-${service.id}`
|
|
||||||
},
|
|
||||||
{
|
|
||||||
content: t('common.delete'),
|
|
||||||
value: `delete-${service.id}`,
|
|
||||||
theme: 'error'
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get service options for builtin services (test only)
|
// Builtin: 仅测试
|
||||||
const getBuiltinServiceOptions = (service: MCPService) => {
|
const getBuiltinServiceOptions = () => {
|
||||||
return [
|
return [
|
||||||
{
|
{ content: t('mcpSettings.actions.test'), value: 'test' }
|
||||||
content: t('mcpSettings.actions.test'),
|
|
||||||
value: `test-${service.id}`
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle menu action
|
// Handle menu action
|
||||||
const handleMenuAction = (data: { value: string }, service: MCPService) => {
|
const handleMenuAction = (data: { value: string }, service: MCPService) => {
|
||||||
const value = data.value
|
if (testing.value) return
|
||||||
|
switch (data.value) {
|
||||||
if (value.startsWith('test-')) {
|
case 'test':
|
||||||
handleTest(service)
|
handleTest(service)
|
||||||
} else if (value.startsWith('edit-')) {
|
break
|
||||||
handleEdit(service)
|
case 'edit':
|
||||||
} else if (value.startsWith('delete-')) {
|
handleEdit(service)
|
||||||
handleDelete(service)
|
break
|
||||||
|
case 'delete':
|
||||||
|
handleDelete(service)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,7 +314,7 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.section-header {
|
.section-header {
|
||||||
margin-bottom: 32px;
|
margin-bottom: 28px;
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
@@ -360,7 +327,7 @@ onMounted(() => {
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: var(--td-text-color-secondary);
|
color: var(--td-text-color-secondary);
|
||||||
margin: 0;
|
margin: 0;
|
||||||
line-height: 1.5;
|
line-height: 1.6;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,20 +336,16 @@ onMounted(() => {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.services-container {
|
.settings-toolbar {
|
||||||
margin-top: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.services-header {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
padding-bottom: 16px;
|
|
||||||
border-bottom: 1px solid var(--td-component-stroke);
|
|
||||||
|
|
||||||
.header-info {
|
.toolbar-info {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
|
||||||
h3 {
|
h3 {
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
@@ -411,91 +374,23 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.services-list {
|
.services-grid {
|
||||||
display: flex;
|
display: grid;
|
||||||
flex-direction: column;
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
gap: 0;
|
gap: 12px;
|
||||||
border: 1px solid var(--td-component-stroke);
|
|
||||||
border-radius: 6px;
|
|
||||||
padding: 16px;
|
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.service-card {
|
.service-meta-item {
|
||||||
padding: 12px 0;
|
display: inline-flex;
|
||||||
border-bottom: 1px solid var(--td-component-stroke);
|
align-items: center;
|
||||||
transition: all 0.2s;
|
gap: 4px;
|
||||||
|
max-width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
&:last-child {
|
.service-meta-text {
|
||||||
border-bottom: none;
|
overflow: hidden;
|
||||||
padding-bottom: 0;
|
text-overflow: ellipsis;
|
||||||
}
|
white-space: nowrap;
|
||||||
|
|
||||||
&:first-child {
|
|
||||||
padding-top: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.service-info {
|
|
||||||
.service-header {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
|
|
||||||
.service-name {
|
|
||||||
font-size: 15px;
|
|
||||||
font-weight: 500;
|
|
||||||
color: var(--td-text-color-primary);
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 8px;
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.service-controls {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 8px;
|
|
||||||
flex-shrink: 0;
|
|
||||||
|
|
||||||
.more-btn {
|
|
||||||
color: var(--td-text-color-placeholder);
|
|
||||||
padding: 4px;
|
|
||||||
transition: all 0.2s;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
color: var(--td-text-color-primary);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.service-description {
|
|
||||||
font-size: 13px;
|
|
||||||
color: var(--td-text-color-secondary);
|
|
||||||
margin-bottom: 8px;
|
|
||||||
line-height: 1.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.service-meta {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 12px;
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--td-text-color-placeholder);
|
|
||||||
|
|
||||||
.meta-item {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 4px;
|
|
||||||
|
|
||||||
.meta-icon {
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,22 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="model-settings">
|
<div class="model-settings">
|
||||||
<div class="section-header">
|
<div class="section-header">
|
||||||
<h2>{{ $t('modelSettings.title') }}</h2>
|
<div class="section-header__top">
|
||||||
<p class="section-description">{{ $t('modelSettings.description') }}</p>
|
<div class="section-header__text">
|
||||||
|
<h2>{{ $t('modelSettings.title') }}</h2>
|
||||||
|
<p class="section-description">{{ $t('modelSettings.description') }}</p>
|
||||||
|
</div>
|
||||||
|
<t-dropdown
|
||||||
|
:options="addModelOptions"
|
||||||
|
placement="bottom-right"
|
||||||
|
@click="(data: any) => openAddDialog(data.value)"
|
||||||
|
>
|
||||||
|
<t-button theme="primary" size="small">
|
||||||
|
<template #icon><add-icon /></template>
|
||||||
|
{{ $t('modelSettings.actions.addModel') }}
|
||||||
|
</t-button>
|
||||||
|
</t-dropdown>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="builtin-models-hint" role="note">
|
<div class="builtin-models-hint" role="note">
|
||||||
<p class="builtin-hint-label">{{ $t('modelSettings.builtinModels.title') }}</p>
|
<p class="builtin-hint-label">{{ $t('modelSettings.builtinModels.title') }}</p>
|
||||||
@@ -18,267 +32,66 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 对话模型 -->
|
<t-tabs v-model="activeTypeFilter" class="model-type-tabs">
|
||||||
<div class="settings-group model-type-group" data-model-type="chat">
|
<t-tab-panel value="all" :label="`${$t('common.all')}(${allLegacyModels.length})`" />
|
||||||
<div class="section-subheader">
|
<t-tab-panel value="chat" :label="`${$t('modelSettings.typeShort.chat')}(${countByType('chat')})`" />
|
||||||
<div class="subheader-text">
|
<t-tab-panel value="embedding" :label="`${$t('modelSettings.typeShort.embedding')}(${countByType('embedding')})`" />
|
||||||
<h3>{{ $t('modelSettings.chat.title') }}</h3>
|
<t-tab-panel value="rerank" :label="`${$t('modelSettings.typeShort.rerank')}(${countByType('rerank')})`" />
|
||||||
<p class="section-desc">{{ $t('modelSettings.chat.desc') }}</p>
|
<t-tab-panel value="vllm" :label="`${$t('modelSettings.typeShort.vllm')}(${countByType('vllm')})`" />
|
||||||
</div>
|
<t-tab-panel value="asr" :label="`${$t('modelSettings.typeShort.asr')}(${countByType('asr')})`" />
|
||||||
<t-button theme="primary" size="small" @click="openAddDialog('chat')">
|
</t-tabs>
|
||||||
<template #icon>
|
|
||||||
<add-icon />
|
|
||||||
</template>
|
|
||||||
{{ $t('modelSettings.actions.addModel') }}
|
|
||||||
</t-button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="chatModels.length > 0" class="model-list-container">
|
<div v-if="filteredModels.length > 0" class="model-grid">
|
||||||
<div v-for="model in chatModels" :key="model.id" class="model-card" :class="{ 'builtin-model': model.isBuiltin }">
|
<SettingCard
|
||||||
<div class="model-info">
|
v-for="model in filteredModels"
|
||||||
<div class="model-name">
|
:key="`${model._modelType}-${model.id}`"
|
||||||
{{ model.name }}
|
:title="model.name"
|
||||||
<t-tag v-if="model.isBuiltin" theme="primary" size="small">{{ $t('modelSettings.builtinTag') }}</t-tag>
|
:disabled="model.isBuiltin"
|
||||||
</div>
|
:actions="getModelOptions(model._modelType, model)"
|
||||||
<div class="model-meta">
|
@action="(value: string) => handleMenuAction({ value }, model._modelType, model)"
|
||||||
<span class="source-tag">{{ model.source === 'local' ? 'Ollama' : $t('modelSettings.source.remote') }}</span>
|
>
|
||||||
<!-- <span class="model-id">{{ model.modelName }}</span> -->
|
<template #tags>
|
||||||
</div>
|
<t-tag size="small" variant="light" :class="`model-type-tag model-type-tag--${model._modelType}`">
|
||||||
</div>
|
{{ typeLabel(model._modelType) }}
|
||||||
<div class="model-actions">
|
</t-tag>
|
||||||
<t-dropdown
|
<t-tag size="small" variant="light-outline">
|
||||||
:options="getModelOptions('chat', model)"
|
{{ model.source === 'local' ? 'Ollama' : sourceLabel(model._modelType) }}
|
||||||
@click="(data: any) => handleMenuAction(data, 'chat', model)"
|
</t-tag>
|
||||||
placement="bottom-right"
|
<t-tag v-if="model.isBuiltin" theme="warning" size="small" variant="light">
|
||||||
attach="body"
|
{{ $t('modelSettings.builtinTag') }}
|
||||||
>
|
</t-tag>
|
||||||
<t-button variant="text" shape="square" size="small" class="more-btn">
|
</template>
|
||||||
<t-icon name="more" />
|
<template #meta>
|
||||||
</t-button>
|
<span v-if="model.baseUrl" class="model-meta-item" :title="model.baseUrl">
|
||||||
</t-dropdown>
|
<t-icon name="link" size="12px" />
|
||||||
</div>
|
<span class="model-meta-text">{{ model.baseUrl }}</span>
|
||||||
</div>
|
</span>
|
||||||
</div>
|
<span v-else-if="model.source === 'local'" class="model-meta-item">
|
||||||
<div v-else class="empty-models">
|
<t-icon name="desktop" size="12px" />
|
||||||
<p>{{ $t('modelSettings.chat.empty') }}</p>
|
<span>Ollama local</span>
|
||||||
<t-button theme="primary" size="small" @click="openAddDialog('chat')">
|
</span>
|
||||||
<template #icon>
|
<span v-if="model._modelType === 'embedding' && model.dimension" class="model-meta-item">
|
||||||
<add-icon />
|
{{ $t('model.editor.dimensionLabel') }}: {{ model.dimension }}
|
||||||
</template>
|
</span>
|
||||||
{{ $t('modelSettings.actions.addModel') }}
|
</template>
|
||||||
</t-button>
|
</SettingCard>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-else class="empty-state">
|
||||||
|
<t-empty :description="emptyHint">
|
||||||
|
<t-dropdown
|
||||||
|
:options="addModelOptions"
|
||||||
|
placement="bottom"
|
||||||
|
@click="(data: any) => openAddDialog(data.value)"
|
||||||
|
>
|
||||||
|
<t-button theme="primary" size="small">
|
||||||
|
<template #icon><add-icon /></template>
|
||||||
|
{{ $t('modelSettings.actions.addModel') }}
|
||||||
|
</t-button>
|
||||||
|
</t-dropdown>
|
||||||
|
</t-empty>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Embedding 模型 -->
|
<!-- 模型编辑器抽屉 -->
|
||||||
<div class="settings-group model-type-group" data-model-type="embedding">
|
|
||||||
<div class="section-subheader">
|
|
||||||
<div class="subheader-text">
|
|
||||||
<h3>{{ $t('modelSettings.embedding.title') }}</h3>
|
|
||||||
<p class="section-desc">{{ $t('modelSettings.embedding.desc') }}</p>
|
|
||||||
</div>
|
|
||||||
<t-button theme="primary" size="small" @click="openAddDialog('embedding')">
|
|
||||||
<template #icon>
|
|
||||||
<add-icon />
|
|
||||||
</template>
|
|
||||||
{{ $t('modelSettings.actions.addModel') }}
|
|
||||||
</t-button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="embeddingModels.length > 0" class="model-list-container">
|
|
||||||
<div v-for="model in embeddingModels" :key="model.id" class="model-card" :class="{ 'builtin-model': model.isBuiltin }">
|
|
||||||
<div class="model-info">
|
|
||||||
<div class="model-name">
|
|
||||||
{{ model.name }}
|
|
||||||
<t-tag v-if="model.isBuiltin" theme="primary" size="small">{{ $t('modelSettings.builtinTag') }}</t-tag>
|
|
||||||
</div>
|
|
||||||
<div class="model-meta">
|
|
||||||
<span class="source-tag">{{ model.source === 'local' ? 'Ollama' : $t('modelSettings.source.remote') }}</span>
|
|
||||||
<!-- <span class="model-id">{{ model.modelName }}</span> -->
|
|
||||||
<span v-if="model.dimension" class="dimension">{{ $t('model.editor.dimensionLabel') }}: {{ model.dimension }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="model-actions">
|
|
||||||
<t-dropdown
|
|
||||||
:options="getModelOptions('embedding', model)"
|
|
||||||
@click="(data: any) => handleMenuAction(data, 'embedding', model)"
|
|
||||||
placement="bottom-right"
|
|
||||||
attach="body"
|
|
||||||
>
|
|
||||||
<t-button variant="text" shape="square" size="small" class="more-btn">
|
|
||||||
<t-icon name="more" />
|
|
||||||
</t-button>
|
|
||||||
</t-dropdown>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-else class="empty-models">
|
|
||||||
<p>{{ $t('modelSettings.embedding.empty') }}</p>
|
|
||||||
<t-button theme="primary" size="small" @click="openAddDialog('embedding')">
|
|
||||||
<template #icon>
|
|
||||||
<add-icon />
|
|
||||||
</template>
|
|
||||||
{{ $t('modelSettings.actions.addModel') }}
|
|
||||||
</t-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- ReRank 模型 -->
|
|
||||||
<div class="settings-group model-type-group" data-model-type="rerank">
|
|
||||||
<div class="section-subheader">
|
|
||||||
<div class="subheader-text">
|
|
||||||
<h3>{{ $t('modelSettings.rerank.title') }}</h3>
|
|
||||||
<p class="section-desc">{{ $t('modelSettings.rerank.desc') }}</p>
|
|
||||||
</div>
|
|
||||||
<t-button theme="primary" size="small" @click="openAddDialog('rerank')">
|
|
||||||
<template #icon>
|
|
||||||
<add-icon />
|
|
||||||
</template>
|
|
||||||
{{ $t('modelSettings.actions.addModel') }}
|
|
||||||
</t-button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="rerankModels.length > 0" class="model-list-container">
|
|
||||||
<div v-for="model in rerankModels" :key="model.id" class="model-card" :class="{ 'builtin-model': model.isBuiltin }">
|
|
||||||
<div class="model-info">
|
|
||||||
<div class="model-name">
|
|
||||||
{{ model.name }}
|
|
||||||
<t-tag v-if="model.isBuiltin" theme="primary" size="small">{{ $t('modelSettings.builtinTag') }}</t-tag>
|
|
||||||
</div>
|
|
||||||
<div class="model-meta">
|
|
||||||
<span class="source-tag">{{ model.source === 'local' ? 'Ollama' : $t('modelSettings.source.remote') }}</span>
|
|
||||||
<!-- <span class="model-id">{{ model.modelName }}</span> -->
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="model-actions">
|
|
||||||
<t-dropdown
|
|
||||||
:options="getModelOptions('rerank', model)"
|
|
||||||
@click="(data: any) => handleMenuAction(data, 'rerank', model)"
|
|
||||||
placement="bottom-right"
|
|
||||||
attach="body"
|
|
||||||
>
|
|
||||||
<t-button variant="text" shape="square" size="small" class="more-btn">
|
|
||||||
<t-icon name="more" />
|
|
||||||
</t-button>
|
|
||||||
</t-dropdown>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-else class="empty-models">
|
|
||||||
<p>{{ $t('modelSettings.rerank.empty') }}</p>
|
|
||||||
<t-button theme="primary" size="small" @click="openAddDialog('rerank')">
|
|
||||||
<template #icon>
|
|
||||||
<add-icon />
|
|
||||||
</template>
|
|
||||||
{{ $t('modelSettings.actions.addModel') }}
|
|
||||||
</t-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- VLLM 视觉模型 -->
|
|
||||||
<div class="settings-group model-type-group" data-model-type="vllm">
|
|
||||||
<div class="section-subheader">
|
|
||||||
<div class="subheader-text">
|
|
||||||
<h3>{{ $t('modelSettings.vllm.title') }}</h3>
|
|
||||||
<p class="section-desc">{{ $t('modelSettings.vllm.desc') }}</p>
|
|
||||||
</div>
|
|
||||||
<t-button theme="primary" size="small" @click="openAddDialog('vllm')">
|
|
||||||
<template #icon>
|
|
||||||
<add-icon />
|
|
||||||
</template>
|
|
||||||
{{ $t('modelSettings.actions.addModel') }}
|
|
||||||
</t-button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="vllmModels.length > 0" class="model-list-container">
|
|
||||||
<div v-for="model in vllmModels" :key="model.id" class="model-card" :class="{ 'builtin-model': model.isBuiltin }">
|
|
||||||
<div class="model-info">
|
|
||||||
<div class="model-name">
|
|
||||||
{{ model.name }}
|
|
||||||
<t-tag v-if="model.isBuiltin" theme="primary" size="small">{{ $t('modelSettings.builtinTag') }}</t-tag>
|
|
||||||
</div>
|
|
||||||
<div class="model-meta">
|
|
||||||
<span class="source-tag">{{ model.source === 'local' ? 'Ollama' : $t('modelSettings.source.openaiCompatible') }}</span>
|
|
||||||
<!-- <span class="model-id">{{ model.modelName }}</span> -->
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="model-actions">
|
|
||||||
<t-dropdown
|
|
||||||
:options="getModelOptions('vllm', model)"
|
|
||||||
@click="(data: any) => handleMenuAction(data, 'vllm', model)"
|
|
||||||
placement="bottom-right"
|
|
||||||
attach="body"
|
|
||||||
>
|
|
||||||
<t-button variant="text" shape="square" size="small" class="more-btn">
|
|
||||||
<t-icon name="more" />
|
|
||||||
</t-button>
|
|
||||||
</t-dropdown>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-else class="empty-models">
|
|
||||||
<p>{{ $t('modelSettings.vllm.empty') }}</p>
|
|
||||||
<t-button theme="primary" size="small" @click="openAddDialog('vllm')">
|
|
||||||
<template #icon>
|
|
||||||
<add-icon />
|
|
||||||
</template>
|
|
||||||
{{ $t('modelSettings.actions.addModel') }}
|
|
||||||
</t-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- STT 语音模型 -->
|
|
||||||
<div class="settings-group model-type-group" data-model-type="asr">
|
|
||||||
<div class="section-subheader">
|
|
||||||
<div class="subheader-text">
|
|
||||||
<h3>{{ $t('modelSettings.asr.title') }}</h3>
|
|
||||||
<p class="section-desc">{{ $t('modelSettings.asr.desc') }}</p>
|
|
||||||
</div>
|
|
||||||
<t-button theme="primary" size="small" @click="openAddDialog('asr')">
|
|
||||||
<template #icon>
|
|
||||||
<add-icon />
|
|
||||||
</template>
|
|
||||||
{{ $t('modelSettings.actions.addModel') }}
|
|
||||||
</t-button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="asrModels.length > 0" class="model-list-container">
|
|
||||||
<div v-for="model in asrModels" :key="model.id" class="model-card" :class="{ 'builtin-model': model.isBuiltin }">
|
|
||||||
<div class="model-info">
|
|
||||||
<div class="model-name">
|
|
||||||
{{ model.name }}
|
|
||||||
<t-tag v-if="model.isBuiltin" theme="primary" size="small">{{ $t('modelSettings.builtinTag') }}</t-tag>
|
|
||||||
</div>
|
|
||||||
<div class="model-meta">
|
|
||||||
<span class="source-tag">{{ model.source === 'local' ? 'Ollama' : $t('modelSettings.source.openaiCompatible') }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="model-actions">
|
|
||||||
<t-dropdown
|
|
||||||
:options="getModelOptions('asr', model)"
|
|
||||||
@click="(data: any) => handleMenuAction(data, 'asr', model)"
|
|
||||||
placement="bottom-right"
|
|
||||||
attach="body"
|
|
||||||
>
|
|
||||||
<t-button variant="text" shape="square" size="small" class="more-btn">
|
|
||||||
<t-icon name="more" />
|
|
||||||
</t-button>
|
|
||||||
</t-dropdown>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-else class="empty-models">
|
|
||||||
<p>{{ $t('modelSettings.asr.empty') }}</p>
|
|
||||||
<t-button theme="primary" size="small" @click="openAddDialog('asr')">
|
|
||||||
<template #icon>
|
|
||||||
<add-icon />
|
|
||||||
</template>
|
|
||||||
{{ $t('modelSettings.actions.addModel') }}
|
|
||||||
</t-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 模型编辑器弹窗 -->
|
|
||||||
<ModelEditorDialog
|
<ModelEditorDialog
|
||||||
v-model:visible="showDialog"
|
v-model:visible="showDialog"
|
||||||
:model-type="currentModelType"
|
:model-type="currentModelType"
|
||||||
@@ -295,74 +108,107 @@ import { MessagePlugin } from 'tdesign-vue-next'
|
|||||||
import { AddIcon } from 'tdesign-icons-vue-next'
|
import { AddIcon } from 'tdesign-icons-vue-next'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import ModelEditorDialog from '@/components/ModelEditorDialog.vue'
|
import ModelEditorDialog from '@/components/ModelEditorDialog.vue'
|
||||||
|
import SettingCard from '@/components/settings/SettingCard.vue'
|
||||||
|
import { useConfirmDelete } from '@/components/settings/useConfirmDelete'
|
||||||
import { listModels, createModel, updateModel as updateModelAPI, deleteModel as deleteModelAPI, type ModelConfig } from '@/api/model'
|
import { listModels, createModel, updateModel as updateModelAPI, deleteModel as deleteModelAPI, type ModelConfig } from '@/api/model'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
const confirmDelete = useConfirmDelete()
|
||||||
|
|
||||||
|
type ModelType = 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr'
|
||||||
|
type FilterType = 'all' | ModelType
|
||||||
|
|
||||||
const showDialog = ref(false)
|
const showDialog = ref(false)
|
||||||
const currentModelType = ref<'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr'>('chat')
|
const currentModelType = ref<ModelType>('chat')
|
||||||
const editingModel = ref<any>(null)
|
const editingModel = ref<any>(null)
|
||||||
const loading = ref(true)
|
const loading = ref(true)
|
||||||
|
const activeTypeFilter = ref<FilterType>('all')
|
||||||
|
|
||||||
// 模型列表数据
|
// 模型列表数据
|
||||||
const allModels = ref<ModelConfig[]>([])
|
const allModels = ref<ModelConfig[]>([])
|
||||||
|
|
||||||
// 根据类型过滤模型
|
// 后端 type → 前端分组 type 的映射
|
||||||
const chatModels = computed(() =>
|
const backendTypeToModelType: Record<string, ModelType> = {
|
||||||
allModels.value
|
KnowledgeQA: 'chat',
|
||||||
.filter(m => m.type === 'KnowledgeQA')
|
Embedding: 'embedding',
|
||||||
.map(convertToLegacyFormat)
|
Rerank: 'rerank',
|
||||||
)
|
VLLM: 'vllm',
|
||||||
|
ASR: 'asr'
|
||||||
|
}
|
||||||
|
|
||||||
const embeddingModels = computed(() =>
|
// 将后端模型格式转换为旧的前端格式(附带 _modelType 便于渲染)
|
||||||
allModels.value
|
|
||||||
.filter(m => m.type === 'Embedding')
|
|
||||||
.map(convertToLegacyFormat)
|
|
||||||
)
|
|
||||||
|
|
||||||
const rerankModels = computed(() =>
|
|
||||||
allModels.value
|
|
||||||
.filter(m => m.type === 'Rerank')
|
|
||||||
.map(convertToLegacyFormat)
|
|
||||||
)
|
|
||||||
|
|
||||||
const vllmModels = computed(() =>
|
|
||||||
allModels.value
|
|
||||||
.filter(m => m.type === 'VLLM')
|
|
||||||
.map(convertToLegacyFormat)
|
|
||||||
)
|
|
||||||
|
|
||||||
const asrModels = computed(() =>
|
|
||||||
allModels.value
|
|
||||||
.filter(m => m.type === 'ASR')
|
|
||||||
.map(convertToLegacyFormat)
|
|
||||||
)
|
|
||||||
|
|
||||||
// 将后端模型格式转换为旧的前端格式
|
|
||||||
function convertToLegacyFormat(model: ModelConfig) {
|
function convertToLegacyFormat(model: ModelConfig) {
|
||||||
return {
|
return {
|
||||||
id: model.id!,
|
id: model.id!,
|
||||||
name: model.name,
|
name: model.name,
|
||||||
source: model.source,
|
source: model.source,
|
||||||
modelName: model.name, // 显示名称作为模型名
|
modelName: model.name,
|
||||||
baseUrl: model.parameters.base_url || '',
|
baseUrl: model.parameters.base_url || '',
|
||||||
apiKey: model.parameters.api_key || '',
|
apiKey: model.parameters.api_key || '',
|
||||||
provider: model.parameters.provider || '', // 添加 provider 字段
|
provider: model.parameters.provider || '',
|
||||||
dimension: model.parameters.embedding_parameters?.dimension,
|
dimension: model.parameters.embedding_parameters?.dimension,
|
||||||
isBuiltin: model.is_builtin || false,
|
isBuiltin: model.is_builtin || false,
|
||||||
supportsVision: model.parameters.supports_vision || false,
|
supportsVision: model.parameters.supports_vision || false,
|
||||||
// 将后端 map 形式转换为前端可编辑的数组形式
|
|
||||||
customHeaders: model.parameters.custom_headers
|
customHeaders: model.parameters.custom_headers
|
||||||
? Object.entries(model.parameters.custom_headers).map(([key, value]) => ({ key, value: String(value) }))
|
? Object.entries(model.parameters.custom_headers).map(([key, value]) => ({ key, value: String(value) }))
|
||||||
: []
|
: [],
|
||||||
|
_modelType: backendTypeToModelType[model.type] || 'chat' as ModelType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 平铺 + 过滤
|
||||||
|
const allLegacyModels = computed(() => allModels.value.map(convertToLegacyFormat))
|
||||||
|
const filteredModels = computed(() => {
|
||||||
|
if (activeTypeFilter.value === 'all') return allLegacyModels.value
|
||||||
|
return allLegacyModels.value.filter(m => m._modelType === activeTypeFilter.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const countByType = (type: ModelType) => allLegacyModels.value.filter(m => m._modelType === type).length
|
||||||
|
|
||||||
|
// "+新增模型" 下拉菜单
|
||||||
|
const addModelOptions = computed(() => ([
|
||||||
|
{ content: t('modelSettings.typeShort.chat'), value: 'chat' },
|
||||||
|
{ content: t('modelSettings.typeShort.embedding'), value: 'embedding' },
|
||||||
|
{ content: t('modelSettings.typeShort.rerank'), value: 'rerank' },
|
||||||
|
{ content: t('modelSettings.typeShort.vllm'), value: 'vllm' },
|
||||||
|
{ content: t('modelSettings.typeShort.asr'), value: 'asr' }
|
||||||
|
]))
|
||||||
|
|
||||||
|
const typeLabel = (type: ModelType) => {
|
||||||
|
const map: Record<ModelType, string> = {
|
||||||
|
chat: t('modelSettings.typeShort.chat'),
|
||||||
|
embedding: t('modelSettings.typeShort.embedding'),
|
||||||
|
rerank: t('modelSettings.typeShort.rerank'),
|
||||||
|
vllm: t('modelSettings.typeShort.vllm'),
|
||||||
|
asr: t('modelSettings.typeShort.asr')
|
||||||
|
}
|
||||||
|
return map[type]
|
||||||
|
}
|
||||||
|
|
||||||
|
const sourceLabel = (type: ModelType) => {
|
||||||
|
// vllm / asr 的 remote 文案特殊,其余走通用 remote 文案
|
||||||
|
if (type === 'vllm' || type === 'asr') {
|
||||||
|
return t('modelSettings.source.openaiCompatible')
|
||||||
|
}
|
||||||
|
return t('modelSettings.source.remote')
|
||||||
|
}
|
||||||
|
|
||||||
|
const emptyHint = computed(() => {
|
||||||
|
if (activeTypeFilter.value === 'all') return t('modelSettings.chat.empty')
|
||||||
|
const map: Record<ModelType, string> = {
|
||||||
|
chat: t('modelSettings.chat.empty'),
|
||||||
|
embedding: t('modelSettings.embedding.empty'),
|
||||||
|
rerank: t('modelSettings.rerank.empty'),
|
||||||
|
vllm: t('modelSettings.vllm.empty'),
|
||||||
|
asr: t('modelSettings.asr.empty')
|
||||||
|
}
|
||||||
|
return map[activeTypeFilter.value as ModelType]
|
||||||
|
})
|
||||||
|
|
||||||
// 加载模型列表
|
// 加载模型列表
|
||||||
const loadModels = async () => {
|
const loadModels = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
// 直接获取所有模型,不分类型
|
|
||||||
const models = await listModels()
|
const models = await listModels()
|
||||||
allModels.value = models
|
allModels.value = models
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -374,15 +220,14 @@ const loadModels = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 打开添加对话框
|
// 打开添加对话框
|
||||||
const openAddDialog = (type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr') => {
|
const openAddDialog = (type: ModelType) => {
|
||||||
currentModelType.value = type
|
currentModelType.value = type
|
||||||
editingModel.value = null
|
editingModel.value = null
|
||||||
showDialog.value = true
|
showDialog.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 编辑模型
|
// 编辑模型
|
||||||
const editModel = (type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr', model: any) => {
|
const editModel = (type: ModelType, model: any) => {
|
||||||
// 内置模型不能编辑
|
|
||||||
if (model.isBuiltin) {
|
if (model.isBuiltin) {
|
||||||
MessagePlugin.warning(t('modelSettings.toasts.builtinCannotEdit'))
|
MessagePlugin.warning(t('modelSettings.toasts.builtinCannotEdit'))
|
||||||
return
|
return
|
||||||
@@ -395,7 +240,6 @@ const editModel = (type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr', model
|
|||||||
// 保存模型
|
// 保存模型
|
||||||
const handleModelSave = async (modelData: any) => {
|
const handleModelSave = async (modelData: any) => {
|
||||||
try {
|
try {
|
||||||
// 字段校验
|
|
||||||
if (!modelData.modelName || !modelData.modelName.trim()) {
|
if (!modelData.modelName || !modelData.modelName.trim()) {
|
||||||
MessagePlugin.warning(t('modelSettings.toasts.nameRequired'))
|
MessagePlugin.warning(t('modelSettings.toasts.nameRequired'))
|
||||||
return
|
return
|
||||||
@@ -406,14 +250,12 @@ const handleModelSave = async (modelData: any) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remote 类型必须填写 baseUrl
|
|
||||||
if (modelData.source === 'remote') {
|
if (modelData.source === 'remote') {
|
||||||
if (!modelData.baseUrl || !modelData.baseUrl.trim()) {
|
if (!modelData.baseUrl || !modelData.baseUrl.trim()) {
|
||||||
MessagePlugin.warning(t('modelSettings.toasts.baseUrlRequired'))
|
MessagePlugin.warning(t('modelSettings.toasts.baseUrlRequired'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 校验 Base URL 格式
|
|
||||||
try {
|
try {
|
||||||
new URL(modelData.baseUrl.trim())
|
new URL(modelData.baseUrl.trim())
|
||||||
} catch {
|
} catch {
|
||||||
@@ -422,7 +264,6 @@ const handleModelSave = async (modelData: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Embedding 模型必须填写维度
|
|
||||||
if (currentModelType.value === 'embedding') {
|
if (currentModelType.value === 'embedding') {
|
||||||
if (!modelData.dimension || modelData.dimension < 128 || modelData.dimension > 4096) {
|
if (!modelData.dimension || modelData.dimension < 128 || modelData.dimension > 4096) {
|
||||||
MessagePlugin.warning(t('modelSettings.toasts.dimensionInvalid'))
|
MessagePlugin.warning(t('modelSettings.toasts.dimensionInvalid'))
|
||||||
@@ -430,7 +271,6 @@ const handleModelSave = async (modelData: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将前端 Key-Value 数组形式的自定义 Header 转换成后端期望的 map
|
|
||||||
const customHeadersMap: Record<string, string> = {}
|
const customHeadersMap: Record<string, string> = {}
|
||||||
if (Array.isArray(modelData.customHeaders)) {
|
if (Array.isArray(modelData.customHeaders)) {
|
||||||
for (const item of modelData.customHeaders) {
|
for (const item of modelData.customHeaders) {
|
||||||
@@ -442,16 +282,15 @@ const handleModelSave = async (modelData: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将前端格式转换为后端格式
|
|
||||||
const apiModelData: ModelConfig = {
|
const apiModelData: ModelConfig = {
|
||||||
name: modelData.modelName.trim(), // 使用 modelName 作为 name,并去除首尾空格
|
name: modelData.modelName.trim(),
|
||||||
type: getModelType(currentModelType.value),
|
type: getModelType(currentModelType.value),
|
||||||
source: modelData.source,
|
source: modelData.source,
|
||||||
description: '',
|
description: '',
|
||||||
parameters: {
|
parameters: {
|
||||||
base_url: modelData.baseUrl?.trim() || '',
|
base_url: modelData.baseUrl?.trim() || '',
|
||||||
api_key: modelData.apiKey?.trim() || '',
|
api_key: modelData.apiKey?.trim() || '',
|
||||||
provider: modelData.provider || '', // 添加 provider 字段
|
provider: modelData.provider || '',
|
||||||
...(Object.keys(customHeadersMap).length > 0 ? { custom_headers: customHeadersMap } : {}),
|
...(Object.keys(customHeadersMap).length > 0 ? { custom_headers: customHeadersMap } : {}),
|
||||||
...(currentModelType.value === 'embedding' && modelData.dimension ? {
|
...(currentModelType.value === 'embedding' && modelData.dimension ? {
|
||||||
embedding_parameters: {
|
embedding_parameters: {
|
||||||
@@ -468,16 +307,14 @@ const handleModelSave = async (modelData: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (editingModel.value && editingModel.value.id) {
|
if (editingModel.value && editingModel.value.id) {
|
||||||
// 更新现有模型
|
|
||||||
await updateModelAPI(editingModel.value.id, apiModelData)
|
await updateModelAPI(editingModel.value.id, apiModelData)
|
||||||
MessagePlugin.success(t('modelSettings.toasts.updated'))
|
MessagePlugin.success(t('modelSettings.toasts.updated'))
|
||||||
} else {
|
} else {
|
||||||
// 添加新模型
|
|
||||||
await createModel(apiModelData)
|
await createModel(apiModelData)
|
||||||
MessagePlugin.success(t('modelSettings.toasts.added'))
|
MessagePlugin.success(t('modelSettings.toasts.added'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新加载模型列表
|
showDialog.value = false
|
||||||
await loadModels()
|
await loadModels()
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('保存模型失败:', error)
|
console.error('保存模型失败:', error)
|
||||||
@@ -486,8 +323,7 @@ const handleModelSave = async (modelData: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 删除模型
|
// 删除模型
|
||||||
const deleteModel = async (type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr', modelId: string) => {
|
const deleteModel = async (_type: ModelType, modelId: string) => {
|
||||||
// 检查是否是内置模型
|
|
||||||
const model = allModels.value.find(m => m.id === modelId)
|
const model = allModels.value.find(m => m.id === modelId)
|
||||||
if (model?.is_builtin) {
|
if (model?.is_builtin) {
|
||||||
MessagePlugin.warning(t('modelSettings.toasts.builtinCannotDelete'))
|
MessagePlugin.warning(t('modelSettings.toasts.builtinCannotDelete'))
|
||||||
@@ -497,7 +333,6 @@ const deleteModel = async (type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr
|
|||||||
try {
|
try {
|
||||||
await deleteModelAPI(modelId)
|
await deleteModelAPI(modelId)
|
||||||
MessagePlugin.success(t('modelSettings.toasts.deleted'))
|
MessagePlugin.success(t('modelSettings.toasts.deleted'))
|
||||||
// 重新加载模型列表
|
|
||||||
await loadModels()
|
await loadModels()
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('删除模型失败:', error)
|
console.error('删除模型失败:', error)
|
||||||
@@ -506,27 +341,23 @@ const deleteModel = async (type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取模型操作菜单选项
|
// 获取模型操作菜单选项
|
||||||
const getModelOptions = (type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr', model: any) => {
|
const getModelOptions = (type: ModelType, model: any) => {
|
||||||
const options: any[] = []
|
const options: any[] = []
|
||||||
|
|
||||||
// 内置模型不能编辑和删除
|
|
||||||
if (model.isBuiltin) {
|
if (model.isBuiltin) {
|
||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
|
||||||
// 编辑选项
|
|
||||||
options.push({
|
options.push({
|
||||||
content: t('common.edit'),
|
content: t('common.edit'),
|
||||||
value: `edit-${type}-${model.id}`
|
value: `edit-${type}-${model.id}`
|
||||||
})
|
})
|
||||||
|
|
||||||
// 复制选项
|
|
||||||
options.push({
|
options.push({
|
||||||
content: t('common.copy'),
|
content: t('common.copy'),
|
||||||
value: `copy-${type}-${model.id}`
|
value: `copy-${type}-${model.id}`
|
||||||
})
|
})
|
||||||
|
|
||||||
// 删除选项
|
|
||||||
options.push({
|
options.push({
|
||||||
content: t('common.delete'),
|
content: t('common.delete'),
|
||||||
value: `delete-${type}-${model.id}`,
|
value: `delete-${type}-${model.id}`,
|
||||||
@@ -537,7 +368,7 @@ const getModelOptions = (type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr',
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理菜单操作
|
// 处理菜单操作
|
||||||
const handleMenuAction = (data: { value: string }, type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr', model: any) => {
|
const handleMenuAction = (data: { value: string }, type: ModelType, model: any) => {
|
||||||
const value = data.value
|
const value = data.value
|
||||||
|
|
||||||
if (value.indexOf('edit-') === 0) {
|
if (value.indexOf('edit-') === 0) {
|
||||||
@@ -545,14 +376,14 @@ const handleMenuAction = (data: { value: string }, type: 'chat' | 'embedding' |
|
|||||||
} else if (value.indexOf('copy-') === 0) {
|
} else if (value.indexOf('copy-') === 0) {
|
||||||
copyModel(type, model.id)
|
copyModel(type, model.id)
|
||||||
} else if (value.indexOf('delete-') === 0) {
|
} else if (value.indexOf('delete-') === 0) {
|
||||||
// 使用确认对话框进行确认
|
confirmDelete({
|
||||||
if (confirm(t('modelSettings.confirmDelete'))) {
|
body: t('modelSettings.confirmDelete'),
|
||||||
deleteModel(type, model.id)
|
onConfirm: () => deleteModel(type, model.id)
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成不重复的复制名称:原名 + 复制后缀(若已存在则追加序号)
|
// 生成不重复的复制名称
|
||||||
const generateCopyName = (originalName: string): string => {
|
const generateCopyName = (originalName: string): string => {
|
||||||
const suffix = t('modelSettings.copySuffix')
|
const suffix = t('modelSettings.copySuffix')
|
||||||
const existingNames = new Set(allModels.value.map(m => m.name))
|
const existingNames = new Set(allModels.value.map(m => m.name))
|
||||||
@@ -566,7 +397,7 @@ const generateCopyName = (originalName: string): string => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 复制模型
|
// 复制模型
|
||||||
const copyModel = async (_type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr', modelId: string) => {
|
const copyModel = async (_type: ModelType, modelId: string) => {
|
||||||
const source = allModels.value.find(m => m.id === modelId)
|
const source = allModels.value.find(m => m.id === modelId)
|
||||||
if (!source) {
|
if (!source) {
|
||||||
return
|
return
|
||||||
@@ -595,7 +426,7 @@ const copyModel = async (_type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr'
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取后端模型类型
|
// 获取后端模型类型
|
||||||
function getModelType(type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr'): 'KnowledgeQA' | 'Embedding' | 'Rerank' | 'VLLM' | 'ASR' {
|
function getModelType(type: ModelType): 'KnowledgeQA' | 'Embedding' | 'Rerank' | 'VLLM' | 'ASR' {
|
||||||
const typeMap = {
|
const typeMap = {
|
||||||
chat: 'KnowledgeQA' as const,
|
chat: 'KnowledgeQA' as const,
|
||||||
embedding: 'Embedding' as const,
|
embedding: 'Embedding' as const,
|
||||||
@@ -606,7 +437,6 @@ function getModelType(type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr'): '
|
|||||||
return typeMap[type]
|
return typeMap[type]
|
||||||
}
|
}
|
||||||
|
|
||||||
// 组件挂载时加载模型列表
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadModels()
|
loadModels()
|
||||||
})
|
})
|
||||||
@@ -618,21 +448,7 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.section-header {
|
.section-header {
|
||||||
margin-bottom: 32px;
|
margin-bottom: 28px;
|
||||||
|
|
||||||
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 0 16px 0;
|
|
||||||
line-height: 1.5;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.builtin-models-hint {
|
.builtin-models-hint {
|
||||||
@@ -669,176 +485,127 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings-group {
|
.section-header__top {
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.model-type-group {
|
|
||||||
margin-bottom: 32px;
|
|
||||||
padding-bottom: 32px;
|
|
||||||
border-bottom: 1px solid var(--td-component-stroke);
|
|
||||||
|
|
||||||
&:last-of-type {
|
|
||||||
margin-bottom: 0;
|
|
||||||
padding-bottom: 0;
|
|
||||||
border-bottom: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.section-subheader {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
gap: 16px;
|
gap: 16px;
|
||||||
margin-bottom: 16px;
|
margin-bottom: 8px;
|
||||||
|
|
||||||
.subheader-text {
|
.section-header__text {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
h3 {
|
h2 {
|
||||||
font-size: 16px;
|
font-size: 20px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: var(--td-text-color-primary);
|
color: var(--td-text-color-primary);
|
||||||
margin: 0 0 4px 0;
|
margin: 0 0 8px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.section-desc {
|
.section-description {
|
||||||
font-size: 13px;
|
font-size: 14px;
|
||||||
color: var(--td-text-color-secondary);
|
color: var(--td-text-color-secondary);
|
||||||
margin: 0;
|
margin: 0;
|
||||||
line-height: 1.5;
|
line-height: 1.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
:deep(.t-button) {
|
:deep(.t-button) {
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
|
margin-top: 4px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.model-list-container {
|
.model-type-tabs {
|
||||||
display: flex;
|
margin-bottom: 16px;
|
||||||
flex-direction: column;
|
|
||||||
gap: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.model-card {
|
:deep(.t-tabs__nav-item) {
|
||||||
display: flex;
|
font-size: 13px;
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
padding: 14px 16px;
|
|
||||||
border: 1px solid var(--td-component-stroke);
|
|
||||||
border-radius: 8px;
|
|
||||||
background: var(--td-bg-color-container);
|
|
||||||
transition: border-color 0.2s ease, background-color 0.2s ease;
|
|
||||||
position: relative;
|
|
||||||
overflow: visible;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
border-color: var(--td-brand-color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&.builtin-model {
|
:deep(.t-tabs__nav-item-wrapper) {
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
padding: 0 12px;
|
||||||
border-color: var(--td-component-stroke);
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
border-color: var(--td-brand-color-light);
|
|
||||||
}
|
|
||||||
|
|
||||||
.model-info {
|
|
||||||
.model-name {
|
|
||||||
color: var(--td-text-color-secondary);
|
|
||||||
}
|
|
||||||
|
|
||||||
.model-meta {
|
|
||||||
.source-tag {
|
|
||||||
background: var(--td-bg-color-container);
|
|
||||||
color: var(--td-text-color-placeholder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.model-info {
|
|
||||||
flex: 1;
|
|
||||||
min-width: 0;
|
|
||||||
|
|
||||||
.model-name {
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: 500;
|
|
||||||
color: var(--td-text-color-primary);
|
|
||||||
margin-bottom: 6px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.model-meta {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 12px;
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--td-text-color-secondary);
|
|
||||||
|
|
||||||
.source-tag {
|
|
||||||
padding: 2px 8px;
|
|
||||||
background: var(--td-component-stroke);
|
|
||||||
border-radius: 3px;
|
|
||||||
font-size: 11px;
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.model-id {
|
|
||||||
font-family: monospace;
|
|
||||||
color: var(--td-text-color-secondary);
|
|
||||||
}
|
|
||||||
|
|
||||||
.dimension {
|
|
||||||
color: var(--td-text-color-placeholder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.model-actions {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 4px;
|
|
||||||
flex-shrink: 0;
|
|
||||||
position: relative;
|
|
||||||
z-index: 1001;
|
|
||||||
|
|
||||||
.more-btn {
|
|
||||||
color: var(--td-text-color-placeholder);
|
|
||||||
padding: 4px;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
color: var(--td-text-color-primary);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.empty-models {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
gap: 16px;
|
|
||||||
padding: 32px;
|
|
||||||
text-align: center;
|
|
||||||
color: var(--td-text-color-placeholder);
|
|
||||||
border: 1px dashed var(--td-component-stroke);
|
|
||||||
border-radius: 8px;
|
|
||||||
font-size: 14px;
|
|
||||||
|
|
||||||
p {
|
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:deep(.t-tabs__operations) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.t-tabs__nav-scroll) {
|
||||||
|
overflow-x: auto;
|
||||||
|
scrollbar-width: none;
|
||||||
|
|
||||||
|
&::-webkit-scrollbar {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.t-tabs__content) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-meta-item {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
max-width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
.model-meta-text {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5 种模型类型各自的 tag 配色
|
||||||
|
:deep(.model-type-tag) {
|
||||||
|
&--chat {
|
||||||
|
background: #E8F3FF;
|
||||||
|
color: #0052D9;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--embedding {
|
||||||
|
background: #F0E9FF;
|
||||||
|
color: #6235BB;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--rerank {
|
||||||
|
background: #FEF3E6;
|
||||||
|
color: #B85C00;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--vllm {
|
||||||
|
background: #FEECEC;
|
||||||
|
color: #C93E3E;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--asr {
|
||||||
|
background: #E7F7F2;
|
||||||
|
color: #118053;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
padding: 64px 0;
|
||||||
|
text-align: center;
|
||||||
|
|
||||||
|
:deep(.t-empty__description) {
|
||||||
|
font-size: 14px;
|
||||||
|
color: var(--td-text-color-placeholder);
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tag 样式优化
|
|
||||||
:deep(.t-tag) {
|
:deep(.t-tag) {
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
padding: 2px 8px;
|
padding: 2px 8px;
|
||||||
@@ -851,16 +618,9 @@ onMounted(() => {
|
|||||||
color: var(--td-brand-color);
|
color: var(--td-brand-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
&.t-tag--theme-success {
|
|
||||||
background: var(--td-success-color-light);
|
|
||||||
color: var(--td-brand-color-active);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.t-size-s {
|
&.t-size-s {
|
||||||
height: 20px;
|
height: 20px;
|
||||||
line-height: 16px;
|
line-height: 16px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dropdown 菜单样式已统一至 @/assets/dropdown-menu.less
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -5,141 +5,138 @@
|
|||||||
<p class="section-description">{{ t('webSearchSettings.description') }}</p>
|
<p class="section-description">{{ t('webSearchSettings.description') }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="settings-group">
|
<div class="settings-toolbar">
|
||||||
<div class="section-subheader">
|
<h3>{{ t('webSearchSettings.providersTitle') }}</h3>
|
||||||
<h3>{{ t('webSearchSettings.providersTitle') }}</h3>
|
<t-button theme="primary" size="small" @click="openAddDialog">
|
||||||
|
<template #icon><add-icon /></template>
|
||||||
|
{{ t('webSearchSettings.addProvider') }}
|
||||||
|
</t-button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Provider List -->
|
||||||
|
<div v-if="providerEntities.length > 0" class="provider-grid">
|
||||||
|
<SettingCard
|
||||||
|
v-for="entity in providerEntities"
|
||||||
|
:key="entity.id"
|
||||||
|
:title="entity.name"
|
||||||
|
:description="entity.description || ''"
|
||||||
|
:actions="getProviderOptions(entity)"
|
||||||
|
@action="(value: string) => handleMenuAction({ value }, entity)"
|
||||||
|
>
|
||||||
|
<template #tags>
|
||||||
|
<t-tag theme="primary" size="small" variant="light">
|
||||||
|
{{ entity.provider }}
|
||||||
|
</t-tag>
|
||||||
|
<t-tag v-if="entity.is_default" theme="success" size="small" variant="light">
|
||||||
|
{{ t('webSearchSettings.default') }}
|
||||||
|
</t-tag>
|
||||||
|
<t-tag v-if="isEntityFree(entity)" theme="warning" size="small" variant="light">
|
||||||
|
{{ t('webSearchSettings.free') }}
|
||||||
|
</t-tag>
|
||||||
|
</template>
|
||||||
|
<template #meta>
|
||||||
|
<span v-if="entity.parameters?.proxy_url" class="provider-meta-item" :title="entity.parameters.proxy_url">
|
||||||
|
<t-icon name="internet" size="12px" />
|
||||||
|
<span class="provider-meta-text">{{ entity.parameters.proxy_url }}</span>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</SettingCard>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Empty State -->
|
||||||
|
<div v-else class="empty-state">
|
||||||
|
<t-empty :description="t('webSearchSettings.noProvidersDesc')">
|
||||||
<t-button theme="primary" size="small" @click="openAddDialog">
|
<t-button theme="primary" size="small" @click="openAddDialog">
|
||||||
<template #icon><add-icon /></template>
|
<template #icon><add-icon /></template>
|
||||||
{{ t('webSearchSettings.addProvider') }}
|
{{ t('webSearchSettings.addProvider') }}
|
||||||
</t-button>
|
</t-button>
|
||||||
</div>
|
</t-empty>
|
||||||
|
|
||||||
<!-- Provider List -->
|
|
||||||
<div v-if="providerEntities.length > 0" class="provider-list">
|
|
||||||
<div v-for="entity in providerEntities" :key="entity.id" class="provider-item">
|
|
||||||
<div class="item-info">
|
|
||||||
<div class="item-header">
|
|
||||||
<span class="item-name">{{ entity.name }}</span>
|
|
||||||
<t-tag v-if="entity.is_default" theme="primary" size="small" variant="light">
|
|
||||||
{{ t('webSearchSettings.default') }}
|
|
||||||
</t-tag>
|
|
||||||
<t-tag size="small" variant="outline">{{ entity.provider }}</t-tag>
|
|
||||||
</div>
|
|
||||||
<div class="item-desc">{{ entity.description || t('webSearchSettings.noDescription') }}</div>
|
|
||||||
</div>
|
|
||||||
<div class="item-actions">
|
|
||||||
<t-button theme="default" variant="text" size="small" @click="testExistingConnection(entity)" :loading="testingId === entity.id">
|
|
||||||
{{ t('webSearchSettings.testConnection') }}
|
|
||||||
</t-button>
|
|
||||||
<t-button theme="primary" variant="text" size="small" @click="editProvider(entity)">
|
|
||||||
{{ t('common.edit') }}
|
|
||||||
</t-button>
|
|
||||||
<t-popconfirm :content="t('webSearchSettings.deleteConfirm')" @confirm="deleteProvider(entity.id!)">
|
|
||||||
<t-button theme="danger" variant="text" size="small">
|
|
||||||
{{ t('common.delete') }}
|
|
||||||
</t-button>
|
|
||||||
</t-popconfirm>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Empty State -->
|
|
||||||
<div v-else class="empty-providers">
|
|
||||||
<p>{{ t('webSearchSettings.noProvidersDesc') }}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Add/Edit Dialog -->
|
<!-- Add/Edit Drawer -->
|
||||||
<t-dialog
|
<SettingDrawer
|
||||||
v-model:visible="showAddProviderDialog"
|
v-model:visible="showAddProviderDialog"
|
||||||
:header="editingProvider ? t('webSearchSettings.editProvider') : t('webSearchSettings.addProvider')"
|
:title="editingProvider ? t('webSearchSettings.editProvider') : t('webSearchSettings.addProvider')"
|
||||||
width="520px"
|
:confirm-loading="saving"
|
||||||
:footer="false"
|
@confirm="saveProvider"
|
||||||
destroy-on-close
|
|
||||||
>
|
>
|
||||||
<div class="dialog-form-container">
|
<t-form ref="formRef" :data="providerForm" label-align="top" class="provider-form">
|
||||||
<t-form :data="providerForm" label-align="top" @submit="saveProvider" class="provider-form">
|
<t-form-item :label="t('webSearchSettings.providerTypeLabel')" name="provider">
|
||||||
<t-form-item :label="t('webSearchSettings.providerTypeLabel')" name="provider">
|
<t-select v-model="providerForm.provider" :disabled="!!editingProvider" @change="onProviderTypeChange">
|
||||||
<t-select v-model="providerForm.provider" :disabled="!!editingProvider" @change="onProviderTypeChange">
|
<t-option v-for="pt in providerTypes" :key="pt.id" :value="pt.id" :label="pt.name">
|
||||||
<t-option v-for="pt in providerTypes" :key="pt.id" :value="pt.id" :label="pt.name">
|
<div class="provider-option">
|
||||||
<div class="provider-option">
|
<span>{{ pt.name }}</span>
|
||||||
<span>{{ pt.name }}</span>
|
<t-tag v-if="isProviderFree(pt)" theme="success" size="small" variant="light">
|
||||||
<t-tag v-if="isProviderFree(pt)" theme="success" size="small" variant="light">{{ t('webSearchSettings.free') }}</t-tag>
|
{{ t('webSearchSettings.free') }}
|
||||||
</div>
|
</t-tag>
|
||||||
</t-option>
|
</div>
|
||||||
</t-select>
|
</t-option>
|
||||||
</t-form-item>
|
</t-select>
|
||||||
|
</t-form-item>
|
||||||
|
|
||||||
<t-form-item :label="t('webSearchSettings.providerNameLabel')" name="name">
|
<t-form-item :label="t('webSearchSettings.providerNameLabel')" name="name">
|
||||||
<t-input v-model="providerForm.name" :placeholder="selectedProviderType?.name || t('webSearchSettings.providerNamePlaceholder')" />
|
<t-input v-model="providerForm.name" :placeholder="selectedProviderType?.name || t('webSearchSettings.providerNamePlaceholder')" />
|
||||||
</t-form-item>
|
</t-form-item>
|
||||||
|
|
||||||
<t-form-item :label="t('webSearchSettings.providerDescLabel')" name="description">
|
<t-form-item :label="t('webSearchSettings.providerDescLabel')" name="description">
|
||||||
<t-input v-model="providerForm.description" :placeholder="t('webSearchSettings.providerDescPlaceholder')" />
|
<t-input v-model="providerForm.description" :placeholder="t('webSearchSettings.providerDescPlaceholder')" />
|
||||||
</t-form-item>
|
</t-form-item>
|
||||||
|
|
||||||
<template v-if="selectedProviderType?.requires_api_key || selectedProviderType?.requires_engine_id">
|
|
||||||
<div class="form-divider"></div>
|
|
||||||
|
|
||||||
<div class="credentials-hint" v-if="selectedProviderType?.docs_url">
|
|
||||||
<a :href="selectedProviderType.docs_url" target="_blank" rel="noopener noreferrer">
|
|
||||||
{{ t('webSearchSettings.viewDocs') }} ↗
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<t-form-item v-if="selectedProviderType?.requires_api_key" :label="t('webSearchSettings.apiKeyLabel')" name="parameters.api_key">
|
|
||||||
<t-input
|
|
||||||
v-model="providerForm.parameters.api_key"
|
|
||||||
type="password"
|
|
||||||
:placeholder="editingProvider ? t('webSearchSettings.apiKeyUnchanged') : t('webSearchSettings.apiKeyPlaceholder')"
|
|
||||||
/>
|
|
||||||
</t-form-item>
|
|
||||||
<t-form-item v-if="selectedProviderType?.requires_engine_id" :label="t('webSearchSettings.engineIdLabel')" name="parameters.engine_id">
|
|
||||||
<t-input v-model="providerForm.parameters.engine_id" :placeholder="t('webSearchSettings.engineIdLabel')" />
|
|
||||||
</t-form-item>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<t-form-item v-if="selectedProviderType?.supports_proxy" :label="t('webSearchSettings.proxyUrlLabel')" name="parameters.proxy_url">
|
|
||||||
<t-input
|
|
||||||
v-model="providerForm.parameters.proxy_url"
|
|
||||||
:placeholder="t('webSearchSettings.proxyUrlPlaceholder')"
|
|
||||||
/>
|
|
||||||
<template #help>
|
|
||||||
<span class="switch-help">{{ t('webSearchSettings.proxyUrlHelp') }}</span>
|
|
||||||
</template>
|
|
||||||
</t-form-item>
|
|
||||||
|
|
||||||
|
<template v-if="selectedProviderType?.requires_api_key || selectedProviderType?.requires_engine_id">
|
||||||
<div class="form-divider"></div>
|
<div class="form-divider"></div>
|
||||||
|
|
||||||
<t-form-item :label="t('webSearchSettings.setAsDefault')" name="is_default">
|
<div class="credentials-hint" v-if="selectedProviderType?.docs_url">
|
||||||
<template #help>
|
<a :href="selectedProviderType.docs_url" target="_blank" rel="noopener noreferrer">
|
||||||
<div class="switch-help">
|
{{ t('webSearchSettings.viewDocs') }} ↗
|
||||||
{{ t('webSearchSettings.setAsDefaultDesc') }}
|
</a>
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<t-switch v-model="providerForm.is_default" />
|
|
||||||
</t-form-item>
|
|
||||||
|
|
||||||
<div class="dialog-footer">
|
|
||||||
<div class="footer-left">
|
|
||||||
<t-button
|
|
||||||
v-if="selectedProviderType && !isProviderFree(selectedProviderType)"
|
|
||||||
theme="default"
|
|
||||||
variant="outline"
|
|
||||||
:loading="testing"
|
|
||||||
@click="testConnection"
|
|
||||||
>
|
|
||||||
{{ testing ? t('webSearchSettings.testing') : t('webSearchSettings.testConnection') }}
|
|
||||||
</t-button>
|
|
||||||
</div>
|
|
||||||
<div class="footer-right">
|
|
||||||
<t-button theme="default" variant="base" @click="showAddProviderDialog = false">{{ t('common.cancel') }}</t-button>
|
|
||||||
<t-button theme="primary" type="submit" :loading="saving">{{ t('common.save') }}</t-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</t-form>
|
|
||||||
</div>
|
<t-form-item v-if="selectedProviderType?.requires_api_key" :label="t('webSearchSettings.apiKeyLabel')" name="parameters.api_key">
|
||||||
</t-dialog>
|
<t-input
|
||||||
|
v-model="providerForm.parameters.api_key"
|
||||||
|
type="password"
|
||||||
|
:placeholder="editingProvider ? t('webSearchSettings.apiKeyUnchanged') : t('webSearchSettings.apiKeyPlaceholder')"
|
||||||
|
/>
|
||||||
|
</t-form-item>
|
||||||
|
<t-form-item v-if="selectedProviderType?.requires_engine_id" :label="t('webSearchSettings.engineIdLabel')" name="parameters.engine_id">
|
||||||
|
<t-input v-model="providerForm.parameters.engine_id" :placeholder="t('webSearchSettings.engineIdLabel')" />
|
||||||
|
</t-form-item>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<t-form-item v-if="selectedProviderType?.supports_proxy" :label="t('webSearchSettings.proxyUrlLabel')" name="parameters.proxy_url">
|
||||||
|
<t-input
|
||||||
|
v-model="providerForm.parameters.proxy_url"
|
||||||
|
:placeholder="t('webSearchSettings.proxyUrlPlaceholder')"
|
||||||
|
/>
|
||||||
|
<template #help>
|
||||||
|
<span class="switch-help">{{ t('webSearchSettings.proxyUrlHelp') }}</span>
|
||||||
|
</template>
|
||||||
|
</t-form-item>
|
||||||
|
|
||||||
|
<div class="form-divider"></div>
|
||||||
|
|
||||||
|
<t-form-item :label="t('webSearchSettings.setAsDefault')" name="is_default">
|
||||||
|
<template #help>
|
||||||
|
<div class="switch-help">
|
||||||
|
{{ t('webSearchSettings.setAsDefaultDesc') }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<t-switch v-model="providerForm.is_default" />
|
||||||
|
</t-form-item>
|
||||||
|
</t-form>
|
||||||
|
|
||||||
|
<template #footer-left>
|
||||||
|
<t-button
|
||||||
|
v-if="selectedProviderType && !isProviderFree(selectedProviderType)"
|
||||||
|
theme="default"
|
||||||
|
variant="outline"
|
||||||
|
:loading="testing"
|
||||||
|
@click="testConnection"
|
||||||
|
>
|
||||||
|
{{ testing ? t('webSearchSettings.testing') : t('webSearchSettings.testConnection') }}
|
||||||
|
</t-button>
|
||||||
|
</template>
|
||||||
|
</SettingDrawer>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -158,8 +155,12 @@ import {
|
|||||||
type WebSearchProviderEntity,
|
type WebSearchProviderEntity,
|
||||||
type WebSearchProviderTypeInfo,
|
type WebSearchProviderTypeInfo,
|
||||||
} from '@/api/web-search-provider'
|
} from '@/api/web-search-provider'
|
||||||
|
import SettingCard from '@/components/settings/SettingCard.vue'
|
||||||
|
import SettingDrawer from '@/components/settings/SettingDrawer.vue'
|
||||||
|
import { useConfirmDelete } from '@/components/settings/useConfirmDelete'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
const confirmDelete = useConfirmDelete()
|
||||||
|
|
||||||
// ===== State =====
|
// ===== State =====
|
||||||
const providerEntities = ref<WebSearchProviderEntity[]>([])
|
const providerEntities = ref<WebSearchProviderEntity[]>([])
|
||||||
@@ -169,6 +170,7 @@ const editingProvider = ref<WebSearchProviderEntity | null>(null)
|
|||||||
const testing = ref(false)
|
const testing = ref(false)
|
||||||
const testingId = ref<string | null>(null)
|
const testingId = ref<string | null>(null)
|
||||||
const saving = ref(false)
|
const saving = ref(false)
|
||||||
|
const formRef = ref<any>()
|
||||||
|
|
||||||
const providerForm = ref<{
|
const providerForm = ref<{
|
||||||
name: string
|
name: string
|
||||||
@@ -193,6 +195,11 @@ const isProviderFree = (providerType: WebSearchProviderTypeInfo) => {
|
|||||||
return !providerType.requires_api_key && !providerType.requires_engine_id
|
return !providerType.requires_api_key && !providerType.requires_engine_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isEntityFree = (entity: WebSearchProviderEntity) => {
|
||||||
|
const pt = providerTypes.value.find(p => p.id === entity.provider)
|
||||||
|
return pt ? isProviderFree(pt) : false
|
||||||
|
}
|
||||||
|
|
||||||
// ===== Methods =====
|
// ===== Methods =====
|
||||||
const onProviderTypeChange = () => {
|
const onProviderTypeChange = () => {
|
||||||
providerForm.value.parameters = {}
|
providerForm.value.parameters = {}
|
||||||
@@ -245,9 +252,11 @@ const editProvider = (entity: WebSearchProviderEntity) => {
|
|||||||
showAddProviderDialog.value = true
|
showAddProviderDialog.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveProvider = async ({ validateResult, firstError }: any) => {
|
const saveProvider = async () => {
|
||||||
|
const validateResult = await formRef.value?.validate()
|
||||||
if (validateResult !== true && validateResult !== undefined) {
|
if (validateResult !== true && validateResult !== undefined) {
|
||||||
MessagePlugin.warning(firstError || 'Please check the form fields')
|
const firstError = typeof validateResult === 'object' ? Object.values(validateResult)[0] : ''
|
||||||
|
MessagePlugin.warning(typeof firstError === 'string' ? firstError : 'Please check the form fields')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,14 +290,19 @@ const saveProvider = async ({ validateResult, firstError }: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteProvider = async (id: string) => {
|
const deleteProvider = (entity: WebSearchProviderEntity) => {
|
||||||
try {
|
confirmDelete({
|
||||||
await deleteWebSearchProviderAPI(id)
|
body: t('webSearchSettings.deleteConfirm'),
|
||||||
MessagePlugin.success(t('webSearchSettings.toasts.providerDeleted'))
|
onConfirm: async () => {
|
||||||
await loadProviderEntities()
|
try {
|
||||||
} catch (error: any) {
|
await deleteWebSearchProviderAPI(entity.id!)
|
||||||
MessagePlugin.error(error?.message || 'Failed to delete provider')
|
MessagePlugin.success(t('webSearchSettings.toasts.providerDeleted'))
|
||||||
}
|
await loadProviderEntities()
|
||||||
|
} catch (error: any) {
|
||||||
|
MessagePlugin.error(error?.message || 'Failed to delete provider')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const testConnection = async () => {
|
const testConnection = async () => {
|
||||||
@@ -337,6 +351,28 @@ const testExistingConnection = async (entity: WebSearchProviderEntity) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getProviderOptions = (_entity: WebSearchProviderEntity) => {
|
||||||
|
return [
|
||||||
|
{ content: t('webSearchSettings.testConnection'), value: 'test' },
|
||||||
|
{ content: t('common.edit'), value: 'edit' },
|
||||||
|
{ content: t('common.delete'), value: 'delete', theme: 'error' as const }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleMenuAction = (data: { value: string }, entity: WebSearchProviderEntity) => {
|
||||||
|
switch (data.value) {
|
||||||
|
case 'test':
|
||||||
|
testExistingConnection(entity)
|
||||||
|
break
|
||||||
|
case 'edit':
|
||||||
|
editProvider(entity)
|
||||||
|
break
|
||||||
|
case 'delete':
|
||||||
|
deleteProvider(entity)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ===== Init =====
|
// ===== Init =====
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await Promise.all([loadProviderTypes(), loadProviderEntities()])
|
await Promise.all([loadProviderTypes(), loadProviderEntities()])
|
||||||
@@ -349,7 +385,7 @@ onMounted(async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.section-header {
|
.section-header {
|
||||||
margin-bottom: 32px;
|
margin-bottom: 28px;
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
@@ -362,16 +398,11 @@ onMounted(async () => {
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: var(--td-text-color-secondary);
|
color: var(--td-text-color-secondary);
|
||||||
margin: 0;
|
margin: 0;
|
||||||
line-height: 1.5;
|
line-height: 1.6;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings-group {
|
.settings-toolbar {
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.section-subheader {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
@@ -385,67 +416,35 @@ onMounted(async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.provider-list {
|
.provider-grid {
|
||||||
display: flex;
|
display: grid;
|
||||||
flex-direction: column;
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
gap: 8px;
|
gap: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.provider-item {
|
.provider-meta-item {
|
||||||
display: flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
gap: 4px;
|
||||||
padding: 14px 16px;
|
max-width: 100%;
|
||||||
background: var(--td-bg-color-container);
|
overflow: hidden;
|
||||||
border: 1px solid var(--td-component-stroke);
|
|
||||||
border-radius: 8px;
|
|
||||||
transition: all 0.2s ease;
|
|
||||||
|
|
||||||
&:hover {
|
.provider-meta-text {
|
||||||
border-color: var(--td-brand-color);
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.item-info {
|
.empty-state {
|
||||||
display: flex;
|
padding: 64px 0;
|
||||||
flex-direction: column;
|
|
||||||
gap: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.item-header {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.item-name {
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: 500;
|
|
||||||
color: var(--td-text-color-primary);
|
|
||||||
}
|
|
||||||
|
|
||||||
.item-desc {
|
|
||||||
font-size: 13px;
|
|
||||||
color: var(--td-text-color-secondary);
|
|
||||||
}
|
|
||||||
|
|
||||||
.item-actions {
|
|
||||||
display: flex;
|
|
||||||
gap: 4px;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.empty-providers {
|
|
||||||
padding: 32px;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: var(--td-text-color-placeholder);
|
|
||||||
border: 1px dashed var(--td-component-stroke);
|
|
||||||
border-radius: 8px;
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dialog-form-container {
|
:deep(.t-empty__description) {
|
||||||
margin-top: 12px;
|
font-size: 14px;
|
||||||
|
color: var(--td-text-color-placeholder);
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.provider-option {
|
.provider-option {
|
||||||
@@ -481,18 +480,4 @@ onMounted(async () => {
|
|||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dialog-footer {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
margin-top: 32px;
|
|
||||||
padding-top: 20px;
|
|
||||||
border-top: 1px solid var(--td-component-border);
|
|
||||||
|
|
||||||
.footer-right {
|
|
||||||
display: flex;
|
|
||||||
gap: 12px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
<template>
|
<template>
|
||||||
<t-dialog
|
<SettingDrawer
|
||||||
v-model:visible="dialogVisible"
|
:visible="dialogVisible"
|
||||||
:header="mode === 'add' ? t('mcpServiceDialog.addTitle') : t('mcpServiceDialog.editTitle')"
|
:title="mode === 'add' ? t('mcpServiceDialog.addTitle') : t('mcpServiceDialog.editTitle')"
|
||||||
width="700px"
|
:confirm-loading="submitting"
|
||||||
:on-confirm="handleSubmit"
|
@update:visible="(v: boolean) => dialogVisible = v"
|
||||||
:on-cancel="handleClose"
|
@confirm="handleSubmit"
|
||||||
:confirm-btn="{ content: t('common.save'), loading: submitting }"
|
@cancel="handleClose"
|
||||||
>
|
>
|
||||||
<t-form
|
<t-form
|
||||||
ref="formRef"
|
ref="formRef"
|
||||||
:data="formData"
|
:data="formData"
|
||||||
:rules="rules"
|
:rules="rules"
|
||||||
label-width="120px"
|
label-align="top"
|
||||||
>
|
>
|
||||||
<t-form-item :label="t('mcpServiceDialog.name')" name="name">
|
<t-form-item :label="t('mcpServiceDialog.name')" name="name">
|
||||||
<t-input v-model="formData.name" :placeholder="t('mcpServiceDialog.namePlaceholder')" />
|
<t-input v-model="formData.name" :placeholder="t('mcpServiceDialog.namePlaceholder')" />
|
||||||
@@ -95,7 +95,7 @@
|
|||||||
</t-collapse-panel>
|
</t-collapse-panel>
|
||||||
</t-collapse>
|
</t-collapse>
|
||||||
</t-form>
|
</t-form>
|
||||||
</t-dialog>
|
</SettingDrawer>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -108,6 +108,7 @@ import {
|
|||||||
updateMCPService,
|
updateMCPService,
|
||||||
type MCPService
|
type MCPService
|
||||||
} from '@/api/mcp-service'
|
} from '@/api/mcp-service'
|
||||||
|
import SettingDrawer from '@/components/settings/SettingDrawer.vue'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
visible: boolean
|
visible: boolean
|
||||||
|
|||||||
Reference in New Issue
Block a user