diff --git a/web/src/components/model-logo.tsx b/web/src/components/model-logo.tsx index d26e3354e..b67ad7542 100644 --- a/web/src/components/model-logo.tsx +++ b/web/src/components/model-logo.tsx @@ -1,4 +1,4 @@ -import { useEffect, useMemo, useState, type ComponentType, type SVGProps } from "react"; +import { useEffect, useMemo, useRef, useState, type ComponentType, type SVGProps } from "react"; import { Input, Popover } from "antd"; import { Cpu, Search, X } from "lucide-react"; @@ -65,48 +65,114 @@ export function ModelLogo({ icon, size = 18, className }: { icon?: string; size? export function ModelIconPicker({ value, onChange }: { value?: string; onChange?: (value: string) => void }) { const [open, setOpen] = useState(false); const [keyword, setKeyword] = useState(""); + const searchInputRef = useRef(null); + + useEffect(() => { + if (open) { + const timer = setTimeout(() => searchInputRef.current?.focus(), 50); + return () => clearTimeout(timer); + } else { + setKeyword(""); + } + }, [open]); + const filteredIcons = useMemo(() => { const query = keyword.trim().toLowerCase(); return query ? iconOptions.filter((item) => `${item.id} ${item.title}`.toLowerCase().includes(query)) : iconOptions; }, [keyword]); const content = ( -
+
event.stopPropagation()} + onClick={(event) => event.stopPropagation()} + >
- } value={keyword} onChange={(event) => setKeyword(event.target.value)} placeholder="搜索 Logo" allowClear /> + } + value={keyword} + onChange={(event) => setKeyword(event.target.value)} + placeholder="搜索 Logo 名称或品牌..." + allowClear + /> {value ? ( - ) : null}
-
- {filteredIcons.map((item) => { - const selected = value === item.id; - return ( - - ); - })} +
event.stopPropagation()} + > + {filteredIcons.length ? ( + filteredIcons.map((item) => { + const selected = value === item.id; + return ( + + ); + }) + ) : ( +
+ 未找到与 “{keyword}” 相关的 Logo +
+ )} +
+
+ 共 {filteredIcons.length} 个可用 Logo + 点击即选定并应用
); return ( - -