From be14099289223a1a82a05d4be5c0bad4fa6f4cd5 Mon Sep 17 00:00:00 2001
From: pfqgauxfb <3521106529@qq.com>
Date: Tue, 3 Jun 2025 10:59:25 +0800
Subject: [PATCH] feng
---
src/components/DocRating/index.js | 57 ++++++++++++++++++
src/components/DocRating/styles.module.css | 69 ++++++++++++++++++++++
src/theme/DocItem/index.js | 2 +
3 files changed, 128 insertions(+)
create mode 100644 src/components/DocRating/index.js
create mode 100644 src/components/DocRating/styles.module.css
diff --git a/src/components/DocRating/index.js b/src/components/DocRating/index.js
new file mode 100644
index 0000000..daf161a
--- /dev/null
+++ b/src/components/DocRating/index.js
@@ -0,0 +1,57 @@
+import React, { useState } from 'react';
+import styles from './styles.module.css';
+
+export default function DocRating({ docId }) {
+ const [hasRated, setHasRated] = useState(false);
+ const [showMessage, setShowMessage] = useState(false);
+ const [message, setMessage] = useState('');
+
+ const handleRating = (isPositive) => {
+ // 保存评级到localStorage
+ const ratings = JSON.parse(localStorage.getItem('docRatings') || '{}');
+ ratings[docId] = isPositive;
+ localStorage.setItem('docRatings', JSON.stringify(ratings));
+
+ // 显示相应的消息
+ setMessage(isPositive
+ ? '感谢您的评价,祝您使用愉快'
+ : '不好意思,给您带来不好的体验,我们一定会积极改进'
+ );
+ setShowMessage(true);
+ setHasRated(true);
+
+ // 3秒后隐藏消息
+ setTimeout(() => {
+ setShowMessage(false);
+ }, 3000);
+ };
+
+ if (hasRated) {
+ return null;
+ }
+
+ return (
+
+
请您对本文档做出评价
+
+
+
+
+ {showMessage && (
+
+ {message}
+
+ )}
+
+ );
+}
\ No newline at end of file
diff --git a/src/components/DocRating/styles.module.css b/src/components/DocRating/styles.module.css
new file mode 100644
index 0000000..f19a9a4
--- /dev/null
+++ b/src/components/DocRating/styles.module.css
@@ -0,0 +1,69 @@
+.ratingSection {
+ margin-top: 2rem;
+ padding: 1.5rem;
+ border: 1px solid var(--ifm-color-emphasis-200);
+ border-radius: 8px;
+ background-color: var(--ifm-background-color);
+ text-align: center;
+}
+
+.ratingText {
+ font-size: 1.1rem;
+ color: var(--ifm-color-emphasis-800);
+ margin-bottom: 1rem;
+}
+
+.ratingButtons {
+ display: flex;
+ justify-content: center;
+ gap: 1rem;
+}
+
+.ratingButton {
+ padding: 0.5rem 2rem;
+ border: none;
+ border-radius: 6px;
+ font-size: 1rem;
+ cursor: pointer;
+ transition: all 0.2s ease;
+}
+
+.positiveButton {
+ background-color: var(--ifm-color-success);
+ color: white;
+}
+
+.positiveButton:hover {
+ background-color: var(--ifm-color-success-darker);
+ transform: translateY(-1px);
+}
+
+.negativeButton {
+ background-color: var(--ifm-color-danger);
+ color: white;
+}
+
+.negativeButton:hover {
+ background-color: var(--ifm-color-danger-darker);
+ transform: translateY(-1px);
+}
+
+.message {
+ margin-top: 1rem;
+ padding: 0.75rem;
+ border-radius: 6px;
+ background-color: var(--ifm-color-emphasis-100);
+ color: var(--ifm-color-emphasis-800);
+ animation: fadeIn 0.3s ease;
+}
+
+@keyframes fadeIn {
+ from {
+ opacity: 0;
+ transform: translateY(-10px);
+ }
+ to {
+ opacity: 1;
+ transform: translateY(0);
+ }
+}
\ No newline at end of file
diff --git a/src/theme/DocItem/index.js b/src/theme/DocItem/index.js
index c09699f..8cc74c5 100644
--- a/src/theme/DocItem/index.js
+++ b/src/theme/DocItem/index.js
@@ -1,11 +1,13 @@
import React from 'react';
import DocItem from '@theme-original/DocItem';
import DocComment from '@site/src/components/DocComment';
+import DocRating from '@site/src/components/DocRating';
export default function DocItemWrapper(props) {
return (
<>
+
>
);