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}
-
- ))}
-
-
-
-
- )}
-
- );
-}
\ No newline at end of file
diff --git a/src/components/Comment/styles.module.css b/src/components/Comment/styles.module.css
deleted file mode 100644
index f21ad8e..0000000
--- a/src/components/Comment/styles.module.css
+++ /dev/null
@@ -1,132 +0,0 @@
-.commentContainer {
- position: relative;
- display: inline-block;
-}
-
-.commentButton {
- background: none;
- border: none;
- cursor: pointer;
- padding: 4px;
- color: var(--ifm-color-emphasis-600);
- transition: all 0.2s ease;
- opacity: 1;
- z-index: 100;
- display: flex;
- align-items: center;
- justify-content: center;
- width: 20px;
- height: 20px;
-}
-
-.commentButton:hover {
- color: var(--ifm-color-primary);
- transform: scale(1.1);
-}
-
-.commentPanel {
- position: absolute;
- top: 100%;
- right: 0;
- width: 300px;
- background: var(--ifm-background-color);
- border: 1px solid var(--ifm-color-emphasis-200);
- border-radius: 8px;
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
- z-index: 1000;
- margin-top: 8px;
- padding: 16px;
-}
-
-.commentList {
- max-height: 300px;
- overflow-y: auto;
- margin-bottom: 16px;
-}
-
-.commentItem {
- padding: 8px;
- border-bottom: 1px solid var(--ifm-color-emphasis-200);
-}
-
-.commentItem:last-child {
- border-bottom: none;
-}
-
-.commentHeader {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 4px;
-}
-
-.commentAuthor {
- font-weight: 500;
- color: var(--ifm-color-primary);
-}
-
-.commentTime {
- font-size: 12px;
- color: var(--ifm-color-emphasis-600);
-}
-
-.deleteButton {
- background: none;
- border: none;
- color: var(--ifm-color-emphasis-600);
- cursor: pointer;
- padding: 0 4px;
- font-size: 16px;
-}
-
-.deleteButton:hover {
- color: var(--ifm-color-danger);
-}
-
-.commentText {
- font-size: 14px;
- line-height: 1.4;
- color: var(--ifm-color-emphasis-800);
-}
-
-.commentInput {
- display: flex;
- flex-direction: column;
- gap: 8px;
-}
-
-.commentInput textarea {
- width: 100%;
- padding: 8px;
- border: 1px solid var(--ifm-color-emphasis-200);
- border-radius: 4px;
- resize: vertical;
- font-family: inherit;
- font-size: 14px;
-}
-
-.commentInput textarea:focus {
- outline: none;
- border-color: var(--ifm-color-primary);
-}
-
-.submitButton {
- align-self: flex-end;
- padding: 6px 12px;
- background-color: var(--ifm-color-primary);
- color: white;
- border: none;
- border-radius: 4px;
- cursor: pointer;
- font-size: 14px;
- transition: background-color 0.2s ease;
-}
-
-.submitButton:hover {
- background-color: var(--ifm-color-primary-darker);
-}
-
-/* 删除鼠标悬停显示按钮的样式 */
-/* :global(.menu__link-wrapper:hover) .commentButton {
- opacity: 1;
-} */
\ No newline at end of file
diff --git a/src/components/DocComment/index.js b/src/components/DocComment/index.js
new file mode 100644
index 0000000..6764492
--- /dev/null
+++ b/src/components/DocComment/index.js
@@ -0,0 +1,69 @@
+import React, { useState, useEffect } from 'react';
+import styles from './styles.module.css';
+
+export default function DocComment({ docId }) {
+ const [comments, setComments] = useState([]);
+ const [newComment, setNewComment] = useState('');
+
+ 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 (
+
+
评论
+
+ {comments.map(comment => (
+
+
+ {comment.author}
+ {comment.timestamp}
+
+
+
{comment.text}
+
+ ))}
+
+
+
+
+ );
+}
\ No newline at end of file
diff --git a/src/components/DocComment/styles.module.css b/src/components/DocComment/styles.module.css
new file mode 100644
index 0000000..3800464
--- /dev/null
+++ b/src/components/DocComment/styles.module.css
@@ -0,0 +1,97 @@
+YYYY.commentSection {
+ margin-top: 3rem;
+ padding-top: 2rem;
+ border-top: 1px solid var(--ifm-color-emphasis-200);
+}
+
+.commentTitle {
+ font-size: 1.5rem;
+ margin-bottom: 1.5rem;
+ color: var(--ifm-color-emphasis-800);
+}
+
+.commentList {
+ margin-bottom: 2rem;
+}
+
+.commentItem {
+ padding: 1rem;
+ border: 1px solid var(--ifm-color-emphasis-200);
+ border-radius: 8px;
+ margin-bottom: 1rem;
+ background-color: var(--ifm-background-color);
+}
+
+.commentHeader {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 0.5rem;
+}
+
+.commentAuthor {
+ font-weight: 500;
+ color: var(--ifm-color-primary);
+}
+
+.commentTime {
+ font-size: 0.875rem;
+ color: var(--ifm-color-emphasis-600);
+}
+
+.deleteButton {
+ background: none;
+ border: none;
+ color: var(--ifm-color-emphasis-600);
+ cursor: pointer;
+ padding: 0 4px;
+ font-size: 1.25rem;
+}
+
+.deleteButton:hover {
+ color: var(--ifm-color-danger);
+}
+
+.commentText {
+ font-size: 1rem;
+ line-height: 1.5;
+ color: var(--ifm-color-emphasis-800);
+}
+
+.commentInput {
+ display: flex;
+ flex-direction: column;
+ gap: 1rem;
+}
+
+.commentInput textarea {
+ width: 100%;
+ padding: 0.75rem;
+ border: 1px solid var(--ifm-color-emphasis-200);
+ border-radius: 8px;
+ resize: vertical;
+ font-family: inherit;
+ font-size: 1rem;
+ min-height: 100px;
+}
+
+.commentInput textarea:focus {
+ outline: none;
+ border-color: var(--ifm-color-primary);
+}
+
+.submitButton {
+ align-self: flex-end;
+ padding: 0.5rem 1.5rem;
+ background-color: var(--ifm-color-primary);
+ color: white;
+ border: none;
+ border-radius: 6px;
+ cursor: pointer;
+ font-size: 1rem;
+ transition: background-color 0.2s ease;
+}
+
+.submitButton:hover {
+ background-color: var(--ifm-color-primary-darker);
+}
\ No newline at end of file
diff --git a/src/theme/DocItem/index.js b/src/theme/DocItem/index.js
new file mode 100644
index 0000000..c09699f
--- /dev/null
+++ b/src/theme/DocItem/index.js
@@ -0,0 +1,12 @@
+import React from 'react';
+import DocItem from '@theme-original/DocItem';
+import DocComment from '@site/src/components/DocComment';
+
+export default function DocItemWrapper(props) {
+ return (
+ <>
+
+
+ >
+ );
+}
\ No newline at end of file