1
This commit is contained in:
parent
9958af7c3f
commit
9491012938
|
|
@ -891,31 +891,7 @@ const GlobalConfig = () => {
|
|||
}
|
||||
|
||||
|
||||
const loadUsersAndAccounts = async () => {
|
||||
if (!isAdmin) return
|
||||
try {
|
||||
setBusy(true)
|
||||
const [users, accounts] = await Promise.all([
|
||||
api.getUsersDetailed ? api.getUsersDetailed() : api.get('/admin/users/detailed').then(r => r.data),
|
||||
api.getAccounts(),
|
||||
])
|
||||
setUsersDetailed(Array.isArray(users) ? users : [])
|
||||
setAccountsAdmin(Array.isArray(accounts) ? accounts : [])
|
||||
const initMap = {}
|
||||
;(Array.isArray(users) ? users : []).forEach(u => {
|
||||
initMap[u.id] = ''
|
||||
})
|
||||
setLinkAccountMap(initMap)
|
||||
} catch (e) {
|
||||
setMessage(e?.message || '加载失败')
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (isAdmin) loadUsersAndAccounts()
|
||||
}, [isAdmin])
|
||||
|
||||
|
||||
if (loading) {
|
||||
return <div className="global-config">加载中...</div>
|
||||
|
|
@ -1005,32 +981,7 @@ const GlobalConfig = () => {
|
|||
|
||||
|
||||
|
||||
const handleGrant = async (userId) => {
|
||||
const aid = parseInt(String(linkAccountMap[userId] || ''), 10)
|
||||
if (!Number.isFinite(aid) || aid <= 0) return
|
||||
try {
|
||||
setBusy(true)
|
||||
await api.grantUserAccount(userId, aid, linkRole)
|
||||
setMessage('已关联账号')
|
||||
await loadUsersAndAccounts()
|
||||
} catch (e) {
|
||||
setMessage(e?.message || '关联失败')
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
const handleRevoke = async (userId, accountId) => {
|
||||
try {
|
||||
setBusy(true)
|
||||
await api.revokeUserAccount(userId, accountId)
|
||||
setMessage('已取消关联')
|
||||
await loadUsersAndAccounts()
|
||||
} catch (e) {
|
||||
setMessage(e?.message || '取消失败')
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div className="global-config">
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user