diff --git a/src/components/Comments/index.js b/src/components/Comments/index.js index 62cba95..fce6a87 100644 --- a/src/components/Comments/index.js +++ b/src/components/Comments/index.js @@ -1,36 +1,79 @@ -import React from 'react'; -import Giscus from '@giscus/react'; -import Rating from '../Rating'; +import React, { useState } from 'react'; import styles from './styles.module.css'; const Comments = () => { - const handleRating = (rating) => { - // 这里可以添加评分提交逻辑 - console.log('Rating submitted:', rating); + const [rating, setRating] = useState(0); + const [comment, setComment] = useState(''); + const [comments, setComments] = useState([]); + + const handleSubmit = (e) => { + e.preventDefault(); + if (comment.trim()) { + setComments([ + ...comments, + { + rating, + text: comment, + date: new Date().toLocaleString(), + }, + ]); + setComment(''); + setRating(0); + } }; return (
+

文档评分与评论

+
-

文档评分

- +
+ {[1, 2, 3, 4, 5].map((star) => ( + setRating(star)} + > + ★ + + ))} +
+
+ {rating ? `您给了 ${rating} 星评价` : '请为本文档评分'} +
- -
-

评论区

- +