feat(settings): redesign websearch/mcp provider cards

Apply the model-card pattern to the other two provider lists in
the new "Data & Extensions" group so they share one visual idiom.

Web search providers:
- Drop the 3-tag row (provider type / default / free) for a 36x36
  monogram badge tinted per provider (duckduckgo, bing, google,
  tavily, baidu, searxng, ollama).
- Title row carries the entity name plus optional "default" /
  "free" pills; the more-actions button hides until hover/focus
  and opens on click.
- Subtitle reads "Provider type · description"; proxy URL drops
  to a muted monospaced last line, no leading icon.
- Grid is responsive: repeat(auto-fill, minmax(320px, 1fr)).

MCP services:
- Same skeleton with a transport-type badge (sse → cast / sse-green,
  http-streamable → link / brand-blue, stdio → code / amber).
- Keep the inline enable switch, but slot it into the title row so
  the card stops repeating "on/off" as a tag.
- Builtin services keep the muted background to signal read-only.
- Three-dot menu hides until hover/focus and opens on click.

Drops dead CSS (.provider-meta-item, .service-meta-item, the old
2-column grids) and the now-unused SettingCard imports. SettingCard
itself is left in place for future consumers.
This commit is contained in:
wizardchen
2026-05-26 21:48:30 +08:00
committed by lyingbug
parent f10b83d92f
commit 260b3eec26
2 changed files with 427 additions and 97 deletions
+204 -63
View File
@@ -33,54 +33,57 @@
</div> </div>
<div v-else class="services-grid"> <div v-else class="services-grid">
<SettingCard <!-- 与 ModelSettings / WebSearchSettings 同形的卡片:左侧 transport 徽章 +
标题 / 副标题 / url 三段式。开关挂在标题行右侧,三点菜单 hover 才出现。
SettingCard 当前没有其它消费者了,但保留组件供未来需要时复用。 -->
<div
v-for="service in services" v-for="service in services"
:key="service.id" :key="service.id"
:title="service.name" class="service-card"
:description="service.description || ''" :class="[
:disabled="service.is_builtin" `service-card--${service.transport_type || 'unknown'}`,
:actions="service.is_builtin ? getBuiltinServiceOptions() : getServiceOptions()" { 'service-card--builtin': service.is_builtin }
@action="(value: string) => handleMenuAction({ value }, service)" ]"
> >
<template #tags> <div class="service-card__badge" :aria-label="getTransportTypeLabel(service.transport_type)">
<t-tag <t-icon :name="getTransportTypeIcon(service.transport_type)" size="18px" />
:theme="getTransportTypeTheme(service.transport_type)" </div>
size="small" <div class="service-card__body">
variant="light" <div class="service-card__header">
> <h3 class="service-card__title" :title="service.name">{{ service.name }}</h3>
{{ getTransportTypeLabel(service.transport_type) }} <span v-if="service.is_builtin" class="service-card__pill service-card__pill--warning">
</t-tag> {{ $t('mcpSettings.builtin') }}
<t-tag </span>
v-if="service.is_builtin" <t-switch
theme="warning" v-model="service.enabled"
size="small" size="medium"
variant="light" :disabled="service.is_builtin || !authStore.hasRole('admin')"
> @change="() => handleToggleEnabled(service)"
{{ $t('mcpSettings.builtin') }} />
</t-tag> <t-dropdown
<t-tag :options="service.is_builtin ? getBuiltinServiceOptions() : getServiceOptions()"
:theme="service.enabled ? 'success' : 'default'" placement="bottom-right"
size="small" attach="body"
variant="light" trigger="click"
> @click="(data: any) => handleMenuAction({ value: data.value }, service)"
{{ service.enabled ? $t('common.on') : $t('common.off') }} >
</t-tag> <t-button variant="text" shape="square" size="small" class="service-card__more">
</template> <t-icon name="ellipsis" />
<template #controls> </t-button>
<t-switch </t-dropdown>
v-model="service.enabled" </div>
size="medium" <div class="service-card__subtitle">
:disabled="service.is_builtin || !authStore.hasRole('admin')" <span class="service-card__type">{{ getTransportTypeLabel(service.transport_type) }}</span>
@change="() => handleToggleEnabled(service)" <template v-if="service.description">
/> <span class="service-card__sep">·</span>
</template> <span class="service-card__desc" :title="service.description">{{ service.description }}</span>
<template #meta> </template>
<span v-if="service.url" class="service-meta-item" :title="service.url"> </div>
<t-icon name="link" size="12px" /> <div v-if="service.url" class="service-card__url" :title="service.url">
<span class="service-meta-text">{{ service.url }}</span> {{ service.url }}
</span> </div>
</template> </div>
</SettingCard> </div>
</div> </div>
</template> </template>
@@ -116,7 +119,6 @@ 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' import { useConfirmDelete } from '@/components/settings/useConfirmDelete'
import { useAuthStore } from '@/stores/auth' import { useAuthStore } from '@/stores/auth'
@@ -289,17 +291,17 @@ const handleMenuAction = (data: { value: string }, service: MCPService) => {
} }
} }
// Get transport type theme for tag // Get transport type icon. 复用 tdesign 自带 icon name;新增 transport 时同步加。
const getTransportTypeTheme = (transportType: string) => { const getTransportTypeIcon = (transportType: string) => {
switch (transportType) { switch (transportType) {
case 'sse': case 'sse':
return 'success' return 'cast'
case 'http-streamable': case 'http-streamable':
return 'primary' return 'link'
case 'stdio': case 'stdio':
return 'warning' return 'code'
default: default:
return 'default' return 'tools'
} }
} }
@@ -390,21 +392,160 @@ onMounted(() => {
.services-grid { .services-grid {
display: grid; display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
gap: 12px; gap: 12px;
} }
.service-meta-item { // Transport-distinguished card. 与 ModelSettings / WebSearchSettings 同形。
display: inline-flex; .service-card {
align-items: center; display: flex;
gap: 4px; align-items: flex-start;
max-width: 100%; gap: 12px;
overflow: hidden; padding: 14px 14px 14px 12px;
border: 1px solid var(--td-component-stroke);
border-radius: 10px;
background: var(--td-bg-color-container);
transition: border-color 0.18s ease, box-shadow 0.18s ease;
min-width: 0;
.service-meta-text { &:hover {
overflow: hidden; border-color: var(--td-brand-color-3, var(--td-brand-color));
text-overflow: ellipsis; box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
white-space: nowrap; }
&--builtin {
background: var(--td-bg-color-secondarycontainer);
&:hover {
box-shadow: none;
border-color: var(--td-component-stroke);
}
} }
} }
.service-card__badge {
flex-shrink: 0;
width: 36px;
height: 36px;
border-radius: 9px;
display: flex;
align-items: center;
justify-content: center;
margin-top: 1px;
background: rgba(0, 82, 217, 0.1);
color: #0052D9;
}
// 三种 transport 的徽章配色:sse 流式 → 绿,http-streamable → 蓝,stdio → 橙
.service-card--sse .service-card__badge {
background: rgba(17, 128, 83, 0.12);
color: #118053;
}
.service-card--http-streamable .service-card__badge {
background: rgba(0, 82, 217, 0.1);
color: #0052D9;
}
.service-card--stdio .service-card__badge {
background: rgba(184, 92, 0, 0.12);
color: #B85C00;
}
.service-card__body {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 4px;
}
.service-card__header {
display: flex;
align-items: center;
gap: 6px;
min-width: 0;
}
.service-card__title {
flex: 1;
min-width: 0;
margin: 0;
font-size: 14px;
font-weight: 600;
line-height: 1.4;
color: var(--td-text-color-primary);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.service-card__pill {
flex-shrink: 0;
padding: 1px 6px;
font-size: 11px;
font-weight: 500;
line-height: 16px;
border-radius: 3px;
&--warning {
color: var(--td-warning-color-7, #B85C00);
background: var(--td-warning-color-1, #FEF3E6);
}
}
.service-card__more {
flex-shrink: 0;
color: var(--td-text-color-placeholder);
padding: 2px;
opacity: 0;
transition: opacity 0.15s ease;
&:hover,
&:focus-visible {
background: var(--td-bg-color-secondarycontainer);
color: var(--td-text-color-primary);
}
}
// switch 始终显示(它是状态锚点);三点按钮只在 hover/focus 时出现。
.service-card:hover .service-card__more,
.service-card:focus-within .service-card__more {
opacity: 1;
}
.service-card__subtitle {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 4px;
font-size: 12px;
line-height: 1.4;
color: var(--td-text-color-secondary);
min-width: 0;
}
.service-card__type {
font-weight: 500;
}
.service-card__sep {
color: var(--td-text-color-placeholder);
}
.service-card__desc {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
}
.service-card__url {
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
font-size: 11px;
line-height: 1.4;
color: var(--td-text-color-placeholder);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
min-width: 0;
}
</style> </style>
+223 -34
View File
@@ -13,29 +13,53 @@
</t-button> </t-button>
</div> </div>
<!-- Provider List --> <!-- Provider List —— 与 ModelSettings 的卡片同形:左侧标识徽章 + 标题 / 副标题 / proxy URL 三段式。
不复用 SettingCard 的原因和 Models 一样:每页有微妙不同的右上侧栏需求(这里没有控件,
Mcp 有开关),SettingCard 仍服务于其它消费者。 -->
<div v-if="providerEntities.length > 0" class="provider-grid"> <div v-if="providerEntities.length > 0" class="provider-grid">
<SettingCard v-for="entity in providerEntities" :key="entity.id" :title="entity.name" <div
:description="entity.description || ''" :actions="getProviderOptions(entity)" v-for="entity in providerEntities"
@action="(value: string) => handleMenuAction({ value }, entity)"> :key="entity.id"
<template #tags> class="provider-card"
<t-tag theme="primary" size="small" variant="light"> :class="`provider-card--${entity.provider}`"
{{ entity.provider }} >
</t-tag> <div class="provider-card__badge" :aria-label="entity.provider">
<t-tag v-if="entity.is_default" theme="success" size="small" variant="light"> {{ providerInitial(entity.provider) }}
{{ t('webSearchSettings.default') }} </div>
</t-tag> <div class="provider-card__body">
<t-tag v-if="isEntityFree(entity)" theme="warning" size="small" variant="light"> <div class="provider-card__header">
{{ t('webSearchSettings.free') }} <h3 class="provider-card__title" :title="entity.name">{{ entity.name }}</h3>
</t-tag> <span v-if="entity.is_default" class="provider-card__pill provider-card__pill--success">
</template> {{ t('webSearchSettings.default') }}
<template #meta> </span>
<span v-if="entity.parameters?.proxy_url" class="provider-meta-item" :title="entity.parameters.proxy_url"> <span v-if="isEntityFree(entity)" class="provider-card__pill provider-card__pill--warning">
<t-icon name="internet" size="12px" /> {{ t('webSearchSettings.free') }}
<span class="provider-meta-text">{{ entity.parameters.proxy_url }}</span> </span>
</span> <t-dropdown
</template> v-if="getProviderOptions(entity).length > 0"
</SettingCard> :options="getProviderOptions(entity)"
placement="bottom-right"
attach="body"
trigger="click"
@click="(data: any) => handleMenuAction({ value: data.value }, entity)"
>
<t-button variant="text" shape="square" size="small" class="provider-card__more">
<t-icon name="ellipsis" />
</t-button>
</t-dropdown>
</div>
<div class="provider-card__subtitle">
<span class="provider-card__type">{{ providerTypeLabel(entity.provider) }}</span>
<template v-if="entity.description">
<span class="provider-card__sep">·</span>
<span class="provider-card__desc" :title="entity.description">{{ entity.description }}</span>
</template>
</div>
<div v-if="entity.parameters?.proxy_url" class="provider-card__url" :title="entity.parameters.proxy_url">
{{ entity.parameters.proxy_url }}
</div>
</div>
</div>
</div> </div>
<!-- Empty State --> <!-- Empty State -->
@@ -164,7 +188,6 @@ import {
type WebSearchProviderTypeInfo, type WebSearchProviderTypeInfo,
type WebSearchCredentialField, type WebSearchCredentialField,
} 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 SettingDrawer from '@/components/settings/SettingDrawer.vue'
import CredentialResource, { import CredentialResource, {
type CredentialFieldDef, type CredentialFieldDef,
@@ -245,6 +268,16 @@ const isEntityFree = (entity: WebSearchProviderEntity) => {
return pt ? isProviderFree(pt) : false return pt ? isProviderFree(pt) : false
} }
// 卡片首字母徽章。复用 providerType 信息表,让多字节缩写也走同一处。
const providerInitial = (providerId: string) => {
const label = providerTypes.value.find(p => p.id === providerId)?.name || providerId
return (label.trim().charAt(0) || '?').toUpperCase()
}
const providerTypeLabel = (providerId: string) => {
return providerTypes.value.find(p => p.id === providerId)?.name || providerId
}
// ===== Methods ===== // ===== Methods =====
const onProviderTypeChange = () => { const onProviderTypeChange = () => {
providerForm.value.parameters = {} providerForm.value.parameters = {}
@@ -480,24 +513,180 @@ onMounted(async () => {
.provider-grid { .provider-grid {
display: grid; display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
gap: 12px; gap: 12px;
} }
.provider-meta-item { // 卡片视觉与 ModelSettings 的 model-card 同构(徽章 + 标题 / 副标题 / url 三段式)。
display: inline-flex; // 现阶段两份样式各自维护避免过度抽象;如果后续 Mcp / 第四个消费者出现,
align-items: center; // 再把共用片段抽到 components/settings/ 下的基类。
gap: 4px; .provider-card {
max-width: 100%; display: flex;
overflow: hidden; align-items: flex-start;
gap: 12px;
padding: 14px 14px 14px 12px;
border: 1px solid var(--td-component-stroke);
border-radius: 10px;
background: var(--td-bg-color-container);
transition: border-color 0.18s ease, box-shadow 0.18s ease;
min-width: 0;
.provider-meta-text { &:hover {
overflow: hidden; border-color: var(--td-brand-color-3, var(--td-brand-color));
text-overflow: ellipsis; box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
white-space: nowrap;
} }
} }
.provider-card__badge {
flex-shrink: 0;
width: 36px;
height: 36px;
border-radius: 9px;
display: flex;
align-items: center;
justify-content: center;
margin-top: 1px;
font-size: 15px;
font-weight: 600;
letter-spacing: 0.02em;
// 默认色,被 provider 修饰覆盖
background: rgba(0, 82, 217, 0.1);
color: #0052D9;
}
// 各搜索源的徽章配色 —— 不强求与官方 logo 一致,挑同色系低饱和版即可。
.provider-card--duckduckgo .provider-card__badge {
background: rgba(222, 88, 51, 0.12);
color: #DE5833;
}
.provider-card--bing .provider-card__badge {
background: rgba(0, 137, 255, 0.12);
color: #0089FF;
}
.provider-card--google .provider-card__badge {
background: rgba(66, 133, 244, 0.12);
color: #4285F4;
}
.provider-card--tavily .provider-card__badge {
background: rgba(98, 53, 187, 0.12);
color: #6235BB;
}
.provider-card--baidu .provider-card__badge {
background: rgba(225, 38, 38, 0.12);
color: #E12626;
}
.provider-card--searxng .provider-card__badge {
background: rgba(33, 86, 137, 0.12);
color: #215689;
}
.provider-card--ollama .provider-card__badge {
background: rgba(70, 70, 70, 0.12);
color: #464646;
}
.provider-card__body {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 4px;
}
.provider-card__header {
display: flex;
align-items: center;
gap: 6px;
min-width: 0;
}
.provider-card__title {
flex: 1;
min-width: 0;
margin: 0;
font-size: 14px;
font-weight: 600;
line-height: 1.4;
color: var(--td-text-color-primary);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.provider-card__pill {
flex-shrink: 0;
padding: 1px 6px;
font-size: 11px;
font-weight: 500;
line-height: 16px;
border-radius: 3px;
&--success {
color: var(--td-success-color-7, #118053);
background: var(--td-success-color-1, #E7F7F2);
}
&--warning {
color: var(--td-warning-color-7, #B85C00);
background: var(--td-warning-color-1, #FEF3E6);
}
}
.provider-card__more {
flex-shrink: 0;
color: var(--td-text-color-placeholder);
padding: 2px;
opacity: 0;
transition: opacity 0.15s ease;
&:hover,
&:focus-visible {
background: var(--td-bg-color-secondarycontainer);
color: var(--td-text-color-primary);
}
}
.provider-card:hover .provider-card__more,
.provider-card:focus-within .provider-card__more {
opacity: 1;
}
.provider-card__subtitle {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 4px;
font-size: 12px;
line-height: 1.4;
color: var(--td-text-color-secondary);
min-width: 0;
}
.provider-card__type {
font-weight: 500;
}
.provider-card__sep {
color: var(--td-text-color-placeholder);
}
.provider-card__desc {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
}
.provider-card__url {
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
font-size: 11px;
line-height: 1.4;
color: var(--td-text-color-placeholder);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
min-width: 0;
}
.empty-state { .empty-state {
padding: 64px 0; padding: 64px 0;
text-align: center; text-align: center;