我的账号与用户管理:表单改成明确的列栅格、规则说明落到字段下方而不是塞进 placeholder,登录设备标题把原始 UA 解析成「Chrome 155 · macOS」并限高滚动,用户管理的筛选条从面板头挪回列表上方、详情字段竖排、允许登录独立成行
parent
72afec93fc
commit
19db4ef3a0
|
|
@ -305,6 +305,37 @@ export function eventLevelKey(level?: string | null) {
|
|||
return level === 'warning' ? 'warn' : level
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录设备:会话表里存的是原始 User-Agent,四五十个字符的英文串会把整行撑成三行,
|
||||
* 谁都看不出「这到底是哪台机器」。这里只留人能读懂的两件事——什么浏览器、什么系统;
|
||||
* 原文由调用方塞进 title,真要逐字排查时还在。
|
||||
*/
|
||||
const UA_BROWSERS: [string, string][] = [
|
||||
['HeadlessChrome', 'Headless Chrome'], ['Edg', 'Edge'], ['OPR', 'Opera'],
|
||||
['Firefox', 'Firefox'], ['Chrome', 'Chrome'], ['Safari', 'Safari']
|
||||
]
|
||||
const UA_SYSTEMS: [RegExp, string][] = [
|
||||
[/Windows NT/, 'Windows'], [/Mac OS X|Macintosh/, 'macOS'], [/Android/, 'Android'],
|
||||
[/iPhone|iPad|CPU OS/, 'iOS'], [/Linux/, 'Linux']
|
||||
]
|
||||
|
||||
export function describeUserAgent(ua?: string | null): string {
|
||||
const s = String(ua || '').trim()
|
||||
if (!s) return '未知客户端'
|
||||
for (const [token, name] of UA_BROWSERS) {
|
||||
// 只取主版本号:156.0.0.0.8078.4 这种长尾在小标签里没有任何信息量
|
||||
const hit = s.match(new RegExp(token + '\\/(\\d+)'))
|
||||
if (hit) {
|
||||
const sys = UA_SYSTEMS.find(([re]) => re.test(s))?.[1]
|
||||
return [name + ' ' + hit[1], sys].filter(Boolean).join(' · ')
|
||||
}
|
||||
}
|
||||
// 命令行客户端(curl / python-requests / 脚本):名字和版本就是全部信息
|
||||
const cli = s.match(/^([A-Za-z][\w!.-]*)\/([\d.]+)/)
|
||||
if (cli) return cli[1] + ' ' + cli[2]
|
||||
return s.length > 28 ? s.slice(0, 28) + '…' : s
|
||||
}
|
||||
|
||||
/**
|
||||
* 镜头审核标签:AI 调度器放行不等于人工审核。
|
||||
* 质检没过、只是「按现有画面继续出片」的软放行,更要显式提醒人工复核,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
import { useEffect, useState } from 'react'
|
||||
import { useSearchParams } from 'react-router-dom'
|
||||
import * as api from '../api/client'
|
||||
import { fmtAgo, fmtTime } from '../lib/format'
|
||||
import { describeUserAgent, fmtAgo, fmtTime } from '../lib/format'
|
||||
import { useAutoRefresh } from '../hooks/use-auto-refresh'
|
||||
import { SecretInput } from '../components/forms'
|
||||
import {
|
||||
|
|
@ -16,7 +16,7 @@ import {
|
|||
} from '../components/ui'
|
||||
import { login, roleLabel, setUser, useAuthStore } from '../stores/auth'
|
||||
|
||||
const RULES_HINT = '至少 8 位,且不能只有一类字符(字母 / 数字 / 符号至少两种)'
|
||||
const RULES_HINT = '至少 8 位,字母 / 数字 / 符号至少两种'
|
||||
|
||||
export default function Account() {
|
||||
const [params] = useSearchParams()
|
||||
|
|
@ -109,7 +109,7 @@ export default function Account() {
|
|||
<Stack>
|
||||
<Panel>
|
||||
<PanelHead title="基本资料" />
|
||||
<FormRow>
|
||||
<FormRow cols={2}>
|
||||
<Field label="登录名"><input value={auth.user?.username || ''} disabled /></Field>
|
||||
<Field label="显示名">
|
||||
<input value={profile.display_name} maxLength={80} placeholder="同事看到的名字"
|
||||
|
|
@ -128,18 +128,17 @@ export default function Account() {
|
|||
|
||||
<Panel>
|
||||
<PanelHead title="修改密码" />
|
||||
<FormRow>
|
||||
<FormRow cols={3}>
|
||||
<Field label="当前密码">
|
||||
<SecretInput value={pwd.current_password} autocomplete="current-password" placeholder="输入当前密码"
|
||||
<SecretInput value={pwd.current_password} autocomplete="current-password" placeholder="当前密码"
|
||||
onChange={(v) => setPwd((p) => ({ ...p, current_password: v }))} />
|
||||
</Field>
|
||||
<Field label="新密码">
|
||||
<SecretInput value={pwd.new_password} title={RULES_HINT} autocomplete="new-password"
|
||||
placeholder="至少 8 位,建议混合字母与数字"
|
||||
<Field label="新密码" hint={RULES_HINT}>
|
||||
<SecretInput value={pwd.new_password} autocomplete="new-password" placeholder="新密码"
|
||||
onChange={(v) => setPwd((p) => ({ ...p, new_password: v }))} />
|
||||
</Field>
|
||||
<Field label="确认新密码">
|
||||
<SecretInput value={pwd.confirm} autocomplete="new-password" placeholder="再输入一次新密码"
|
||||
<Field label="确认新密码" hint="改完后其它设备会被注销">
|
||||
<SecretInput value={pwd.confirm} autocomplete="new-password" placeholder="再输入一次"
|
||||
onChange={(v) => setPwd((p) => ({ ...p, confirm: v }))}
|
||||
onKeyUp={(e) => { if (e.key === 'Enter') void changePassword() }} />
|
||||
</Field>
|
||||
|
|
@ -159,15 +158,18 @@ export default function Account() {
|
|||
|
||||
<Stack>
|
||||
<Panel>
|
||||
<PanelHead title="登录设备" />
|
||||
<PanelHead title="登录设备" right={<Tag tone="mono">{sessions.length}</Tag>} />
|
||||
{!sessions.length
|
||||
? <Empty>只有一个当前会话,没有其它设备在线。</Empty>
|
||||
: (
|
||||
<div className="flex flex-col">
|
||||
/* 会话是一条条堆起来的(脚本、探针、旧浏览器都算一条),
|
||||
限高滚动才不会让这一栏把整页撑到看不完 */
|
||||
<div className="flex max-h-[420px] flex-col overflow-auto scrollbar-slim">
|
||||
{sessions.map((row) => (
|
||||
<CardRow key={row.id} title={row.current ? '当前会话' : row.label}
|
||||
<CardRow key={row.id}
|
||||
title={<span title={row.label || ''}>{row.current ? '当前会话' : describeUserAgent(row.label)}</span>}
|
||||
right={row.current
|
||||
? <Tag>使用中</Tag>
|
||||
? <Tag tone="ok">使用中</Tag>
|
||||
: <Button variant="outline" size="sm" disabled={!!busy} onClick={() => revoke(row)}>注销</Button>}>
|
||||
<p>{row.ip || '未知 IP'} · 活跃于 {fmtAgo(row.last_seen_at)} · {fmtTime(row.expires_at)} 过期</p>
|
||||
</CardRow>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ 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,
|
||||
Actions, Badge, 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'
|
||||
|
|
@ -173,18 +173,16 @@ export default function UserAdmin() {
|
|||
<Layout>
|
||||
<Stack>
|
||||
<Panel>
|
||||
<PanelHead 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>
|
||||
} />
|
||||
<PanelHead title="账号列表" right={<Badge>{visible.length}</Badge>} />
|
||||
<Ctlbar>
|
||||
<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>
|
||||
|
|
@ -217,23 +215,23 @@ export default function UserAdmin() {
|
|||
|
||||
<Panel>
|
||||
<PanelHead title="新建账号" />
|
||||
<FormRow>
|
||||
<Field label="用户名" required>
|
||||
<input value={create.username} maxLength={60} placeholder="登录用,小写字母/数字"
|
||||
<FormRow cols={2}>
|
||||
<Field label="用户名" required hint="登录用,小写字母或数字,创建后不可改">
|
||||
<input value={create.username} maxLength={60} placeholder="例如 zhangsan"
|
||||
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 }))} />
|
||||
<input value={create.email} maxLength={160} placeholder="用于通知,可留空"
|
||||
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 位,首次登录要求修改"
|
||||
<Field label="初始密码" required hint="至少 8 位,字母 / 数字 / 符号至少两种">
|
||||
<SecretInput value={create.password} maxLength={200} autocomplete="new-password" placeholder="首次登录要求修改"
|
||||
onChange={(v) => setCreate((f) => ({ ...f, password: v }))} />
|
||||
</Field>
|
||||
<Field label="备注">
|
||||
|
|
@ -249,7 +247,7 @@ export default function UserAdmin() {
|
|||
{!audit.length
|
||||
? <Empty>还没有账号操作记录。</Empty>
|
||||
: (
|
||||
<div className="flex max-h-[320px] flex-col gap-[2px] overflow-auto">
|
||||
<div className="flex max-h-[320px] flex-col gap-[2px] overflow-auto scrollbar-slim">
|
||||
{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">
|
||||
|
|
@ -268,20 +266,23 @@ export default function UserAdmin() {
|
|||
<Panel>
|
||||
<PanelHead title={selected.display_name || selected.username}
|
||||
right={<Tag tone="mono">#{selected.id}</Tag>} />
|
||||
<FormRow>
|
||||
<FormRow cols={2} stack>
|
||||
<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 }))} />
|
||||
<input value={edit.email} maxLength={160} placeholder="用于通知,可留空"
|
||||
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>
|
||||
<Ctlbar>
|
||||
<Check checked={edit.is_active} onChange={(v) => setEdit((f) => ({ ...f, is_active: v }))}>允许登录</Check>
|
||||
</Ctlbar>
|
||||
<FieldBlock label="备注">
|
||||
<textarea rows={2} maxLength={200} value={edit.note} onChange={(e) => setEdit((f) => ({ ...f, note: e.target.value }))} />
|
||||
</FieldBlock>
|
||||
|
|
|
|||
Loading…
Reference in New Issue