From cb9f84267f7a73cddf2a23e894a1be03e843ea03 Mon Sep 17 00:00:00 2001 From: kicer Date: Sun, 6 Sep 2026 23:04:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E5=BC=B9=E7=AA=97=E7=B2=BE?= =?UTF-8?q?=E7=AE=80=EF=BC=9Atype/concurrency=20=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E8=BF=9B=E5=BC=B9=E7=AA=97=E4=B8=8E=E9=85=8D=E7=BD=AE=EF=BC=9B?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E8=A1=8C=E6=94=B9=E5=AD=90=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E5=8F=8C=E8=A1=8C(id=20+=20vision/enable=20=E5=8B=BE=E9=80=89)?= =?UTF-8?q?=EF=BC=9B=E5=B7=B2=E6=9C=89=E6=A8=A1=E5=9E=8B=E5=8F=AA=E6=8C=89?= =?UTF-8?q?=E7=BB=86=E7=B2=92=E5=BA=A6=20path=20=E6=94=B9=20vision/enable?= =?UTF-8?q?=EF=BC=8C=E4=BF=9D=E4=BD=8F=E6=96=87=E4=BB=B6=E9=87=8C=20displa?= =?UTF-8?q?y=5Fname/extra=5Fparams=20=E7=AD=89=E5=85=B6=E4=BD=99=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=EF=BC=9B=E6=96=B0=E5=A2=9E=E6=A8=A1=E5=9E=8B=E5=8F=AA?= =?UTF-8?q?=E5=86=99=E9=9D=9E=E7=BC=BA=E7=9C=81=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/server/public/css/style.css | 10 ++-- app/server/public/index.html | 87 ++++++++++++++------------------- 2 files changed, 44 insertions(+), 53 deletions(-) diff --git a/app/server/public/css/style.css b/app/server/public/css/style.css index 0d7d2b6..4b2508b 100644 --- a/app/server/public/css/style.css +++ b/app/server/public/css/style.css @@ -981,10 +981,12 @@ label.icon-btn { cursor: pointer; } .modal .mpe-row { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; } .modal .mpe-row input { width: auto; margin-bottom: 0; padding: 8px 10px; font-size: 13px; } .modal .mpe-grow { flex: 1; min-width: 0; } -.modal .mpe-con { flex: none; width: 56px; } -.modal .mpe-mid { flex: none; width: 104px; } -.modal .mpe-vis { flex: none; display: flex; align-items: center; gap: 3px; font-size: 12px; color: var(--gray); margin: 0; width: auto; } -.modal .mpe-vis input { width: 15px; height: 15px; padding: 0; margin: 0; border: none; background: none; accent-color: var(--active); cursor: pointer; } +/* 模型子卡片:上行 id+删除,下行 vision/enable 勾选 */ +.modal .mpe-mcard { border: 1px solid var(--border); border-radius: 10px; padding: 9px 10px; margin-bottom: 8px; background: #fafbfd; } +.modal .mpe-mcard .mpe-row { margin-bottom: 0; } +.modal .mpe-cks { display: flex; align-items: center; gap: 16px; margin-top: 8px; } +.modal .mpe-ck { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--gray); } +.modal .mpe-ck input { width: 15px; height: 15px; padding: 0; margin: 0; border: none; background: none; accent-color: var(--active); cursor: pointer; } .modal .mpe-del { flex: none; border: none; background: none; margin: 0; padding: 2px 7px; cursor: pointer; color: var(--gray-light); font-size: 18px; line-height: 1.2; } .modal .mpe-del:active { color: #c0392b; } diff --git a/app/server/public/index.html b/app/server/public/index.html index bd87733..76a6c3d 100644 --- a/app/server/public/index.html +++ b/app/server/public/index.html @@ -239,7 +239,6 @@

编辑平台

-
API Keys(同平台多 Key 共用下方模型)
模型
@@ -3328,15 +3327,13 @@ const p = add ? {} : (SET.cfgPlatforms[pi] || {}); pfEdit = { idx: add ? -1 : Number(pi), - keys: add ? [] : (p.keys || []).map((k, ki) => ({ ref: ki, api_key: k.api_key || '', concurrency: k.concurrency || 1 })), - models: add ? [] : platformModels(pi).map(m => ({ ref: m.model_index, id: m.mid || m.id, display_name: m.display_name || '', vision: !!m.vision, enable: m.enable !== false })), + keys: add ? [] : (p.keys || []).map((k, ki) => ({ ref: ki, api_key: k.api_key || '' })), + models: add ? [] : platformModels(pi).map(m => ({ ref: m.model_index, id: m.mid || m.id, vision: !!m.vision, enable: m.enable !== false })), }; $('mpe-title').textContent = add ? '新增平台' : '编辑平台'; $('mpe-name').value = add ? '' : (p.name || ''); $('mpe-url').value = add ? '' : (p.url || ''); - // 运行态 type = 规范化后的值(缺省已填 name);与 name 相同时置空,表示“跟随平台名” - $('mpe-type').value = add ? '' : ((p.type && p.type !== p.name) ? p.type : ''); - if (add) { pfEdit.keys.push({ ref: null, api_key: '', concurrency: 1 }); pfEdit.models.push({ ref: null, id: '', display_name: '', vision: false, enable: true }); } + if (add) { pfEdit.keys.push({ ref: null, api_key: '' }); pfEdit.models.push({ ref: null, id: '', vision: false, enable: true }); } $('mpe-restart').checked = true; // 默认勾选「保存后立即重启」 $('mpe-del-btn').classList.toggle('hidden', add); renderPfRows(); @@ -3347,18 +3344,23 @@ return '
' + '' + - '' + '' + '
'; } + // 模型子卡片两行:上行只配 id(已有行不可改),下行勾 vision/enable。 + // display_name/concurrency/type 不进弹窗:保存时只改 vision/enable 细粒度 path,不碰文件里其余字段。 function pfModelsRowHtml(r, i) { const isNew = r.ref == null; - return '
' + - '' + - '' + - '' + - '' + + return '
' + + '
' + + '' + + '' + + '
' + + '
' + + '' + + '' + + '
' + '
'; } // 行下标变化后需重渲染(事件处理器里捕获了旧 i),故增删后重建两段行列表。 @@ -3367,8 +3369,8 @@ $('mpe-keys').innerHTML = pfEdit.keys.map(pfKeysRowHtml).join('') || '
至少保留一个 Key
'; $('mpe-models').innerHTML = pfEdit.models.map(pfModelsRowHtml).join('') || '
至少保留一个模型
'; } - function addPfKey() { if (!pfEdit) return; pfEdit.keys.push({ ref: null, api_key: '', concurrency: 1 }); renderPfRows(); } - function addPfModel() { if (!pfEdit) return; pfEdit.models.push({ ref: null, id: '', display_name: '', vision: false, enable: true }); renderPfRows(); } + function addPfKey() { if (!pfEdit) return; pfEdit.keys.push({ ref: null, api_key: '' }); renderPfRows(); } + function addPfModel() { if (!pfEdit) return; pfEdit.models.push({ ref: null, id: '', vision: false, enable: true }); renderPfRows(); } function delPfKey(i) { if (!pfEdit) return; if (pfEdit.keys.length <= 1) return toast('至少保留一个 Key'); @@ -3389,46 +3391,30 @@ const edits = []; const name = $('mpe-name').value.trim(); const url = $('mpe-url').value.trim().replace(/\/+$/, ''); - let type = $('mpe-type').value.trim(); - // type 置空 = 「跟随平台名」:原配置显式配过 type 且与 name 不同的,写回新 name(规范化后等价缺省) - const effName = name || p.name; - if (!type && p.type && p.type !== p.name) type = effName; if (name && name !== p.name) edits.push({ path: ['platforms', pfEdit.idx, 'name'], value: name }); if (url && url !== p.url) edits.push({ path: ['platforms', pfEdit.idx, 'url'], value: url }); - if (type && type !== p.type) edits.push({ path: ['platforms', pfEdit.idx, 'type'], value: type }); - // Key:concurrency 可原地改;已有 api_key 不写回(脱敏值会污染真 Key),换 Key 走删行+新增行 + // Key:弹窗只配 api_key(concurrency/type 不进弹窗);已有 api_key 不写回(脱敏值会污染真 Key),换 Key 走删行+新增行 pfEdit.keys.forEach(r => { - if (r.ref != null) { - const oc = (p.keys[r.ref] || {}).concurrency || 1; - const nc = Math.max(1, parseInt(r.concurrency, 10) || 1); - if (nc !== oc) edits.push({ path: ['platforms', pfEdit.idx, 'keys', r.ref, 'concurrency'], value: nc }); - } else { - edits.push({ op: 'append', path: ['platforms', pfEdit.idx, 'keys'], value: { - api_key: String(r.api_key || '').trim(), concurrency: Math.max(1, parseInt(r.concurrency, 10) || 1), - } }); - } + if (r.ref == null) edits.push({ op: 'append', path: ['platforms', pfEdit.idx, 'keys'], value: { api_key: String(r.api_key || '').trim() } }); }); const delKeys = []; for (let ki = 0; ki < (p.keys || []).length; ki++) { if (!pfEdit.keys.some(r => r.ref === ki)) delKeys.push(ki); } delKeys.sort((a, b) => b - a).forEach(ki => edits.push({ op: 'delete', path: ['platforms', pfEdit.idx, 'keys', ki] })); - // 模型:整体覆盖改(保留 enable)/新增 append/删行;id 不可改故无新增行冲突 + // 模型:已有行只按细粒度 path 改 vision/enable(不整体覆盖,保住文件里的 display_name/extra_params 等); + // 新增行 append 最小对象(缺省项不写:display_name 后端同 id,enable 缺省启用) pfEdit.models.forEach(r => { if (r.ref != null) { const om = (p.models || [])[r.ref] || {}; - const nd = String(r.display_name || '').trim() || r.id; - const ne = r.enable !== false; - if ((om.display_name || '') !== nd || !!om.vision !== !!r.vision || (om.enable !== false) !== ne) { - edits.push({ path: ['platforms', pfEdit.idx, 'models', r.ref], value: { - id: om.id || r.id, display_name: nd, vision: !!r.vision, enable: ne, - } }); - } + if (!!om.vision !== !!r.vision) edits.push({ path: ['platforms', pfEdit.idx, 'models', r.ref, 'vision'], value: !!r.vision }); + if ((om.enable !== false) !== (r.enable !== false)) edits.push({ path: ['platforms', pfEdit.idx, 'models', r.ref, 'enable'], value: r.enable !== false }); } else { const id = String(r.id || '').trim(); - edits.push({ op: 'append', path: ['platforms', pfEdit.idx, 'models'], value: { - id, display_name: String(r.display_name || '').trim() || id, vision: !!r.vision, - } }); + const nv = { id }; + if (r.vision) nv.vision = true; + if (r.enable === false) nv.enable = false; + edits.push({ op: 'append', path: ['platforms', pfEdit.idx, 'models'], value: nv }); } }); const delMods = (p.models || []).map((_, i) => i).filter(i => !pfEdit.models.some(r => r.ref === i)).sort((a, b) => b - a); @@ -3438,10 +3424,8 @@ async function saveModelEditor() { if (!pfEdit) return; const add = pfEdit.idx < 0; - // 采集当前输入框值到工作态(避免用户只改最后一个框未触发 oninput 的边界) const name = $('mpe-name').value.trim(); const url = $('mpe-url').value.trim().replace(/\/+$/, ''); - const type = $('mpe-type').value.trim(); if (!url) return toast('请填写平台上游地址'); if (!pfEdit.models.length) return toast('至少保留一个模型'); if (!pfEdit.keys.length) return toast('至少保留一个 Key'); @@ -3455,11 +3439,17 @@ let edits; try { if (add) { - // 新增平台:一次 append 整个对象(name/url/type 留空由服务端规范化: name 取主机段、type 取 name) + // 新增平台:一次 append 整个对象(name 留空由服务端取主机段;type/concurrency/display_name 均不落配置,走各自缺省) edits = [{ op: 'append', path: ['platforms'], value: { - name, url, type, - keys: pfEdit.keys.map(r => ({ api_key: String(r.api_key || '').trim(), concurrency: Math.max(1, parseInt(r.concurrency, 10) || 1) })), - models: pfEdit.models.map(r => ({ id: String(r.id).trim(), display_name: String(r.display_name || '').trim() || String(r.id).trim(), vision: !!r.vision })), + name, url, + keys: pfEdit.keys.map(r => ({ api_key: String(r.api_key || '').trim() })), + models: pfEdit.models.map(r => { + const id = String(r.id).trim(); + const nv = { id }; + if (r.vision) nv.vision = true; + if (r.enable === false) nv.enable = false; + return nv; + }), } }]; } else { // 改名不影响 pi(数组位置);其余按原 ref 定位,见 buildPfEdits @@ -3531,10 +3521,9 @@ mAddModel: addPfModel, mDelModel: delPfModel, mKeyApi: function (i, v) { setPfKey(i, 'api_key', v); }, - mKeyCon: function (i, v) { setPfKey(i, 'concurrency', v); }, mModId: function (i, v) { setPfModel(i, 'id', v); }, - mModName: function (i, v) { setPfModel(i, 'display_name', v); }, mModVision: function (i, v) { setPfModel(i, 'vision', v); }, + mModEnable: function (i, v) { setPfModel(i, 'enable', v); }, mDelPlat: delPlatformFromModal, toggleGroup: toggleModelGroup, refreshBalance: refreshBalance,