From 84cce45151ac5cb0d881cd4ac3bd29f720106849 Mon Sep 17 00:00:00 2001 From: JSR Date: Wed, 18 Mar 2026 19:03:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=90=9C=E7=B4=A2=E6=A1=86?= =?UTF-8?q?=E4=B8=8B=E6=96=B9=E4=B9=9D=E5=AE=AB=E6=A0=BC=E6=8B=BC=E9=9F=B3?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E9=94=AE=E7=9B=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Home.tsx | 88 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 9 deletions(-) diff --git a/src/components/Home.tsx b/src/components/Home.tsx index 3fb36ea..be569c5 100644 --- a/src/components/Home.tsx +++ b/src/components/Home.tsx @@ -31,9 +31,11 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => { const [loading, setLoading] = useState(false) const [sortType, setSortType] = useState("alphabet") const [searchKeyword, setSearchKeyword] = useState("") + const [showPinyinKeyboard, setShowPinyinKeyboard] = useState(false) const scrollContainerRef = useRef(null) const groupRefs = useRef>({}) + const searchAreaRef = useRef(null) const [selectedStudent, setSelectedStudent] = useState(null) const [operationVisible, setOperationVisible] = useState(false) @@ -92,6 +94,31 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => { return () => window.removeEventListener("ss:data-updated", onDataUpdated as any) }, [fetchData]) + useEffect(() => { + const onDocumentClick = (e: MouseEvent) => { + const target = e.target as Node | null + if (searchAreaRef.current && target && !searchAreaRef.current.contains(target)) { + setShowPinyinKeyboard(false) + } + } + document.addEventListener("mousedown", onDocumentClick) + return () => document.removeEventListener("mousedown", onDocumentClick) + }, []) + + const pinyinKeyRows = [ + ["ABC", "DEF", "GHI"], + ["JKL", "MNO", "PQRS"], + ["TUV", "WXYZ", "⌫"], + ] + + const handlePinyinKeyPress = (value: string) => { + if (value === "⌫") { + setSearchKeyword((prev) => prev.slice(0, -1)) + return + } + setSearchKeyword((prev) => `${prev}${value.charAt(0).toLowerCase()}`) + } + const getDisplayText = (name: string) => { if (!name) return "" return name.length > 2 ? name.substring(name.length - 2) : name @@ -702,15 +729,58 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {

- - setSearchKeyword(e.target.value)} - placeholder={t("home.searchPlaceholder")} - prefix={} - allowClear - style={{ width: "220px" }} - /> + +
+ setSearchKeyword(e.target.value)} + onFocus={() => setShowPinyinKeyboard(true)} + onClick={() => setShowPinyinKeyboard(true)} + onKeyDown={(e) => { + if (e.key === "Escape") setShowPinyinKeyboard(false) + }} + placeholder={t("home.searchPlaceholder")} + prefix={} + allowClear + style={{ width: "220px" }} + /> + {showPinyinKeyboard && ( +
+
+ {pinyinKeyRows.map((row, rowIndex) => ( +
+ {row.map((keyValue) => ( + + ))} +
+ ))} +
+
+ )} +