From 19db4ef3a0ec06e284b37453c18c8a74ba670c2f Mon Sep 17 00:00:00 2001 From: "mula.liu" Date: Mon, 2 Nov 2026 10:33:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=91=E7=9A=84=E8=B4=A6=E5=8F=B7=E4=B8=8E?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86=EF=BC=9A=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E6=94=B9=E6=88=90=E6=98=8E=E7=A1=AE=E7=9A=84=E5=88=97=E6=A0=85?= =?UTF-8?q?=E6=A0=BC=E3=80=81=E8=A7=84=E5=88=99=E8=AF=B4=E6=98=8E=E8=90=BD?= =?UTF-8?q?=E5=88=B0=E5=AD=97=E6=AE=B5=E4=B8=8B=E6=96=B9=E8=80=8C=E4=B8=8D?= =?UTF-8?q?=E6=98=AF=E5=A1=9E=E8=BF=9B=20placeholder=EF=BC=8C=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E8=AE=BE=E5=A4=87=E6=A0=87=E9=A2=98=E6=8A=8A=E5=8E=9F?= =?UTF-8?q?=E5=A7=8B=20UA=20=E8=A7=A3=E6=9E=90=E6=88=90=E3=80=8CChrome=201?= =?UTF-8?q?55=20=C2=B7=20macOS=E3=80=8D=E5=B9=B6=E9=99=90=E9=AB=98?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=EF=BC=8C=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=9A=84=E7=AD=9B=E9=80=89=E6=9D=A1=E4=BB=8E=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E5=A4=B4=E6=8C=AA=E5=9B=9E=E5=88=97=E8=A1=A8=E4=B8=8A=E6=96=B9?= =?UTF-8?q?=E3=80=81=E8=AF=A6=E6=83=85=E5=AD=97=E6=AE=B5=E7=AB=96=E6=8E=92?= =?UTF-8?q?=E3=80=81=E5=85=81=E8=AE=B8=E7=99=BB=E5=BD=95=E7=8B=AC=E7=AB=8B?= =?UTF-8?q?=E6=88=90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/lib/format.ts | 31 ++++++++++++++++++++ frontend/src/pages/Account.tsx | 30 ++++++++++--------- frontend/src/pages/UserAdmin.tsx | 49 ++++++++++++++++---------------- 3 files changed, 72 insertions(+), 38 deletions(-) diff --git a/frontend/src/lib/format.ts b/frontend/src/lib/format.ts index de5b6f5..2af92fa 100644 --- a/frontend/src/lib/format.ts +++ b/frontend/src/lib/format.ts @@ -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 调度器放行不等于人工审核。 * 质检没过、只是「按现有画面继续出片」的软放行,更要显式提醒人工复核, diff --git a/frontend/src/pages/Account.tsx b/frontend/src/pages/Account.tsx index 8399959..d7ed514 100644 --- a/frontend/src/pages/Account.tsx +++ b/frontend/src/pages/Account.tsx @@ -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() { - + - + - setPwd((p) => ({ ...p, current_password: v }))} /> - - + setPwd((p) => ({ ...p, new_password: v }))} /> - - + setPwd((p) => ({ ...p, confirm: v }))} onKeyUp={(e) => { if (e.key === 'Enter') void changePassword() }} /> @@ -159,15 +158,18 @@ export default function Account() { - + {sessions.length}} /> {!sessions.length ? 只有一个当前会话,没有其它设备在线。 : ( -
+ /* 会话是一条条堆起来的(脚本、探针、旧浏览器都算一条), + 限高滚动才不会让这一栏把整页撑到看不完 */ +
{sessions.map((row) => ( - {row.current ? '当前会话' : describeUserAgent(row.label)}} right={row.current - ? 使用中 + ? 使用中 : }>

{row.ip || '未知 IP'} · 活跃于 {fmtAgo(row.last_seen_at)} · {fmtTime(row.expires_at)} 过期

diff --git a/frontend/src/pages/UserAdmin.tsx b/frontend/src/pages/UserAdmin.tsx index 4b9225f..fde51f8 100644 --- a/frontend/src/pages/UserAdmin.tsx +++ b/frontend/src/pages/UserAdmin.tsx @@ -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() { - - - setKeyword(e.target.value)} /> - - - setKeyword(e.target.value)} /> + + + + + setCreate((f) => ({ ...f, username: e.target.value }))} /> setCreate((f) => ({ ...f, display_name: e.target.value }))} /> - setCreate((f) => ({ ...f, email: e.target.value }))} /> + setCreate((f) => ({ ...f, email: e.target.value }))} /> setEdit((f) => ({ ...f, display_name: e.target.value }))} /> - setEdit((f) => ({ ...f, email: e.target.value }))} /> + setEdit((f) => ({ ...f, email: e.target.value }))} />