From cb90fd41b06c73a3d3fdb854d18c424735778a34 Mon Sep 17 00:00:00 2001 From: pfqgauxfb <3521106529@qq.com> Date: Tue, 3 Jun 2025 10:30:08 +0800 Subject: [PATCH] feng --- src/components/Comment/index.js | 93 -------------- src/components/Comment/styles.module.css | 132 -------------------- src/components/DocComment/index.js | 69 ++++++++++ src/components/DocComment/styles.module.css | 97 ++++++++++++++ src/theme/DocItem/index.js | 12 ++ 5 files changed, 178 insertions(+), 225 deletions(-) delete mode 100644 src/components/Comment/index.js delete mode 100644 src/components/Comment/styles.module.css create mode 100644 src/components/DocComment/index.js create mode 100644 src/components/DocComment/styles.module.css create mode 100644 src/theme/DocItem/index.js diff --git a/src/components/Comment/index.js b/src/components/Comment/index.js deleted file mode 100644 index 0442a95..0000000 --- a/src/components/Comment/index.js +++ /dev/null @@ -1,93 +0,0 @@ -import React, { useState, useEffect } from 'react'; -import styles from './styles.module.css'; - -export default function Comment({ docId }) { - const [comments, setComments] = useState([]); - const [newComment, setNewComment] = useState(''); - const [isOpen, setIsOpen] = useState(false); - - useEffect(() => { - // 从localStorage中读取评论 - const savedComments = JSON.parse(localStorage.getItem(`docComments_${docId}`) || '[]'); - setComments(savedComments); - }, [docId]); - - const handleAddComment = () => { - if (!newComment.trim()) return; - - const comment = { - id: Date.now(), - text: newComment, - timestamp: new Date().toLocaleString(), - author: '用户' // 这里可以替换为实际的用户名 - }; - - const updatedComments = [...comments, comment]; - setComments(updatedComments); - localStorage.setItem(`docComments_${docId}`, JSON.stringify(updatedComments)); - setNewComment(''); - }; - - const handleDeleteComment = (commentId) => { - const updatedComments = comments.filter(comment => comment.id !== commentId); - setComments(updatedComments); - localStorage.setItem(`docComments_${docId}`, JSON.stringify(updatedComments)); - }; - - return ( -
- - - {isOpen && ( -
-
- {comments.map(comment => ( -
-
- {comment.author} - {comment.timestamp} - -
-
{comment.text}
-
- ))} -
-
-