fix: 恢复用户菜单(修改昵称/修改密码)

- userInfo 添加 onclick 触发用户菜单
- 添加 userMenu 下拉菜单(修改昵称/修改密码)
- 点击页面其他位置关闭菜单
This commit is contained in:
OP
2026-06-29 00:28:42 +08:00
parent 5d5ee9ecdc
commit c5697f8b7b
2 changed files with 17 additions and 3 deletions

View File

@@ -373,7 +373,13 @@ body{font-family:-apple-system,BlinkMacSystemFont,"SF Pro Display","SF Pro Text"
<div class="notif-list" id="notifList"><div class="notif-empty">暂无通知</div></div>
</div>
</div>
<span class="user-info" id="userInfo"></span>
<div class="export-wrap">
<span class="user-info" id="userInfo" onclick="toggleUserMenu(event)"></span>
<div class="export-menu" id="userMenu">
<a href="#" onclick="showChangeNick(event)">修改昵称</a>
<a href="#" onclick="showChangePwd(event)">修改密码</a>
</div>
</div>
<a href="/admin.html" class="admin-link" id="adminLink" style="display:none">管理</a>
<div class="export-wrap">
<button class="hdr-btn" onclick="toggleExport(event)">导出</button>
@@ -492,6 +498,7 @@ async function apiFetch(path,opts={}){
return res;
}
function toggleUserMenu(e){e.stopPropagation();$('userMenu').classList.toggle('show');}
async function checkAuth(){
if(!token){showLogin();return false;}
const res=await apiFetch('/auth/profile');
@@ -616,7 +623,7 @@ function toggleHideOthers(){hideOthers=!hideOthers;$('hideOthersIcon').textConte
function toggleMonth(ym){if(openMonths.has(ym))openMonths.delete(ym);else openMonths.add(ym);renderMonthPlan();}
function toggleExport(e){e.stopPropagation();$('exportMenu').classList.toggle('show');}
document.addEventListener('click',function(){$('exportMenu').classList.remove('show');});
document.addEventListener('click',function(){$('exportMenu').classList.remove('show');$('importMenu').classList.remove('show');$('userMenu').classList.remove('show');});
function download(filename,content,mime){const blob=new Blob(['\uFEFF'+content],{type:mime});const a=document.createElement('a');a.href=URL.createObjectURL(blob);a.download=filename;a.click();}
function exportCSV(e){e.preventDefault();if(!loans.length)return showToast('暂无数据可导出','info');let csv='借款人,借款日期,借款金额,年利率(%),总利息,分期数,还款方式,已还期数,状态\n';loans.forEach(l=>{const ti=l.schedule.reduce((s,r)=>s+r.it,0);const paid=l.paid.length+'/'+l.periods;const status=l.paid.length>=l.periods?'已还清':'还款中';csv+=`${escapeHtml(l.name)},${l.date},${l.amount},${l.rate},${ti.toFixed(2)},${l.periods},${methodLabel(l.method)},${paid},${status}\n`;});download('债务统计_'+today()+'.csv',csv,'text/csv;charset=utf-8');}
function exportJSON(e){e.preventDefault();if(!loans.length)return showToast('暂无数据可导出','info');const data=loans.map(l=>({借款人:l.name,借款日期:l.date,借款金额:l.amount,年利率:l.rate,分期数:l.periods,还款方式:methodLabel(l.method),已还期数:l.paid.length,状态:l.paid.length>=l.periods?'已还清':'还款中',还款计划:l.schedule.map(r=>({期数:r.p,日期:r.date,还款额:r.pay,本金:r.pr,利息:r.it}))}));download('债务统计_'+today()+'.json',JSON.stringify(data,null,2),'application/json;charset=utf-8');}