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) => ( + + ))} +
+ ))} +
+
+ )} +