blob: c22a52879f9e0b59b02df2db7264c41ede8b4081 [file] [log] [blame]
San3yuan03ab0642025-04-29 18:00:25 +08001import React from "react";
2import { Outlet } from "react-router";
3import { useEffect, useState } from "react";
4import {
5 SearchOutlined,
6 FontSizeOutlined,
7 MessageOutlined,
8 SunOutlined,
9 MoonOutlined
10 } from "@ant-design/icons";
11import style from "./frame.module.css";
12import logo from "&/assets/logo.png";
13import { useAppDispatch } from "@/hooks/store";
14import { useSelector } from "react-redux";
阳菜,放晴!7e1e3a52025-06-05 23:00:51 +080015
16import { useNavigate } from "react-router-dom";
17
18
San3yuan03ab0642025-04-29 18:00:25 +080019const Frame:React.FC = () => {
20
21 const dispatch = useAppDispatch();
22
23 const showSearch = useSelector((state: any) => state.setting.showSearch);
24 const theme= useSelector((state: any) => state.setting.theme);
阳菜,放晴!7e1e3a52025-06-05 23:00:51 +080025
26 const navigate = useNavigate(); // ✅ 用于跳转
27 const [searchText, setSearchText] = useState(""); // ✅ 存储搜索输入内容
28
29
San3yuan03ab0642025-04-29 18:00:25 +080030 const toggleSearch = () => {
31 dispatch({ type: "setting/toggleSearch" });
32 }
33
34 const toggleFontSize = () => {
35 dispatch({ type: "setting/toggleFontSize" });
36 };
37
38 const toggleTheme = () => {
39 dispatch({ type: "setting/toggleTheme" });
40 };
41
阳菜,放晴!7e1e3a52025-06-05 23:00:51 +080042 // ✅ 用于跳转
43 const handleSearch = (e: React.KeyboardEvent<HTMLInputElement>) => {
44 if (e.key === "Enter" && searchText.trim() !== "") {
45 navigate(`/search?keyword=${encodeURIComponent(searchText.trim())}`);
46 }
47 };
48
San3yuan03ab0642025-04-29 18:00:25 +080049
50 return (
51 <div style={{ display: 'block', height: '100vh' }}>
52 <header className={style.header}>
53 <img className={style.logo} src={logo} alt="website logo"></img>
阳菜,放晴!7e1e3a52025-06-05 23:00:51 +080054 {showSearch && (
55 // <input className={style.searchInput} placeholder="输入关键词进行搜索"/>
56 <input
57 className={style.searchInput}
58 placeholder="输入关键词进行搜索"
59 value={searchText}
60 onChange={(e) => setSearchText(e.target.value)}
61 onKeyDown={handleSearch} // ⌨️ 按下回车时执行跳转
62 />)}
San3yuan03ab0642025-04-29 18:00:25 +080063 <div className={style.toollist}>
64 <SearchOutlined onClick={toggleSearch}/>
65 <FontSizeOutlined onClick={toggleFontSize}/>
66 <MessageOutlined />
67 {theme === 'dark' ? <MoonOutlined onClick={toggleTheme}/> : <SunOutlined onClick={toggleTheme}/>}
68 </div>
69 </header>
70 <div className={style.container}>
71 <Outlet/>
72 </div>
73
74
75 </div>
76 );
77}
78
79export default Frame;