feat: 设置页面添加管理后台入口
- 在账户区域添加"进入管理后台"按钮(仅管理员可见) - 使用 localStorage 缓存用户信息确保显示正确 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7174,6 +7174,11 @@ def get_settings_page_html() -> str:
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 管理后台入口(仅管理员可见) -->
|
||||
<a href="/admin" id="admin-entry" class="btn btn-primary" style="width: 100%; display: none; text-align: center; text-decoration: none; margin-bottom: 12px;">
|
||||
进入管理后台
|
||||
</a>
|
||||
|
||||
<button type="button" class="btn btn-danger" onclick="logoutAccount()" style="width: 100%;">
|
||||
退出登录
|
||||
</button>
|
||||
@@ -7631,12 +7636,37 @@ def get_settings_page_html() -> str:
|
||||
document.getElementById('account-role').textContent = user.is_admin ? '管理员账户' : '普通用户';
|
||||
if (user.is_admin) {
|
||||
document.getElementById('account-badge').style.display = 'block';
|
||||
// 显示管理后台入口
|
||||
document.getElementById('admin-entry').style.display = 'block';
|
||||
}
|
||||
// 保存到 localStorage
|
||||
localStorage.setItem('user', JSON.stringify(user));
|
||||
} else {
|
||||
// 如果获取失败,尝试从 localStorage 获取
|
||||
const cachedUser = localStorage.getItem('user');
|
||||
if (cachedUser) {
|
||||
const user = JSON.parse(cachedUser);
|
||||
document.getElementById('account-name').textContent = user.name;
|
||||
document.getElementById('account-role').textContent = user.is_admin ? '管理员账户' : '普通用户';
|
||||
if (user.is_admin) {
|
||||
document.getElementById('account-badge').style.display = 'block';
|
||||
document.getElementById('admin-entry').style.display = 'block';
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载账户信息失败:', error);
|
||||
// 尝试从 localStorage 获取
|
||||
const cachedUser = localStorage.getItem('user');
|
||||
if (cachedUser) {
|
||||
const user = JSON.parse(cachedUser);
|
||||
document.getElementById('account-name').textContent = user.name;
|
||||
document.getElementById('account-role').textContent = user.is_admin ? '管理员账户' : '普通用户';
|
||||
if (user.is_admin) {
|
||||
document.getElementById('account-badge').style.display = 'block';
|
||||
document.getElementById('admin-entry').style.display = 'block';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user