fix(webui): align debug account picker styling (#181)

This commit is contained in:
囧囧JOJO authored and GitHub committed 2026-07-01 14:43:29 +08:00
1 parent 5d6ce86b66
commit f424454422
2 files changed
+38 -7

No files matched your search

@@ -8,7 +8,6 @@
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
import { motion } from 'motion/react';
import { AlertTriangle, FlaskConical, History, Loader2, Play, RotateCcw, ShieldCheck, Trash2, Zap } from 'lucide-react';
import { Select } from '@/components/ui/select';
import { Textarea } from '@/components/ui/textarea';
import { Picker } from '@/components/ui/picker';
import { JsonTree } from '@/components/ui/json-tree';
@@ -27,6 +26,10 @@ const cardCls = 'rounded-2xl border border-border/60 bg-card/80 shadow-[0_1px_2p
// stakes (the amber banner already warns that any write is real).
const DESTRUCTIVE_RE = /(kick|ban|mute|recall|withdraw|delete|del_|dismiss|disband|leave|quit|remove|revoke)/i;
function qqAvatarUrl(uin: string) {
return `/avatar/${encodeURIComponent(uin)}`;
}
function coerceParam(type: string, raw: string): unknown {
if (raw === '') return undefined;
if (/int|uint|number|messageId/i.test(type)) {
@@ -82,6 +85,18 @@ export function ActionTester({ accounts, docs, presetAction }: { accounts: QQInf
const isStream = !!doc?.stream;
const isDestructive = DESTRUCTIVE_RE.test(actionName);
const accountOptions = useMemo(
() => accounts.length === 0
? [{ value: '', label: '(无在线账号)' }]
: accounts.map((a) => ({
value: a.uin,
label: a.nickname || a.uin,
sub: a.nickname ? a.uin : undefined,
avatar: qqAvatarUrl(a.uin),
})),
[accounts],
);
const actionOptions = useMemo(
() => docs.map((d) => ({ value: d.name, label: d.name, sub: d.summary })),
[docs],
@@ -201,10 +216,15 @@ export function ActionTester({ accounts, docs, presetAction }: { accounts: QQInf
<div className="grid gap-4 sm:grid-cols-2">
<Field label="账号">
<Select value={uin} onChange={(e) => setUin(e.target.value)}>
{accounts.length === 0 && <option value="">(无在线账号)</option>}
{accounts.map((a) => <option key={a.uin} value={a.uin}>{a.nickname || a.uin}</option>)}
</Select>
<Picker
ariaLabel="选择账号"
value={uin}
onChange={setUin}
options={accountOptions}
placeholder="选择账号…"
validateRaw={() => false}
disabled={accounts.length === 0}
/>
</Field>
<Field label="Action">
<Picker
+13 -2
View File
@@ -50,6 +50,7 @@ export function Picker({
const rootRef = useRef<HTMLDivElement>(null);
const listRef = useRef<HTMLDivElement>(null);
const searchRef = useRef<HTMLInputElement>(null);
const suppressTriggerClick = useRef(false);
const selected = options.find((o) => o.value === value);
@@ -124,7 +125,13 @@ export function Picker({
aria-label={ariaLabel}
aria-haspopup="listbox"
aria-expanded={open}
onClick={() => !disabled && setOpen((v) => !v)}
onClick={() => {
if (suppressTriggerClick.current) {
suppressTriggerClick.current = false;
return;
}
if (!disabled) setOpen((v) => !v);
}}
className={cn(
'flex h-9 w-full items-center gap-2 rounded-md border border-border bg-transparent px-3 text-sm outline-none transition-colors',
'focus-visible:ring-[3px] focus-visible:ring-ring/40 focus-visible:border-ring disabled:opacity-50',
@@ -196,7 +203,11 @@ export function Picker({
role="option"
aria-selected={idx === active}
onMouseEnter={() => setActive(idx)}
onClick={() => choose(idx)}
onPointerDown={(e) => {
e.preventDefault();
suppressTriggerClick.current = true;
choose(idx);
}}
className={cn(
'absolute left-0 right-0 flex cursor-pointer items-center gap-2.5 px-3',
idx === active ? 'bg-accent text-accent-foreground' : 'hover:bg-accent/50',