From 008dec350eafb0705be0dbeda8d0123112d2a0fe Mon Sep 17 00:00:00 2001 From: xueweihan <595666367@qq.com> Date: Wed, 8 Jan 2025 12:54:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=A0=87=E7=AD=BE=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E9=AB=98=E5=BA=A6=E5=8A=A8=E6=80=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/respository/CommentSubmit.tsx | 2 +- src/components/side/TagList.tsx | 21 +++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/components/respository/CommentSubmit.tsx b/src/components/respository/CommentSubmit.tsx index c82ee9a..6e3fbe6 100644 --- a/src/components/respository/CommentSubmit.tsx +++ b/src/components/respository/CommentSubmit.tsx @@ -38,7 +38,7 @@ function CommentSubmit(props: CommentSubmitProps) { setCommentData({ ...commentData, - comment: value.trim(), + comment: value, height: e.currentTarget.scrollHeight + 2, }); }; diff --git a/src/components/side/TagList.tsx b/src/components/side/TagList.tsx index 8aaf9eb..d27141b 100644 --- a/src/components/side/TagList.tsx +++ b/src/components/side/TagList.tsx @@ -32,6 +32,14 @@ export default function TagList() { month, } = router.query; const [tags, setTags] = useState([]); + const [maxHeight, setMaxHeight] = useState(444); // 初始为默认高度 + + // 动态更新 maxHeight 基于屏幕高度 + const updateMaxHeight = () => { + // 根据需求动态计算,例如屏幕高度的 60% + const calculatedHeight = Math.max(window.innerHeight * 0.6, 300); // 最小值为 300px + setMaxHeight(calculatedHeight); + }; useEffect(() => { const initTags = async () => { @@ -44,6 +52,14 @@ export default function TagList() { if (!isMobile()) { initTags(); + // 初始化计算高度 + updateMaxHeight(); + // 监听窗口大小变化,更新高度 + window.addEventListener('resize', updateMaxHeight); + // 清理事件监听器 + return () => { + window.removeEventListener('resize', updateMaxHeight); + }; } }, []); // 确保 useEffect 只在组件挂载时执行 @@ -70,7 +86,10 @@ export default function TagList() { -
+
{!tags.length && } {tags.map((item: Tag) => (