feat: 实现积分与等级系统 + 签到功能 + 下拉菜单优化
- User 模型增加 exp 字段,等级规则 Lv0-Lv6 - 新增签到记录(UserCheckIn)与任务记录(UserTask)模型,唯一索引防重 - 自动签到:AuthMiddleware 验证会话后,基于 Asia/Shanghai 自然日自动签到 +5 经验 - 手动签到:下拉菜单"签到"按钮兜底,已签到显示"今日已签到"并禁用 - 首次任务经验:上传头像/设置用户名/设置个性签名各 +10,审核通过与直接更新均触发 - 经验值变动后自动比对等级,升级时通过通知系统发送"恭喜提升至 LvX" - 下拉菜单重构:顶部头像+用户名+LvX 等级标签,菜单项增加左侧图标,优化布局样式 - 新增 API:POST /api/level/checkin、GET /api/level/info
This commit is contained in:
@ -262,17 +262,65 @@ header {
|
||||
}
|
||||
|
||||
.nav-dropdown-header {
|
||||
padding: .75rem 1rem;
|
||||
font-weight: 600;
|
||||
font-size: .9rem;
|
||||
color: var(--color-text);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .75rem;
|
||||
padding: 1rem;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.nav-dropdown-avatar {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 50%;
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
background: var(--color-accent);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #fff;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.nav-dropdown-avatar img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.nav-dropdown-meta {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.nav-dropdown-username {
|
||||
font-weight: 600;
|
||||
font-size: .95rem;
|
||||
color: var(--color-text);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.nav-dropdown-level {
|
||||
display: inline-block;
|
||||
margin-top: .2rem;
|
||||
padding: .1rem .5rem;
|
||||
border-radius: 4px;
|
||||
background: linear-gradient(135deg, #ff6b6b, #feca57);
|
||||
color: #fff;
|
||||
font-size: .75rem;
|
||||
font-weight: 700;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.nav-dropdown-item {
|
||||
display: block !important;
|
||||
padding: .6rem 1rem !important;
|
||||
display: flex !important;
|
||||
align-items: center;
|
||||
gap: .6rem;
|
||||
padding: .65rem 1rem !important;
|
||||
font-size: .9rem;
|
||||
color: var(--color-text-light) !important;
|
||||
transition: background .15s ease, color .15s ease;
|
||||
@ -291,6 +339,28 @@ header {
|
||||
color: var(--color-danger) !important;
|
||||
}
|
||||
|
||||
.nav-dropdown-icon {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
flex-shrink: 0;
|
||||
opacity: .7;
|
||||
}
|
||||
|
||||
.nav-dropdown-item:hover .nav-dropdown-icon {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.nav-dropdown-item.disabled {
|
||||
opacity: .5;
|
||||
cursor: not-allowed;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.nav-dropdown-item.disabled:hover {
|
||||
background: transparent;
|
||||
color: var(--color-text-light) !important;
|
||||
}
|
||||
|
||||
.mobile-menu-btn {
|
||||
display: none;
|
||||
background: none;
|
||||
|
||||
@ -283,6 +283,59 @@
|
||||
setInterval(pollUnread, POLL_INTERVAL);
|
||||
}
|
||||
|
||||
// ---- Level / Check-in ----
|
||||
var checkInBtn = document.getElementById('checkInBtn');
|
||||
if (checkInBtn) {
|
||||
// 页面加载时查询等级和签到状态
|
||||
fetch('/api/level/info')
|
||||
.then(function (res) {
|
||||
if (!res.ok) return;
|
||||
return res.json();
|
||||
})
|
||||
.then(function (data) {
|
||||
if (!data || !data.success) return;
|
||||
var d = data.data || {};
|
||||
if (d.checked_in) {
|
||||
setCheckInDone();
|
||||
}
|
||||
})
|
||||
.catch(function () {});
|
||||
|
||||
function setCheckInDone() {
|
||||
checkInBtn.classList.add('disabled');
|
||||
var span = checkInBtn.querySelector('span');
|
||||
if (span) span.textContent = '今日已签到';
|
||||
}
|
||||
|
||||
checkInBtn.addEventListener('click', function () {
|
||||
if (checkInBtn.classList.contains('disabled')) return;
|
||||
|
||||
fetch('/api/level/checkin', { method: 'POST' })
|
||||
.then(function (res) {
|
||||
if (!res.ok) return;
|
||||
return res.json();
|
||||
})
|
||||
.then(function (data) {
|
||||
if (!data || !data.success) return;
|
||||
var d = data.data || {};
|
||||
if (!d.checked_in) {
|
||||
setCheckInDone();
|
||||
return;
|
||||
}
|
||||
setCheckInDone();
|
||||
if (d.level_up) {
|
||||
window.MetaLab.toast(document.querySelector('.toast'), '恭喜您!您的等级已提升至 Lv' + d.level, false);
|
||||
}
|
||||
// 刷新等级展示
|
||||
var levelEl = document.querySelector('.nav-dropdown-level');
|
||||
if (levelEl) {
|
||||
levelEl.textContent = 'Lv' + d.level;
|
||||
}
|
||||
})
|
||||
.catch(function () {});
|
||||
});
|
||||
}
|
||||
|
||||
// ---- Auto-refresh token (silent) ----
|
||||
// 场景 A:页面开着时,每 10 分钟静默续期(保持 access token 不过期)
|
||||
// 场景 B:关浏览器 15+ min 后回来,access token 过期但 refresh 仍有效
|
||||
|
||||
Reference in New Issue
Block a user