设置页用户卡:Google风双字母头像+居中布局+修改密码/退出登录按钮,移除重复的当前用户行

This commit is contained in:
2026-09-02 08:06:24 +08:00
parent 192db98c37
commit a0ceca6ed4
3 changed files with 42 additions and 39 deletions
+10 -4
View File
@@ -356,11 +356,17 @@ body {
.model-card-meta { font-size: 12px; color: #888; margin-top: 4px; }
/* ---- 设置页行 ---- */
.settings-row {
display: flex; align-items: center; justify-content: space-between; gap: 10px;
background: #fff; border-radius: 12px; padding: 12px 14px; margin-bottom: 10px;
box-shadow: 0 1px 4px rgba(30,40,90,0.06); font-size: 14px;
/* 设置页顶部用户卡:头像在上,用户名居中,下方等宽双按钮 */
.user-card { display: flex; flex-direction: column; align-items: center; padding: 20px 16px 16px; }
.user-avatar {
width: 64px; height: 64px; border-radius: 50%; border: none;
color: #fff; font-size: 26px; font-weight: 600; letter-spacing: 1px;
display: flex; align-items: center; justify-content: center;
box-shadow: 0 2px 6px rgba(30, 40, 90, 0.18); user-select: none;
}
.user-name { margin-top: 10px; font-size: 16px; font-weight: 600; color: #223; word-break: break-all; text-align: center; }
.user-acts { display: flex; gap: 10px; width: 100%; max-width: 360px; margin-top: 14px; }
.user-acts .ghost-btn { flex: 1; }
.ghost-btn.small { flex: none; padding: 6px 12px; font-size: 13px; border-radius: 8px; }
/* ---- 技能页(阶段 3) ---- */
+5 -9
View File
@@ -96,10 +96,6 @@
</div>
</div>
<div class="tab-body-area">
<div class="settings-row">
<span>当前用户:<b id="whoami" class="hidden">-</b></span>
<button class="ghost-btn small hidden" id="logout-btn" onclick="ui.logout()">退出登录</button>
</div>
<div id="cfg-sections"><div class="empty-tip">加载中…</div></div>
</div>
@@ -286,10 +282,10 @@
<div class="toast hidden" id="toast"></div>
<!-- 发版时更新 v 参数,避免移动端浏览器缓存旧 JS -->
<script src="/js/core.js?v=20260901q"></script>
<script src="/js/tasks.js?v=20260901q"></script>
<script src="/js/skills.js?v=20260901q"></script>
<script src="/js/models.js?v=20260901q"></script>
<script src="/js/settings.js?v=20260901q"></script>
<script src="/js/core.js?v=20260901r"></script>
<script src="/js/tasks.js?v=20260901r"></script>
<script src="/js/skills.js?v=20260901r"></script>
<script src="/js/models.js?v=20260901r"></script>
<script src="/js/settings.js?v=20260901r"></script>
</body>
</html>
+27 -26
View File
@@ -57,17 +57,35 @@ function kvPlain(label, v) {
return '<div class="cfg-kv"><label>' + esc(label) + '</label><b>' + esc(dispVal(v)) + '</b></div>';
}
// 账号卡(仅启用认证时显示):当前登录 + 修改密码(prompt 弹窗,免原密码,立即生效)
function accountCard(me) {
return '<div class="settings-card"><h4>账号</h4>' +
kvPlain('当前登录', me) +
'<button class="primary-btn" id="pwd-btn" style="width:100%;margin-top:8px" onclick="cfgUI.changePassword()">修改密码</button>' +
'<div class="cfg-note">修改立即生效并写回 config.yml;其他已登录设备需重新登录时才用新密码。</div></div>';
// 用户信息卡(仅启用认证时显示,页面顶部):Google 风双字母头像 + 用户名 + 操作按钮。
// 头像字母/配色均前端本地生成,无外部依赖。
const AVATAR_COLORS = ['#4285F4', '#EA4335', '#FBBC05', '#34A853', '#5C6BC0', '#00897B', '#8E24AA', '#F4511E'];
// 取用户名前两个字符:首字母大写、次字母小写(kicer→Ki);单字符只显一个;
// 中文取前两字,charAt 大小写对汉字无副作用,无需特判
function userInitials(name) {
const s = String(name || '').trim();
if (!s) return '?';
const two = s.slice(0, 2);
return two.charAt(0).toUpperCase() + (two.length > 1 ? two.charAt(1).toLowerCase() : '');
}
function avatarColor(name) {
let h = 0;
for (const ch of String(name || '')) h = (h * 31 + ch.codePointAt(0)) >>> 0;
return AVATAR_COLORS[h % AVATAR_COLORS.length];
}
function userCard(me) {
return '<div class="settings-card user-card">' +
'<div class="user-avatar" style="background:' + avatarColor(me) + '">' + esc(userInitials(me)) + '</div>' +
'<div class="user-name">' + esc(me) + '</div>' +
'<div class="user-acts">' +
'<button class="ghost-btn" onclick="cfgUI.changePassword()">修改密码</button>' +
'<button class="ghost-btn" onclick="ui.logout()">退出登录</button>' +
'</div></div>';
}
async function changePassword() {
const btn = $('pwd-btn');
if (btn) btn.disabled = true;
try {
const newP = await promptModal('修改密码', '新密码,至少 6 位', '', { type: 'password' });
if (newP == null) return;
@@ -76,8 +94,6 @@ async function changePassword() {
toast('密码已修改,立即生效');
} catch (e) {
toast('修改失败:' + e.message);
} finally {
if (btn) btn.disabled = false;
}
}
@@ -121,7 +137,6 @@ function formCard() {
}
async function loadSettings() {
refreshUser();
bindDirtyMark();
const el = $('cfg-sections');
if (!el) return;
@@ -133,26 +148,12 @@ async function loadSettings() {
req('GET', '/api/me').catch(function () { return { user: null }; }), // 未启用认证时无此路由
]);
effCfg = cg.effective || {};
el.innerHTML = (st.auth_enabled && me && me.user ? accountCard(me.user) : '') + svcCard(st) + formCard();
el.innerHTML = (st.auth_enabled && me && me.user ? userCard(me.user) : '') + svcCard(st) + formCard();
} catch (e) {
el.innerHTML = '<div class="empty-tip">加载失败:' + esc(e.message) + '</div>';
}
}
// 显示登录用户(沿用 1.0 逻辑;未启用认证时静默跳过)
async function refreshUser() {
try {
const me = await req('GET', '/api/me');
const who = $('whoami');
if (who && me && me.user) {
who.textContent = me.user;
who.classList.remove('hidden');
}
const out = $('logout-btn');
if (out) out.classList.toggle('hidden', !(me && me.user));
} catch (_) { /* 未启用认证 */ }
}
// 未保存改动标红:委托监听(#cfg-sections 容器常驻,innerHTML 重建不影响)
let dirtyBound = false;
function bindDirtyMark() {