blob: 0f96e8dfb8c767961c9e43e2375c4d57154f7f4d [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>) => {
阳菜,放晴!33a0d332025-06-08 22:39:42 +080045 console.log(e.key);
阳菜,放晴!7e1e3a52025-06-05 23:00:51 +080046 if (e.key === "Enter" && searchText.trim() !== "") {
47 navigate(`/search?keyword=${encodeURIComponent(searchText.trim())}`);
48 }
49 };
50
San3yuan03ab0642025-04-29 18:00:25 +080051
52 return (
53 <div style={{ display: 'block', height: '100vh' }}>
54 <header className={style.header}>
San3yuan30e245f2025-06-07 20:04:23 +080055 <img className={style.logo} src={logo} alt="website logo" onClick={()=>navigate('/')}></img>
阳菜,放晴!7e1e3a52025-06-05 23:00:51 +080056 {showSearch && (
57 // <input className={style.searchInput} placeholder="输入关键词进行搜索"/>
58 <input
59 className={style.searchInput}
60 placeholder="输入关键词进行搜索"
61 value={searchText}
62 onChange={(e) => setSearchText(e.target.value)}
63 onKeyDown={handleSearch} // ⌨️ 按下回车时执行跳转
64 />)}
San3yuan03ab0642025-04-29 18:00:25 +080065 <div className={style.toollist}>
66 <SearchOutlined onClick={toggleSearch}/>
67 <FontSizeOutlined onClick={toggleFontSize}/>
68 <MessageOutlined />
69 {theme === 'dark' ? <MoonOutlined onClick={toggleTheme}/> : <SunOutlined onClick={toggleTheme}/>}
70 </div>
71 </header>
72 <div className={style.container}>
73 <Outlet/>
74 </div>
75
76
77 </div>
78 );
79}
80
81export default Frame;