diff --git a/web/src/components/blog-home/blog-home.tsx b/web/src/components/blog-home/blog-home.tsx index cd614c9..e4fbb66 100644 --- a/web/src/components/blog-home/blog-home.tsx +++ b/web/src/components/blog-home/blog-home.tsx @@ -14,6 +14,7 @@ import { useStoredState } from '@/hooks/use-storage-state'; import { listLabels } from "@/api/label"; import { POST_SORT_TYPE } from "@/localstore"; import { motion } from "framer-motion"; +import { useDevice } from "@/hooks/use-device"; // 定义排序类型 type SortType = 'latest' | 'popular'; @@ -22,6 +23,7 @@ export default function BlogHome() { const [labels, setLabels] = useState([]); const [posts, setPosts] = useState([]); const [loading, setLoading] = useState(false); + const { isMobile } = useDevice(); const [sortType, setSortType, sortTypeLoaded] = useStoredState(POST_SORT_TYPE, 'latest'); useEffect(() => { if (!sortTypeLoaded) return; @@ -88,7 +90,7 @@ export default function BlogHome() { {/* 主要内容区域 */} {/* 文章列表标题 */} @@ -153,8 +155,8 @@ export default function BlogHome() { {/* 侧边栏 */} { + // 简单判断移动端 + const check = () => { + const ua = navigator.userAgent; + setIsMobile(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua)); + }; + check(); + window.addEventListener("resize", check); + return () => window.removeEventListener("resize", check); + }, []); + + return { isMobile }; +}