blob: ba179962ba78e2e1e10fd77ef11b36d1de41eaed [file] [log] [blame]
San3yuana2ee30b2025-06-05 21:20:17 +08001import React, { use } from "react";
San3yuan03ab0642025-04-29 18:00:25 +08002import { 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";
San3yuana2ee30b2025-06-05 21:20:17 +080015import { checkAndRefreshToken } from "@/utils/jwt";
阳菜,放晴!7e1e3a52025-06-05 23:00:51 +080016import { useNavigate } from "react-router-dom";
San3yuan03ab0642025-04-29 18:00:25 +080017const Frame:React.FC = () => {
18
San3yuana2ee30b2025-06-05 21:20:17 +080019 useEffect(() => {
20 checkAndRefreshToken();
21 }, []);
San3yuan03ab0642025-04-29 18:00:25 +080022 const dispatch = useAppDispatch();
23
24 const showSearch = useSelector((state: any) => state.setting.showSearch);
25 const theme= useSelector((state: any) => state.setting.theme);
阳菜,放晴!7e1e3a52025-06-05 23:00:51 +080026
27 const navigate = useNavigate(); // ✅ 用于跳转
28 const [searchText, setSearchText] = useState(""); // ✅ 存储搜索输入内容
29
30
San3yuan03ab0642025-04-29 18:00:25 +080031 const toggleSearch = () => {
32 dispatch({ type: "setting/toggleSearch" });
33 }
34
35 const toggleFontSize = () => {
36 dispatch({ type: "setting/toggleFontSize" });
37 };
38
39 const toggleTheme = () => {
40 dispatch({ type: "setting/toggleTheme" });
41 };
42
阳菜,放晴!7e1e3a52025-06-05 23:00:51 +080043 // ✅ 用于跳转
44 const handleSearch = (e: React.KeyboardEvent<HTMLInputElement>) => {
45 if (e.key === "Enter" && searchText.trim() !== "") {
46 navigate(`/search?keyword=${encodeURIComponent(searchText.trim())}`);
47 }
48 };
49
San3yuan03ab0642025-04-29 18:00:25 +080050
51 return (
52 <div style={{ display: 'block', height: '100vh' }}>
53 <header className={style.header}>
San3yuan30e245f2025-06-07 20:04:23 +080054 <img className={style.logo} src={logo} alt="website logo" onClick={()=>navigate('/')}></img>
阳菜,放晴!7e1e3a52025-06-05 23:00:51 +080055 {showSearch && (
56 // <input className={style.searchInput} placeholder="输入关键词进行搜索"/>
57 <input
58 className={style.searchInput}
59 placeholder="输入关键词进行搜索"
60 value={searchText}
61 onChange={(e) => setSearchText(e.target.value)}
62 onKeyDown={handleSearch} // ⌨️ 按下回车时执行跳转
63 />)}
San3yuan03ab0642025-04-29 18:00:25 +080064 <div className={style.toollist}>
65 <SearchOutlined onClick={toggleSearch}/>
66 <FontSizeOutlined onClick={toggleFontSize}/>
67 <MessageOutlined />
68 {theme === 'dark' ? <MoonOutlined onClick={toggleTheme}/> : <SunOutlined onClick={toggleTheme}/>}
69 </div>
70 </header>
71 <div className={style.container}>
72 <Outlet/>
73 </div>
74
75
76 </div>
77 );
78}
79
80export default Frame;