diff --git a/src/components/ArticleLayout/components/Dynamic/index.tsx b/src/components/ArticleLayout/components/Dynamic/index.tsx index dee59ac..2fd41a8 100755 --- a/src/components/ArticleLayout/components/Dynamic/index.tsx +++ b/src/components/ArticleLayout/components/Dynamic/index.tsx @@ -1,52 +1,106 @@ 'use client'; -import { useState, useEffect } from 'react'; -import Image from 'next/image'; +import { useState, useEffect, useRef } from 'react'; import Link from 'next/link'; -import dynamic from '../../svg/dynamic.svg'; +import { HiOutlineSpeakerphone } from 'react-icons/hi'; +import { FiChevronRight } from 'react-icons/fi'; import { getRecordPagingAPI } from '@/api/record'; import { Record } from '@/types/app/record'; import { extractText } from '@/utils'; -export default function Dynamic({ className }: { className?: string }) { +export default function Dynamic({ className = '' }: { className?: string }) { const [list, setList] = useState([]); + const [currentIndex, setCurrentIndex] = useState(0); + const [isFading, setIsFading] = useState(false); + const [isLoading, setIsLoading] = useState(true); + + // 使用 useRef 管理定时器,防止组件卸载时内存泄漏 + const timerRef = useRef(null); + const fadeTimerRef = useRef(null); const getRecordList = async () => { - const { data } = await getRecordPagingAPI({ pagination: { page: 1, size: 8 } }); - setList(data?.result ?? []); + try { + const { data } = await getRecordPagingAPI({ pagination: { page: 1, size: 8 } }); + setList(data?.result ?? []); + } catch (error) { + console.error('Failed to fetch records:', error); + } finally { + setIsLoading(false); + } }; useEffect(() => { getRecordList(); }, []); - // 使用useState来管理当前显示的内容索引 - const [currentContentIndex, setCurrentContentIndex] = useState(0); - const [fade, setFade] = useState(true); - - // 使用useEffect来设置定时器 useEffect(() => { - const interval = setInterval(() => { - setFade(false); // 开始淡出 - setTimeout(() => { - setCurrentContentIndex((prevIndex) => (prevIndex + 1) % list.length); - setFade(true); // 淡入新内容 - }, 500); // 500ms的淡出时间 - }, 5000); // 每2.5秒切换一次内容,包括500ms的过渡时间 + if (list.length <= 1) return; - // 清除定时器 - return () => clearInterval(interval); - }, [list]); + timerRef.current = setInterval(() => { + setIsFading(true); + + fadeTimerRef.current = setTimeout(() => { + setCurrentIndex((prevIndex) => (prevIndex + 1) % list.length); + setIsFading(false); + }, 400); + }, 4500); + + return () => { + if (timerRef.current) clearInterval(timerRef.current); + if (fadeTimerRef.current) clearTimeout(fadeTimerRef.current); + }; + }, [list.length]); + + if (isLoading) { + return ( +
+
+
+
+ ); + } + + if (list.length === 0) return null; + + const currentContent = extractText(list[currentIndex]?.content || ''); return ( -
-
- 动态 - 最新动态: +
+
+ + + + + + + 最新动态 + +
- - {extractText(list[currentContentIndex]?.content || '')} + +
+ + {currentContent} + +
+ +
); diff --git a/src/components/Sidebar/Author/index.tsx b/src/components/Sidebar/Author/index.tsx index b8d0f96..73d06ef 100755 --- a/src/components/Sidebar/Author/index.tsx +++ b/src/components/Sidebar/Author/index.tsx @@ -35,7 +35,7 @@ const Author = async () => { return (
{ const [list, setList] = useState([]); @@ -22,19 +23,25 @@ const NewComments = () => { }, []); return ( -
+
最新评论 最新评论
-
- {list?.map((item) => ( - - {item.avatar ? avatar : } +
+ {list.map((item) => ( + +
{item.avatar ? avatar : }
-
-
{item.content}
-
{dayjs(+item.createTime!).format('YYYY-MM-DD HH:mm')}
+
+

{item.content}

+ +
+ + +
))} diff --git a/src/components/Sidebar/HotArticle/index.tsx b/src/components/Sidebar/HotArticle/index.tsx index a17d625..6a0d590 100755 --- a/src/components/Sidebar/HotArticle/index.tsx +++ b/src/components/Sidebar/HotArticle/index.tsx @@ -16,19 +16,23 @@ const RandomArticle = async () => { return (
-
+
作者推荐 作者推荐
- {/* 文章列表 */} -
+
{list?.map((item: Article) => ( -
- - - {item.title} +
+ + {item.title} + +
))} diff --git a/src/components/Sidebar/RunTime/index.tsx b/src/components/Sidebar/RunTime/index.tsx index db98b60..3c94fe8 100644 --- a/src/components/Sidebar/RunTime/index.tsx +++ b/src/components/Sidebar/RunTime/index.tsx @@ -69,7 +69,7 @@ export default () => { }; return ( -
+
站点运行时间 站点运行时间
diff --git a/src/components/Sidebar/Study/index.tsx b/src/components/Sidebar/Study/index.tsx index 3510542..c543de1 100644 --- a/src/components/Sidebar/Study/index.tsx +++ b/src/components/Sidebar/Study/index.tsx @@ -5,17 +5,17 @@ import { getPageConfigDataByNameAPI } from '@/api/config'; import { MyData } from '@/types/app/my'; export default async () => { - const { data } = await getPageConfigDataByNameAPI('my'); - const { technology_stack } = data?.value as MyData; - return ( -
-
- 最新评论 学无止境 -
+ const { data } = await getPageConfigDataByNameAPI('my'); + const { technology_stack } = data?.value as MyData; + return ( +
+
+ 最新评论 学无止境 +
-
- -
-
- ); +
+ +
+
+ ); }; diff --git a/src/styles/tailwind.scss b/src/styles/tailwind.scss index bd3dc42..a2b031d 100755 --- a/src/styles/tailwind.scss +++ b/src/styles/tailwind.scss @@ -3,7 +3,7 @@ @tailwind utilities; .tw_container { - @apply border dark:border-transparent rounded-md transition-shadow ease-in-out hover:shadow-[0_10px_20px_1px_rgb(83,157,253,.1)]; + @apply border dark:border-transparent rounded-xl transition-shadow ease-in-out hover:shadow-[0_10px_20px_1px_rgb(83,157,253,.1)]; } .tw_title {