From 7260f47ad78a0b4ac149c93f1b55cb50a75c3a1f Mon Sep 17 00:00:00 2001 From: kicer Date: Fri, 25 Sep 2026 18:02:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=94=BB=E5=83=8F=E5=B9=B6?= =?UTF-8?q?=E8=BF=9B=E8=B4=A6=E6=88=B7=E9=A1=B5(=E5=8E=BB=E6=8E=89?= =?UTF-8?q?=E4=BA=8C=E7=BA=A7=E9=A1=B5=E4=B8=8E=E5=85=A5=E5=8F=A3=E5=8D=A1?= =?UTF-8?q?):setPageAccount=20=E5=90=8C=E6=97=B6=E6=8B=89=20/api/me=20?= =?UTF-8?q?=E4=B8=8E=20/api/profile,=E7=94=BB=E5=83=8F=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=8D=A1(=E5=90=AF=E7=94=A8=E5=8B=BE=E9=80=89+=E4=B8=89?= =?UTF-8?q?=E5=AD=97=E6=AE=B5+=E4=BF=9D=E5=AD=98)=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E5=B9=B3=E9=93=BA=E5=9C=A8=E8=B4=A6=E6=88=B7=E5=8D=A1=E4=B8=8B?= =?UTF-8?q?=E6=96=B9;=E6=9C=AA=E5=90=AF=E7=94=A8=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E6=97=B6=E4=B8=8D=E5=86=8D=E6=95=B4=E9=A1=B5=E7=A9=BA=E6=8F=90?= =?UTF-8?q?=E7=A4=BA,=E4=BB=85=E6=97=A0=E5=AF=86=E7=A0=81/=E7=99=BB?= =?UTF-8?q?=E5=87=BA=E5=8D=A1=E8=80=8C=E7=94=BB=E5=83=8F=E4=BB=8D=E5=8F=AF?= =?UTF-8?q?=E7=94=A8(=E9=9A=90=E5=BC=8F=E5=8D=95=E7=94=A8=E6=88=B7);?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=90=8E=20renderSetPage=20=E9=87=8D?= =?UTF-8?q?=E6=8B=89=E5=88=B7=E6=96=B0=E5=81=9C=E7=94=A8=E5=BE=BD=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/server/public/js/settings.js | 52 +++++++++++--------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/app/server/public/js/settings.js b/app/server/public/js/settings.js index 2ec215b..d8a5847 100644 --- a/app/server/public/js/settings.js +++ b/app/server/public/js/settings.js @@ -250,7 +250,6 @@ const ctx = () => tok === setTok && setTop() === p; // 异步回包时页面可能已切走 if (p === 'home') return setPageHome(ctx); if (p === 'account') return setPageAccount(ctx); - if (p === 'profile') return setPageProfile(ctx); if (p === 'service') return setPageService(ctx); if (p === 'cfg-editor') return setPageCfgEditor(ctx); if (p === 'skills') return setPageSkills(ctx); @@ -339,27 +338,19 @@ setTitle('账户'); setActions(''); setBody('
加载中…
'); - // 单个 /api/me 即可判认证开关:启用认证时中间件保证已登录,user 必有; - // 未启用时 createAuth 提前返回,该路由不存在 → 404。无需再拉 /api/system/status - let me; - try { - me = await req('GET', '/api/me'); - } catch (e) { - if (ctx()) setBody('
' + - (e.status === 404 ? '未启用登录认证,无账户设置。' : '加载失败:' + esc(e.message)) + '
'); - return; - } + // 单个 /api/me 判认证开关:启用时中间件保证已登录,user 必有; + // 未启用时该路由 404 → 只是没有密码/登出卡,画像仍渲染(未认证 = 空串键隐式单用户)。 + let me = null; + try { const r = await req('GET', '/api/me'); if (r && r.user) me = r; } catch (_) { /* 404 等一律按无账户信息处理 */ } + let p = null, pErr = ''; + try { p = await req('GET', '/api/profile'); } catch (e) { pErr = String((e && e.message) || e); } if (!ctx()) return; - if (!me || !me.user) { - setBody('
未启用登录认证,无账户设置。
'); - return; - } - setBody('
' + userCardHtml(me.user) + - '' + - '
'); + let html = '
'; + if (me) html += userCardHtml(me.user); + html += pErr + ? '

用户画像

加载失败:' + esc(pErr) + '
' + : profileCardHtml(p); + setBody(html + '
'); } async function changePassword() { try { @@ -370,21 +361,14 @@ toast('密码已修改,立即生效'); } catch (e) { toast('修改失败:' + e.message); } } - // ---------- 页:用户画像(三字段 + 总开关;「近期关注」注入时现取会话标题,不展示不维护) ---------- + // ---------- 页:账户——用户画像编辑卡直接渲染在账户页(无二级页;保存后 renderSetPage 重拉刷新停用徽标) ---------- const PROFILE_FIELDS = [ ['honorific', '称谓', '希望被怎么称呼'], ['industry', '行业', '影响术语与默认假设'], ['preference', '偏好', '语言 / 交付格式等输出要求'], ]; - async function setPageProfile(ctx) { - setTitle('用户画像'); - setActions(''); - setBody('
加载中…
'); - let p; - try { p = await req('GET', '/api/profile'); } - catch (e) { if (ctx()) setBody('
加载失败:' + esc(e.message) + '
'); return; } - if (!ctx()) return; - let html = '

用户画像' + + function profileCardHtml(p) { + let html = '

用户画像' + (p.enabled === false ? ' 已停用' : '') + '

' + '
'; for (const [k, name, ph] of PROFILE_FIELDS) { @@ -394,13 +378,13 @@ } html += '' + '
画像只记「不知道就会做错」的信息,新会话开始时作为背景注入(会话内不更新;清空字段保存即抹除)。' + - '停用后不再注入也不再更新,重新启用仅对新会话/清空后的会话生效。近期关注(最近会话标题)自动带入背景,无需维护。

'; - setBody(html); + '停用后不再注入也不再更新,重新启用仅对新会话/清空后的会话生效。近期关注(最近会话标题)自动带入背景,无需维护。
'; + return html; } async function saveProfile() { const body = { enabled: $('prof-enabled').checked }; for (const [k] of PROFILE_FIELDS) { const el = $('prof-' + k); if (el) body[k] = el.value.trim(); } - try { await req('PUT', '/api/profile', body); toast('已保存,新会话生效'); } + try { await req('PUT', '/api/profile', body); toast('已保存,新会话生效'); renderSetPage(); } catch (e) { toast('保存失败:' + e.message); } }