feat: super admin badge — earliest admin shows 超级管理员 in user list
- /api/users: mark is_super for the earliest-registered admin (matches the auto-promotion migration semantics) - AdminUsers: render 超级管理员 badge for is_super, 管理员 otherwise - i18n keys admin.user.roleSuper (zh/en) - Mobile settings nav: active tab gets top-left/top-right rounded corners only (desktop unchanged)
This commit is contained in:
1 parent
f0867935ac
commit
d757bde780
5 files changed
+17
-4
No files matched your search
@@ -11,6 +11,12 @@ export async function GET(req) {
|
|||||||
const username = url.searchParams.get('username');
|
const username = url.searchParams.get('username');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// 超级管理员 = 最早注册的 admin(对齐迁移:无 admin 时自动提升最早注册用户)
|
||||||
|
const superR = await pool.query(
|
||||||
|
`SELECT id FROM users WHERE role = 'admin' ORDER BY created_at ASC, id ASC LIMIT 1`
|
||||||
|
);
|
||||||
|
const superAdminId = superR.rows[0]?.id || null;
|
||||||
|
|
||||||
let query = 'SELECT id, username, avatar_url, bio, role, created_at FROM users';
|
let query = 'SELECT id, username, avatar_url, bio, role, created_at FROM users';
|
||||||
const params = [];
|
const params = [];
|
||||||
if (username) {
|
if (username) {
|
||||||
@@ -19,7 +25,9 @@ export async function GET(req) {
|
|||||||
}
|
}
|
||||||
query += ' ORDER BY created_at DESC';
|
query += ' ORDER BY created_at DESC';
|
||||||
const r = await pool.query(query, params);
|
const r = await pool.query(query, params);
|
||||||
return Response.json(r.rows);
|
// 标记超级管理员(前端显示"超级管理员")
|
||||||
|
const rows = r.rows.map((u) => ({ ...u, is_super: u.id === superAdminId }));
|
||||||
|
return Response.json(rows);
|
||||||
} catch {
|
} catch {
|
||||||
return Response.json({ error: '服务器错误' }, { status: 500 });
|
return Response.json({ error: '服务器错误' }, { status: 500 });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2855,6 +2855,9 @@ a.btn-secondary {
|
|||||||
.settings-nav-item.active {
|
.settings-nav-item.active {
|
||||||
border-left-color: transparent;
|
border-left-color: transparent;
|
||||||
border-bottom-color: var(--primary);
|
border-bottom-color: var(--primary);
|
||||||
|
/* 手机端选中 tab:仅左上/右上圆角(桌面端保持直角不变) */
|
||||||
|
border-top-left-radius: 8px;
|
||||||
|
border-top-right-radius: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings-content {
|
.settings-content {
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ export default function AdminUsers() {
|
|||||||
display: 'inline-block', padding: '2px 10px', borderRadius: 4, fontSize: 12, fontWeight: 500,
|
display: 'inline-block', padding: '2px 10px', borderRadius: 4, fontSize: 12, fontWeight: 500,
|
||||||
...(isAdmin ? { background: '#6366f1', color: '#fff' } : { background: 'var(--border)', color: 'var(--text-secondary)' }),
|
...(isAdmin ? { background: '#6366f1', color: '#fff' } : { background: 'var(--border)', color: 'var(--text-secondary)' }),
|
||||||
}}>
|
}}>
|
||||||
{isAdmin ? t('admin.user.roleAdmin') : t('admin.user.roleUser')}
|
{isAdmin ? (u.is_super ? t('admin.user.roleSuper') : t('admin.user.roleAdmin')) : t('admin.user.roleUser')}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td style={{ padding: '10px 12px', color: '#94a3b8', fontSize: 13 }}>
|
<td style={{ padding: '10px 12px', color: '#94a3b8', fontSize: 13 }}>
|
||||||
|
|||||||
+2
-1
@@ -208,7 +208,8 @@
|
|||||||
"you": "You",
|
"you": "You",
|
||||||
"cannotSelf": "You cannot edit yourself",
|
"cannotSelf": "You cannot edit yourself",
|
||||||
"makeUser": "Make user",
|
"makeUser": "Make user",
|
||||||
"makeAdmin": "Make admin"
|
"makeAdmin": "Make admin",
|
||||||
|
"roleSuper": "Super admin"
|
||||||
},
|
},
|
||||||
"log": {
|
"log": {
|
||||||
"empty": "No logs",
|
"empty": "No logs",
|
||||||
|
|||||||
+2
-1
@@ -208,7 +208,8 @@
|
|||||||
"you": "你",
|
"you": "你",
|
||||||
"cannotSelf": "不可操作自己",
|
"cannotSelf": "不可操作自己",
|
||||||
"makeUser": "设为普通用户",
|
"makeUser": "设为普通用户",
|
||||||
"makeAdmin": "设为管理员"
|
"makeAdmin": "设为管理员",
|
||||||
|
"roleSuper": "超级管理员"
|
||||||
},
|
},
|
||||||
"log": {
|
"log": {
|
||||||
"empty": "暂无日志",
|
"empty": "暂无日志",
|
||||||
|
|||||||
Reference in new issue
Block a user