Files
X-Financial/web/src/assets/styles/views/settings-view.css
caoxiaozhu 86568660a4 feat: 重构模型配置存储与 API Key 加密管理
主要修改点:

1. 遗留密码格式兼容 (server/src/app/core/admin_secret.py)
   - 新增 legacy_admin_secret_to_password_hash(): 将旧版 admin secret 记录转换为标准 scrypt 哈希格式

2. Scrypt 密码验证增强 (server/src/app/core/security.py)
   - verify_password(): 新增 scrypt$ 前缀检测,分流到专用验证函数
   - 新增 verify_scrypt_password(): 解析 scrypt$ 格式哈希并验证

3. 模型配置存储重构 (server/src/app/models/system_model_setting.py)
   - 新增 SystemModelSetting 模型(slot 为 PK)
   - 字段: slot, provider, model_name, endpoint, capability, priority, enabled, api_key_encrypted, created_at, updated_at

4. Settings Repository 扩展 (server/src/app/repositories/settings.py)
   - 新增 get_model_settings(): 获取所有模型配置
   - 新增 get_model_setting(slot): 按 slot 获取单个模型配置

5. Settings Service 重构 (server/src/app/services/settings.py)
   - 新增 ModelSlotConfig dataclass: 封装单个模型槽位的配置属性
   - 新增 MODEL_SLOT_CONFIGS 字典: main/backup/vlm/embedding 四个槽位配置
   - 重构 save_model_settings(): 批量保存模型配置到 SystemModelSetting 表
   - 新增 load_model_settings(): 从 SystemModelSetting 表加载所有模型配置
   - read_settings(): 整合 legacy secrets 与新的 SystemModelSetting 表数据
   - write_settings(): 拆分 model secrets 到 SystemModelSetting 表
   - decrypt_model_secret(): 新增从数据库读取加密的 API Key

6. 数据库模型注册 (server/src/app/db/base.py)
   - 注册 SystemModelSetting 模型

7. 前端 API URL 智能解析 (web/src/services/api.js)
   - 新增 isLoopbackHost(): 判断是否为回环地址
   - 新增 resolveBrowserReachableApiBaseUrl(): 当后端配置为回环地址但浏览器非回环时,自动替换为浏览器 host
   - 改进错误信息: "无法连接 FastAPI 后端服务,请确认后端已启动且浏览器可访问后端端口。"

8. 前端 Session 导航增强 (web/src/composables/useSystemState.js)
   - installSessionNavigation(): 调用 fetchBootstrapState 后设置运行时 API Base URL

9. Settings 视图增强 (web/src/views/SettingsView.vue)
   - API Key 输入框: 新增 @focus="clearModelSecretMask('xxx')" 清除遮罩
   - 新增 .secret-bound-state 提示: 显示"已从数据库加密加载,测试会使用已保存密钥"

10. Settings 脚本增强 (web/src/views/scripts/SettingsView.js)
    - 新增 clearModelSecretMask(slot): 清除指定槽位的 API Key 遮罩状态

11. CSS 样式 (web/src/assets/styles/views/settings-view.css)
    - 新增 .secret-bound-state 样式: 显示数据库已加载密钥的提示样式
2026-05-08 11:14:04 +08:00

698 lines
12 KiB
CSS

.settings-page {
height: 100%;
min-height: 0;
animation: fadeUp 220ms var(--ease) both;
}
.settings-shell {
height: 100%;
min-height: 0;
display: grid;
grid-template-columns: 248px minmax(0, 1fr);
overflow: hidden;
border-radius: 24px;
background: linear-gradient(180deg, #ffffff 0%, #fbfefd 100%);
}
.settings-nav {
min-width: 0;
min-height: 0;
display: grid;
grid-template-rows: auto minmax(0, 1fr);
gap: 10px;
padding: 22px 16px 18px;
border-right: 1px solid #e7edf3;
background: linear-gradient(180deg, #fcfffd 0%, #f5fbf8 58%, #ffffff 100%);
}
.settings-nav-head {
display: grid;
gap: 8px;
padding: 4px 10px 18px;
border-bottom: 1px solid #eef3f7;
}
.nav-kicker {
color: #10b981;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.settings-nav-head h2 {
color: #0f172a;
font-size: 24px;
font-weight: 860;
line-height: 1.1;
}
.settings-nav-head p {
color: #64748b;
font-size: 12px;
line-height: 1.6;
}
.settings-nav-list {
min-height: 0;
display: grid;
align-content: start;
gap: 8px;
overflow: auto;
padding-right: 4px;
}
.settings-nav-item {
width: 100%;
min-height: 74px;
display: block;
padding: 14px 14px 14px 16px;
border: 1px solid transparent;
border-radius: 18px;
background: transparent;
color: #334155;
text-align: left;
transition:
background 180ms var(--ease),
border-color 180ms var(--ease),
box-shadow 180ms var(--ease),
color 180ms var(--ease),
transform 180ms var(--ease);
}
.settings-nav-item:hover {
transform: translateY(-1px);
border-color: rgba(16, 185, 129, 0.14);
background: rgba(255, 255, 255, 0.9);
}
.settings-nav-item.active {
border-color: rgba(16, 185, 129, 0.16);
background: linear-gradient(135deg, rgba(16, 185, 129, 0.14), rgba(16, 185, 129, 0.04));
box-shadow: inset 3px 0 0 #10b981;
color: #047857;
}
.nav-item-copy {
min-width: 0;
display: grid;
gap: 4px;
}
.nav-item-copy strong {
color: inherit;
font-size: 14px;
font-weight: 820;
line-height: 1.25;
}
.nav-item-copy small {
color: #64748b;
font-size: 12px;
line-height: 1.45;
}
.settings-body {
min-width: 0;
min-height: 0;
display: grid;
grid-template-rows: auto minmax(0, 1fr);
background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(248, 250, 252, 0.96) 100%);
}
.settings-toolbar {
position: sticky;
top: 0;
z-index: 2;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
padding: 24px 28px 20px;
border-bottom: 1px solid #eef2f7;
background: rgba(255, 255, 255, 0.92);
backdrop-filter: blur(14px);
}
.settings-toolbar-copy {
min-width: 0;
}
.settings-breadcrumb {
display: inline-flex;
align-items: center;
min-height: 28px;
padding: 0 12px;
border-radius: 999px;
background: #eef8f2;
color: #047857;
font-size: 12px;
font-weight: 800;
}
.settings-toolbar-copy h3 {
margin-top: 14px;
color: #0f172a;
font-size: 28px;
font-weight: 860;
line-height: 1.15;
}
.settings-toolbar-copy p {
margin-top: 10px;
max-width: 760px;
color: #64748b;
font-size: 14px;
line-height: 1.7;
}
.settings-toolbar-actions {
display: grid;
justify-items: end;
gap: 12px;
}
.save-button {
min-height: 42px;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
padding: 0 18px;
border: 0;
border-radius: 14px;
background: linear-gradient(135deg, #13b87b, #0a9d68);
color: #fff;
font-size: 13px;
font-weight: 820;
box-shadow: 0 12px 26px rgba(5, 150, 105, 0.2);
transition:
transform 180ms var(--ease),
box-shadow 180ms var(--ease),
filter 180ms var(--ease);
}
.save-button:hover {
transform: translateY(-1px);
box-shadow: 0 16px 30px rgba(5, 150, 105, 0.22);
filter: saturate(1.04);
}
.settings-content {
min-height: 0;
overflow: auto;
display: grid;
align-content: start;
gap: 18px;
padding: 24px 28px 28px;
}
.model-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 18px;
}
.settings-card {
padding: 22px 22px 24px;
border: 1px solid #e8eef3;
border-radius: 22px;
background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 251, 255, 0.94));
}
.card-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 14px;
margin-bottom: 18px;
}
.card-head-actions {
display: flex;
align-items: center;
gap: 10px;
flex: 0 0 auto;
}
.card-head h4 {
color: #0f172a;
font-size: 18px;
font-weight: 840;
line-height: 1.2;
}
.card-head p {
margin-top: 6px;
color: #64748b;
font-size: 13px;
line-height: 1.65;
}
.test-button {
min-height: 38px;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
padding: 0 14px;
border: 1px solid rgba(16, 185, 129, 0.18);
border-radius: 12px;
background: #f7fffb;
color: #047857;
font-size: 13px;
font-weight: 800;
transition:
border-color 180ms var(--ease),
background 180ms var(--ease),
color 180ms var(--ease),
transform 180ms var(--ease);
}
.test-button:hover:not(:disabled) {
transform: translateY(-1px);
border-color: rgba(16, 185, 129, 0.34);
background: #ecfdf5;
}
.test-button:disabled {
cursor: wait;
opacity: 0.78;
}
.form-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 18px 20px;
align-items: start;
}
.profile-grid {
grid-template-columns: 96px repeat(2, minmax(0, 1fr));
}
.compact-grid {
margin-bottom: 18px;
}
.field {
display: grid;
gap: 8px;
}
.field-wide {
grid-column: span 2;
}
.field-full {
grid-column: 1 / -1;
}
.field span {
color: #334155;
font-size: 12px;
font-weight: 800;
line-height: 1.2;
}
.field em {
margin-right: 4px;
color: #ef4444;
font-style: normal;
}
.field input,
.field select {
width: 100%;
min-height: 44px;
padding: 0 14px;
border: 1px solid #d7e0ea;
border-radius: 16px;
background: #fff;
color: #0f172a;
font-size: 13px;
line-height: 1.45;
transition:
border-color 180ms var(--ease),
box-shadow 180ms var(--ease),
background 180ms var(--ease);
}
.field input::placeholder {
color: #94a3b8;
}
.field input:focus,
.field select:focus {
outline: none;
border-color: rgba(16, 185, 129, 0.55);
box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.12);
}
.secret-bound-state {
min-height: 24px;
display: inline-flex;
align-items: center;
gap: 7px;
color: #047857;
font-size: 12px;
font-weight: 750;
line-height: 1.45;
}
.secret-bound-state i {
font-size: 15px;
}
.test-feedback {
display: flex;
align-items: flex-start;
gap: 8px;
margin-top: 16px;
padding: 12px 14px;
border-radius: 14px;
font-size: 12px;
font-weight: 700;
line-height: 1.6;
}
.test-feedback i {
margin-top: 2px;
font-size: 15px;
}
.test-feedback.is-success {
background: #ecfdf5;
color: #047857;
}
.test-feedback.is-error {
background: #fef2f2;
color: #b91c1c;
}
.test-feedback.is-testing {
background: #eff6ff;
color: #1d4ed8;
}
.logo-field {
align-self: stretch;
}
.logo-tile {
width: 96px;
height: 96px;
display: grid;
place-items: center;
border: 1px dashed #cbd5e1;
border-radius: 22px;
background:
linear-gradient(45deg, #f8fafc 25%, transparent 25%, transparent 75%, #f8fafc 75%, #f8fafc),
linear-gradient(45deg, #f8fafc 25%, transparent 25%, transparent 75%, #f8fafc 75%, #f8fafc);
background-position: 0 0, 9px 9px;
background-size: 18px 18px;
color: #10b981;
font-size: 36px;
}
.preview-card {
display: grid;
grid-template-columns: 78px minmax(0, 1fr) auto;
align-items: center;
gap: 18px;
padding: 22px;
border: 1px solid rgba(16, 185, 129, 0.14);
border-radius: 24px;
background: linear-gradient(135deg, rgba(16, 185, 129, 0.08), rgba(59, 130, 246, 0.05));
}
.preview-icon {
width: 78px;
height: 78px;
display: grid;
place-items: center;
border-radius: 22px;
background: linear-gradient(135deg, #10b981, #0f766e);
color: #fff;
font-size: 34px;
box-shadow: 0 14px 28px rgba(16, 185, 129, 0.18);
}
.preview-copy strong {
display: block;
color: #0f172a;
font-size: 18px;
font-weight: 840;
}
.preview-copy p {
margin-top: 6px;
color: #334155;
font-size: 14px;
font-weight: 700;
}
.preview-copy small {
display: block;
margin-top: 8px;
color: #64748b;
font-size: 12px;
line-height: 1.55;
}
.preview-badge {
min-height: 30px;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0 12px;
border-radius: 999px;
background: #ecfdf5;
color: #059669;
font-size: 12px;
font-weight: 820;
white-space: nowrap;
}
.chip-row {
display: flex;
gap: 10px;
flex-wrap: wrap;
margin-bottom: 18px;
}
.level-chip {
min-width: 78px;
min-height: 36px;
padding: 0 14px;
border: 1px solid #d7e0ea;
border-radius: 999px;
background: #fff;
color: #475569;
font-size: 12px;
font-weight: 820;
transition:
border-color 160ms ease,
background 160ms ease,
box-shadow 160ms ease,
color 160ms ease;
}
.level-chip.active {
border-color: #10b981;
background: #10b981;
color: #fff;
box-shadow: 0 8px 18px rgba(16, 185, 129, 0.18);
}
.range-shell {
min-height: 44px;
display: flex;
align-items: center;
gap: 14px;
padding: 0 14px;
border: 1px solid #d7e0ea;
border-radius: 16px;
background: #fff;
}
.range-shell input[type='range'] {
flex: 1 1 auto;
accent-color: #10b981;
}
.range-shell strong {
min-width: 28px;
color: #0f172a;
font-size: 13px;
font-weight: 800;
text-align: right;
}
.switch-group {
display: grid;
gap: 12px;
}
.switch-row {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 15px 16px;
border: 1px solid #e5eaf0;
border-radius: 18px;
background: #fbfdff;
text-align: left;
transition:
border-color 180ms var(--ease),
background 180ms var(--ease),
transform 180ms var(--ease);
}
.switch-row:hover {
transform: translateY(-1px);
border-color: rgba(16, 185, 129, 0.18);
background: #f7fffb;
}
.switch-copy {
min-width: 0;
display: grid;
gap: 4px;
}
.switch-copy strong {
color: #0f172a;
font-size: 14px;
font-weight: 800;
}
.switch-copy small {
color: #64748b;
font-size: 12px;
line-height: 1.55;
}
.switch {
position: relative;
flex: 0 0 auto;
width: 48px;
height: 28px;
display: inline-flex;
align-items: center;
padding: 3px;
border-radius: 999px;
background: #dbe4ee;
transition: background 180ms var(--ease);
}
.switch i {
width: 22px;
height: 22px;
border-radius: 999px;
background: #fff;
box-shadow: 0 2px 6px rgba(15, 23, 42, 0.14);
transition: transform 180ms var(--ease);
}
.switch.active {
background: #10b981;
}
.switch.active i {
transform: translateX(20px);
}
@media (max-width: 1260px) {
.settings-shell {
grid-template-columns: 226px minmax(0, 1fr);
}
.settings-toolbar {
flex-direction: column;
align-items: stretch;
}
.settings-toolbar-actions {
justify-items: stretch;
}
.save-button {
justify-content: center;
}
}
@media (max-width: 960px) {
.settings-shell {
grid-template-columns: 1fr;
}
.settings-nav {
grid-template-rows: auto auto auto;
border-right: 0;
border-bottom: 1px solid #e7edf3;
}
.settings-nav-list {
display: flex;
gap: 8px;
overflow-x: auto;
padding-right: 0;
}
.settings-nav-item {
min-width: 208px;
}
.settings-toolbar,
.settings-content {
padding-inline: 20px;
}
.model-grid,
.form-grid,
.profile-grid {
grid-template-columns: 1fr;
}
.field-wide,
.field-full {
grid-column: span 1;
}
.logo-field {
width: fit-content;
}
.preview-card {
grid-template-columns: 1fr;
justify-items: start;
}
}
@media (max-width: 640px) {
.settings-toolbar {
padding: 18px 16px;
}
.settings-toolbar-copy h3 {
font-size: 24px;
}
.settings-content {
padding: 16px;
}
.settings-card {
padding: 18px 16px;
border-radius: 18px;
}
.settings-nav {
padding: 18px 12px 14px;
}
}