迁移用户管理页;Table 支持整行选中、StatGrid 支持自定义降列节奏、Select 支持 title

main
mula.liu 2026-11-01 16:54:51 +08:00
parent b8734c9adc
commit c2bdd6e070
8 changed files with 366 additions and 21 deletions

View File

@ -28,11 +28,13 @@ export type SelectProps = {
className?: string
id?: string
name?: string
/** 禁用时要解释原因(「不能修改自己的角色」),否则灰掉的下拉只会让人反复点 */
title?: string
}
export function Select({
value, onChange, options, disabled, placeholder = '请选择', searchThreshold = 8,
size = 'md', ariaLabel, className, id, name
size = 'md', ariaLabel, className, id, name, title
}: SelectProps) {
const opts = useMemo(() => toOptions(options), [options])
const uid = useId()
@ -141,7 +143,7 @@ export function Select({
return (
<span className={cn('relative inline-flex w-full min-w-0 align-middle', open && 'z-[401]', className)}>
<button ref={triggerRef} type="button" id={id} disabled={disabled} aria-label={ariaLabel || undefined}
aria-haspopup="listbox" aria-expanded={open} data-name={name}
title={title} aria-haspopup="listbox" aria-expanded={open} data-name={name}
aria-activedescendant={open && active >= 0 ? `${uid}-o${active}` : undefined}
className={triggerCls({ open, size, disabled })}
onClick={() => toggle()} onKeyDown={onKeydown}>

View File

@ -100,9 +100,9 @@ export function FormRow({ children, cols, tight, stack, className }: {
: `repeat(${cols},minmax(0,1fr))`
return (
<div className={cn('grid mb-[10px] min-w-0 [&>*]:min-w-0',
cols === undefined && 'max-[1180px]:grid-cols-2',
(cols === 3 || cols === 4) && 'max-[1180px]:grid-cols-2',
(cols === 4 || cols === 6) && 'max-[900px]:grid-cols-2',
cols === undefined && 'max-mid:grid-cols-2',
(cols === 3 || cols === 4) && 'max-mid:grid-cols-2',
(cols === 4 || cols === 6) && 'max-nav:grid-cols-2',
stack && 'gap-y-[10px] [&>*]:flex-col [&>*]:items-stretch [&>*]:gap-[5px] [&>*]:flex-none [&>*]:w-auto [&>*:not(span)]:w-full',
className)}
style={{ gridTemplateColumns: tracks, gap: tight ? 8 : undefined }}>

View File

@ -60,8 +60,8 @@ export function Drawer({ open, onClose, eyebrow, title, sub, children, actions,
onMouseDown={(e) => { if (closeOnBackdrop && e.target === e.currentTarget) onClose() }}>
<section role="dialog" aria-modal="true" aria-label={typeof label === 'string' ? label : undefined}
className={cn('flex flex-col min-w-0 h-screen border-l border-line-strong bg-shell shadow-drawer',
'w-[min(1360px,calc(100vw-20px))] max-[1440px]:w-[calc(100vw-16px)] max-[820px]:w-screen')}>
<header className="flex-none flex justify-between items-start gap-[14px] p-[20px_24px_15px] max-[820px]:p-[20px_14px_15px] border-b border-[--c-bg-emphasis] bg-[linear-gradient(120deg,var(--c-bg-raised),var(--c-bg-panel)_55%)]">
'w-[min(1360px,calc(100vw-20px))] max-huge:w-[calc(100vw-16px)] max-short:w-screen')}>
<header className="flex-none flex justify-between items-start gap-[14px] p-[20px_24px_15px] max-short:p-[20px_14px_15px] border-b border-[--c-bg-emphasis] bg-[linear-gradient(120deg,var(--c-bg-raised),var(--c-bg-panel)_55%)]">
<div className="min-w-0">
{eyebrow && <small className="text-tiny tracking-[1.6px] text-muted font-bold">{eyebrow}</small>}
<h2 className="text-lg font-bold mt-[5px] mb-0">{title}</h2>
@ -70,11 +70,11 @@ export function Drawer({ open, onClose, eyebrow, title, sub, children, actions,
<button type="button" aria-label="关闭" onClick={onClose}
className="flex-none grid place-items-center w-(--ctl-h-md) h-(--ctl-h-md) border border-line-strong rounded-tile bg-card text-ink-2 text-ui hover:border-[--c-accent-deep] hover:text-accent-bright hover:bg-accent-tint">✕</button>
</header>
<div className="flex-1 min-w-0 overflow-y-auto scrollbar-slim p-[20px_24px_24px] max-[820px]:p-[20px_14px_14px] [scrollbar-gutter:stable]">
<div className="flex-1 min-w-0 overflow-y-auto scrollbar-slim p-[20px_24px_24px] max-short:p-[20px_14px_14px] [scrollbar-gutter:stable]">
{children}
</div>
{actions && (
<footer className="flex-none flex items-center gap-2 p-[14px_24px] max-[820px]:p-[14px] border-t border-line bg-raised [--ctl-h:var(--ctl-h-md)]">
<footer className="flex-none flex items-center gap-2 p-[14px_24px] max-short:p-[14px] border-t border-line bg-raised [--ctl-h:var(--ctl-h-md)]">
{actions}
</footer>
)}

View File

@ -8,6 +8,11 @@
import type { ReactNode } from 'react'
import { cn } from '../../lib/cn'
/** 次要说明文字(.muted):11px + 最淡的一级灰,表格单元格的第二行、附注都用它 */
export const MUTED = 'text-faint text-caption'
/** 弱化 + 等宽(.muted.mono):id、路径、枚举码 */
export const MUTED_MONO = 'text-faint text-[10.5px] font-mono tracking-[-.2px]'
/** 站内文字链配色(.link):<Link> 没有组件形态,用这个类名常量保持一致 */
export const LINK_CLS = 'text-success text-caption no-underline hover:underline'

View File

@ -6,7 +6,7 @@ export function Panel({ children, className, style, pad = true }: {
children?: ReactNode; className?: string; style?: CSSProperties; pad?: boolean
}) {
return (
<section style={style} className={cn('bg-panel border border-line rounded-block p-[18px] max-[560px]:p-[13px] min-w-0', pad && '', className)}>
<section style={style} className={cn('bg-panel border border-line rounded-block p-[18px] max-narrow:p-[13px] min-w-0', pad && '', className)}>
{children}
</section>
)
@ -53,18 +53,37 @@ export function SectionTitle({ children, action, className }: { children: ReactN
/** 指标卡 */
export function Stat({ label, value, hint, className }: { label: ReactNode; value: ReactNode; hint?: ReactNode; className?: string }) {
return (
<div className={cn('bg-panel border border-line rounded-block p-[18px] min-w-0 max-[560px]:p-[13px]', className)}>
<div className={cn('bg-panel border border-line rounded-block p-[18px] min-w-0 max-narrow:p-[13px]', className)}>
<small className="block text-muted text-tiny">{label}</small>
<b className="block text-num mt-[9px] font-bold max-[560px]:text-num-sm break-words">{value}</b>
<b className="block text-num mt-[9px] font-bold max-narrow:text-num-sm break-words">{value}</b>
{hint && <small className="block text-faint text-tiny mt-[6px]">{hint}</small>}
</div>
)
}
/** 指标卡栅格:4 → 2 → 1 由容器自己降列,页面不写 @media */
export function StatGrid({ children, cols = 4, className }: { children: ReactNode; cols?: number; className?: string }) {
/* 降列档位写成字面量:Tailwind 按源码里的字符串生成工具类,
运行时拼出来的 `max-[${w}px]:grid-cols-${c}` 根本不会被扫描到。 */
const STEP_CLS: Record<string, string> = {
'huge:3': 'max-huge:grid-cols-3', 'mid:3': 'max-mid:grid-cols-3', 'mid2:3': 'max-mid2:grid-cols-3',
'nav:2': 'max-nav:grid-cols-2', 'short:2': 'max-short:grid-cols-2', 'mid2:2': 'max-mid2:grid-cols-2',
'tiny:1': 'max-tiny:grid-cols-1', 'narrow:1': 'max-narrow:grid-cols-1', 'short:1': 'max-short:grid-cols-1'
}
export type StatStep = { at: 'huge' | 'mid' | 'mid2' | 'nav' | 'short' | 'tiny' | 'narrow'; cols: 1 | 2 | 3 }
/**
* 指标卡栅格:列数与降列节奏都由容器声明,页面不写 @media。
* 默认沿用旧站 .stats:4 列 → ≤900 两列 → ≤560 收紧间距(卡片本身跟着换小字号内边距)。
* 卡片数不是 4 的页面把节奏写进 steps(用户管理 5 张卡:≤1280 三列、≤820 两列),
* 这样例外是可见的参数,而不是又一段散回样式表、没人敢删的 @media。
*/
export function StatGrid({ children, cols = 4, steps, className }: {
children: ReactNode; cols?: number; steps?: StatStep[]; className?: string
}) {
return (
<div className={cn('grid gap-3 mb-[17px] grid-cols-[repeat(var(--cols),minmax(0,1fr))] max-[1100px]:grid-cols-2 max-[560px]:gap-2', className)}
<div className={cn('grid gap-3 mb-[17px] grid-cols-[repeat(var(--cols),minmax(0,1fr))] min-w-0',
!steps && 'max-nav:grid-cols-2',
...(steps || []).map((st) => STEP_CLS[`${st.at}:${st.cols}`]),
'max-narrow:gap-2', className)}
style={{ ['--cols' as string]: cols }}>
{children}
</div>

View File

@ -13,7 +13,7 @@ export function LogRow({ time, who, children, level, className, onClick }: {
}) {
return (
<div onClick={onClick}
className={cn('grid grid-cols-[54px_minmax(86px,108px)_minmax(0,1fr)] gap-[9px] p-[8px_2px] border-b border-line-soft text-body max-[560px]:grid-cols-[50px_minmax(0,1fr)_66px]',
className={cn('grid grid-cols-[54px_minmax(86px,108px)_minmax(0,1fr)] gap-[9px] p-[8px_2px] border-b border-line-soft text-body max-narrow:grid-cols-[50px_minmax(0,1fr)_66px]',
onClick && 'cursor-pointer',
level === 'error' && 'text-danger',
(level === 'warning' || level === 'warn') && 'text-warn', className)}>

View File

@ -17,13 +17,20 @@ export function TableBox({ children, className, maxHeight = 520 }: { children: R
)
}
export function Table({ children, className, minWidth = 720 }: { children: ReactNode; className?: string; minWidth?: number }) {
export function Table({ children, className, minWidth = 720, pickable }: {
children: ReactNode; className?: string; minWidth?: number; pickable?: boolean
}) {
return (
<table className={cn('w-full border-collapse text-label min-w-0',
<table style={minWidth ? { minWidth } : undefined}
className={cn('w-full border-collapse text-label min-w-0',
'[&_th]:text-left [&_th]:text-tiny [&_th]:tracking-[.8px] [&_th]:text-faint [&_th]:font-bold [&_th]:px-2 [&_th]:py-[7px]',
'[&_th]:border-b [&_th]:border-line [&_th]:whitespace-nowrap [&_th]:bg-shell [&_th]:sticky [&_th]:top-0 [&_th]:z-[1]',
'[&_td]:px-2 [&_td]:py-[9px] [&_td]:border-b [&_td]:border-line-soft [&_td]:align-middle',
'[&_tbody_tr:hover>td]:bg-panel',
/* 整行是热区的表(账号列表、模型列表):指针形状说明「点这一行有用」 */
pickable && '[&_tbody_tr]:cursor-pointer',
/* 选中态排在 hover 之后:同一行既被选中又被悬停时,仍然要看得出选中的是它 */
pickable && '[&_tbody_tr[data-chosen]>td]:bg-accent-tint [&_tbody_tr[data-chosen]>td]:border-b-accent-line',
className)}>
{children}
</table>
@ -34,7 +41,7 @@ export function Table({ children, className, minWidth = 720 }: { children: React
export function WideTable({ children, className, minWidth = 720 }: { children: ReactNode; className?: string; minWidth?: number }) {
return (
<TableBox>
<div style={{ minWidth }} className="max-[560px]:min-w-[720px]">
<div style={{ minWidth }} className="max-narrow:min-w-[720px]">
<Table className={className}>{children}</Table>
</div>
</TableBox>

View File

@ -1,4 +1,316 @@
/** 待迁移:用户管理(占位,见 .local/vue-ref/src/views/UserAdmin.vue) */
/**
* 用户管理(仅管理员):账号列表 / 新建 / 详情编辑 / 重置密码 / 操作流水。
*
* 账号列表到点自动刷新,页头不放任何刷新控件。但自动刷新不能把管理员
* 正在敲的表单冲掉:syncEdit() 会用服务端值重写 edit/reset 两个表单,
* 因此只要这几块里有没保存的内容,就暂停轮询,保存完自动恢复。
*/
import { useCallback, useEffect, useState } from 'react'
import * as api from '../api/client'
import { fmtAgo, fmtTime } from '../lib/format'
import { useAutoRefresh } from '../hooks'
import { SecretInput, Select } from '../components/forms'
import {
Actions, Button, Check, Ctlbar, Empty, ErrorText, Field, FieldBlock, FormRow, Layout, MUTED,
MUTED_MONO, PageHead, Panel, PanelHead, Stack, Stat, StatGrid, Sub, Table, TableBox, Tag, cellRight
} from '../components/ui'
import { notify, notifyBad } from '../stores/notice'
import { roleLabel, useAuthStore } from '../stores/auth'
const FALLBACK_ROLES = ['admin', 'editor', 'viewer'].map((v) => ({ value: v, label: roleLabel(v) }))
export default function UserAdmin() {
return <div className="p-[26px] text-center text-faint text-body">用户管理 迁移中…</div>
const auth = useAuthStore()
const [users, setUsers] = useState<any[]>([])
const [roles, setRoles] = useState<any[]>([])
const [audit, setAudit] = useState<any[]>([])
const [counts, setCounts] = useState<any>({})
const [error, setError] = useState('')
const [busy, setBusy] = useState('')
const [keyword, setKeyword] = useState('')
const [roleFilter, setRoleFilter] = useState('')
const [selectedId, setSelectedId] = useState<number | null>(null)
const [create, setCreate] = useState({ username: '', password: '', display_name: '', email: '', role: 'editor', note: '' })
const [edit, setEdit] = useState({ display_name: '', email: '', role: 'editor', is_active: true, note: '' })
const [reset, setReset] = useState({ password: '', must_change: true, revoke_sessions: true })
const roleOptions = roles.length ? roles : FALLBACK_ROLES
const selected = users.find((row) => row.id === selectedId) || null
const visible = users.filter((row) => {
if (roleFilter && row.role !== roleFilter) return false
const q = keyword.trim().toLowerCase()
if (!q) return true
return [row.username, row.display_name, row.email, row.note].join(' ').toLowerCase().includes(q)
})
/** 详情表单是否已被服务端数据覆盖过(切行时同步一次,避免每次渲染都重置输入框) */
const syncEdit = useCallback((row: any) => {
if (!row) return
setEdit({
display_name: row.display_name || '', email: row.email || '',
role: row.role || 'editor', is_active: !!row.is_active, note: row.note || ''
})
setReset({ password: '', must_change: true, revoke_sessions: true })
}, [])
const load = useCallback(async (silent = true, keepForms = false) => {
if (!silent) setBusy('读取账号')
setError('')
try {
const [list, trail] = await Promise.all([
api.get('/api/users'),
api.get('/api/users/audit', { limit: 60 })
])
const items: any[] = list.items || []
setUsers(items)
if (list.roles?.length) setRoles(list.roles)
setCounts(list.counts || {})
setAudit(trail.items || [])
setSelectedId((cur) => {
if (items.some((row) => row.id === cur)) return cur
return items[0]?.id ?? null
})
if (!keepForms) syncEdit(items.find((row) => row.id === selectedId) || items[0])
} catch (exc: any) {
setError(exc?.message || String(exc))
} finally {
setBusy('')
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedId, syncEdit])
useEffect(() => { void load(false) }, [])
const formDirty = !!selected && (
edit.display_name !== (selected.display_name || '') || edit.email !== (selected.email || '')
|| edit.role !== (selected.role || 'editor') || edit.is_active !== !!selected.is_active
|| edit.note !== (selected.note || ''))
|| !!reset.password
|| !!(create.username || create.password || create.display_name || create.email || create.note)
useAutoRefresh(() => void load(true, true), 30000, !!busy, formDirty)
function pick(row: any) {
setSelectedId(row.id)
syncEdit(row)
}
async function createUser() {
if (!create.username.trim() || !create.password) { notifyBad('用户名和密码都不能为空'); return }
setBusy('新建账号'); setError('')
try {
const made = await api.post('/api/users', { ...create, username: create.username.trim() })
const name = made?.username || create.username.trim()
setCreate({ username: '', password: '', display_name: '', email: '', role: create.role, note: '' })
setSelectedId(made?.id ?? null)
await load(true, true)
notify(`账号已创建:${name}`)
} catch (exc: any) { setError(exc?.message || String(exc)) }
finally { setBusy('') }
}
async function saveEdit() {
if (!selected) return
setBusy('保存账号'); setError('')
try {
await api.patch(`/api/users/${selected.id}`, { ...edit })
await load(true, true)
notify(`账号「${selected.username}」已更新`)
} catch (exc: any) { setError(exc?.message || String(exc)) }
finally { setBusy('') }
}
async function resetPassword() {
if (!selected || !reset.password) { notifyBad('请先填写新密码'); return }
setBusy('重置密码'); setError('')
try {
await api.post(`/api/users/${selected.id}/password`, { ...reset })
setReset((r) => ({ ...r, password: '' }))
await load(true, true)
notify(`已重置「${selected.username}」的密码${reset.revoke_sessions ? ',并注销其全部会话' : ''}`)
} catch (exc: any) { setError(exc?.message || String(exc)) }
finally { setBusy('') }
}
async function kickSessions() {
if (!selected) return
setBusy('注销会话'); setError('')
try {
const data = await api.post(`/api/users/${selected.id}/sessions/revoke`)
await load(true, true)
notify(`已注销「${selected.username}」的 ${data?.revoked ?? 0} 个会话`)
} catch (exc: any) { setError(exc?.message || String(exc)) }
finally { setBusy('') }
}
async function disable() {
if (!selected) return
if (!window.confirm(`停用「${selected.display_name || selected.username}」?停用后该账号无法登录,历史操作记录仍会保留。`)) return
setBusy('停用账号'); setError('')
try {
await api.del(`/api/users/${selected.id}`)
await load(true, true)
notify(`账号「${selected.username}」已停用`)
} catch (exc: any) { setError(exc?.message || String(exc)) }
finally { setBusy('') }
}
return (
<div className="min-w-0">
<PageHead eyebrow="ACCESS CONTROL" title="用户管理" />
<ErrorText className="mb-[14px] text-caption">{error}</ErrorText>
{/* 统计卡一共 5 项:给 5 列,别让第 5 张孤零零掉到第二行 */}
<StatGrid cols={5} steps={[{ at: 'huge', cols: 3 }, { at: 'short', cols: 2 }]}>
<Stat label="账号总数" value={counts.total ?? users.length} />
<Stat label="管理员" value={counts.admins ?? 0} />
<Stat label="已停用" value={counts.disabled ?? 0} />
<Stat label="待改初始密码" value={counts.pending_password ?? 0} />
<Stat label="活跃会话" value={counts.sessions ?? 0} />
</StatGrid>
<Layout>
<Stack>
<Panel>
<PanelHead eyebrow="ACCOUNTS" title="账号列表"
right={
<Ctlbar className="mb-0">
<Field label="搜索" width="grow">
<input value={keyword} placeholder="用户名 / 姓名 / 邮箱" onChange={(e) => setKeyword(e.target.value)} />
</Field>
<Field label="角色" width="narrow">
<Select size="sm" ariaLabel="按角色筛选" value={roleFilter} onChange={setRoleFilter}
options={[{ value: '', label: '全部角色' }, ...roleOptions]} />
</Field>
</Ctlbar>
} />
<TableBox maxHeight={460}>
<Table pickable minWidth={0}>
<thead>
<tr><th>账号</th><th>角色</th><th>状态</th><th>最近登录</th><th className={cellRight}>会话</th></tr>
</thead>
<tbody>
{visible.map((row) => (
<tr key={row.id} data-chosen={row.id === selectedId || undefined} onClick={() => pick(row)}>
<td>
<b className="text-body">{row.display_name || row.username}</b>
<p className={`mt-[3px] mb-0 ${MUTED_MONO}`}>{row.username}{row.email ? ` · ${row.email}` : ''}</p>
</td>
<td><Tag tone={row.role === 'admin' ? 'info' : 'default'}>{row.role_label || roleLabel(row.role)}</Tag></td>
<td>
<Tag tone={row.is_active ? 'default' : 'bad'}>{row.is_active ? '正常' : '已停用'}</Tag>
{row.must_change_password && <p className={`mt-[3px] mb-0 ${MUTED}`}>未改初始密码</p>}
</td>
<td>
<span>{row.last_login_at ? fmtAgo(row.last_login_at) : '从未登录'}</span>
<p className={`mt-[3px] mb-0 ${MUTED}`}>{row.login_count || 0} 次{row.last_login_ip ? ' · ' + row.last_login_ip : ''}</p>
</td>
<td className={cellRight}>{row.active_sessions || 0}</td>
</tr>
))}
</tbody>
</Table>
{!visible.length && <Empty className="m-3 border-0">没有匹配的账号。</Empty>}
</TableBox>
</Panel>
<Panel>
<PanelHead eyebrow="NEW ACCOUNT" title="新建账号" />
<FormRow>
<Field label="用户名" required>
<input value={create.username} maxLength={60} placeholder="登录用,小写字母/数字"
onChange={(e) => setCreate((f) => ({ ...f, username: e.target.value }))} />
</Field>
<Field label="显示名">
<input value={create.display_name} maxLength={80} onChange={(e) => setCreate((f) => ({ ...f, display_name: e.target.value }))} />
</Field>
<Field label="邮箱">
<input value={create.email} maxLength={160} onChange={(e) => setCreate((f) => ({ ...f, email: e.target.value }))} />
</Field>
<Field label="角色">
<Select value={create.role} onChange={(v) => setCreate((f) => ({ ...f, role: v }))} options={roleOptions} />
</Field>
<Field label="初始密码" required>
<SecretInput value={create.password} maxLength={200} autocomplete="new-password"
placeholder="至少 8 位,首次登录要求修改"
onChange={(v) => setCreate((f) => ({ ...f, password: v }))} />
</Field>
<Field label="备注">
<input value={create.note} maxLength={200} placeholder="例如:外包配音,仅本项目"
onChange={(e) => setCreate((f) => ({ ...f, note: e.target.value }))} />
</Field>
</FormRow>
<Actions><Button variant="primary" disabled={!!busy} onClick={createUser}>创建账号</Button></Actions>
</Panel>
<Panel>
<PanelHead eyebrow="AUDIT" title={<span title="登录 / 改密 / 停用都会留痕">账号操作流水</span>} />
{!audit.length
? <Empty>还没有账号操作记录。</Empty>
: (
<div className="flex max-h-[320px] flex-col gap-[2px] overflow-auto">
{audit.map((row) => (
<div key={row.id}
className="grid grid-cols-[132px_74px_minmax(0,1fr)] items-baseline gap-[9px] border-b border-line px-[2px] py-[7px] text-caption last:border-b-0">
<span className={`${MUTED_MONO} text-tiny`}>{fmtTime(row.created_at)}</span>
<span className="font-semibold text-accent-bright [overflow-wrap:anywhere]">{row.actor || 'system'}</span>
<span className="text-ink-2 [overflow-wrap:anywhere]">{row.message}</span>
</div>
))}
</div>
)}
</Panel>
</Stack>
<Stack>
{selected ? (
<Panel>
<PanelHead eyebrow="DETAIL" title={selected.display_name || selected.username}
right={<Tag tone="mono">#{selected.id}</Tag>} />
<FormRow>
<Field label="显示名">
<input value={edit.display_name} maxLength={80} onChange={(e) => setEdit((f) => ({ ...f, display_name: e.target.value }))} />
</Field>
<Field label="邮箱">
<input value={edit.email} maxLength={160} onChange={(e) => setEdit((f) => ({ ...f, email: e.target.value }))} />
</Field>
<Field label="角色">
<Select value={edit.role} disabled={selected.id === auth.user?.id}
title={selected.id === auth.user?.id ? '不能修改自己的角色' : undefined}
onChange={(v) => setEdit((f) => ({ ...f, role: v }))} options={roleOptions} />
</Field>
<Check checked={edit.is_active} onChange={(v) => setEdit((f) => ({ ...f, is_active: v }))}>允许登录</Check>
</FormRow>
<FieldBlock label="备注">
<textarea rows={2} maxLength={200} value={edit.note} onChange={(e) => setEdit((f) => ({ ...f, note: e.target.value }))} />
</FieldBlock>
<Actions>
<Button variant="primary" disabled={!!busy} onClick={saveEdit}>保存</Button>
<Button variant="outline" disabled={!!busy || !selected.is_active} onClick={disable}>停用账号</Button>
</Actions>
<Sub>
<h3>重置密码</h3>
<FieldBlock label="新密码" required>
<SecretInput value={reset.password} maxLength={200} autocomplete="new-password" placeholder="留空不可提交"
onChange={(v) => setReset((f) => ({ ...f, password: v }))} />
</FieldBlock>
<Ctlbar>
<Check checked={reset.must_change} onChange={(v) => setReset((f) => ({ ...f, must_change: v }))}>要求该账号下次登录改密</Check>
<Check checked={reset.revoke_sessions} onChange={(v) => setReset((f) => ({ ...f, revoke_sessions: v }))}>同时注销该账号全部会话</Check>
</Ctlbar>
<Actions>
<Button variant="secondary" disabled={!!busy || !reset.password} onClick={resetPassword}>重置密码</Button>
<Button variant="outline" disabled={!!busy} onClick={kickSessions}>仅注销会话</Button>
</Actions>
</Sub>
</Panel>
) : (
<Panel><Empty>在左侧选择一个账号开始管理。</Empty></Panel>
)}
</Stack>
</Layout>
</div>
)
}