Jelajahi Sumber

fleat: update feedback

igb 1 Minggu lalu
induk
melakukan
1c5d191c20
2 mengubah file dengan 112 tambahan dan 23 penghapusan
  1. 53 9
      usr/themes/beardocs/archive.php
  2. 59 14
      usr/themes/beardocs/footer.php

+ 53 - 9
usr/themes/beardocs/archive.php

@@ -1,6 +1,9 @@
 <?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
 
-
+if(!empty($_GET['feedback'])) {
+    require_once __DIR__ . '/feedback.php';
+    exit;
+}
 ?>
 <?php $this->need('header.php'); ?>
 
@@ -8,18 +11,14 @@
 
 
 
-
-
-
-
-
 // 示例调用
-$token = 'dataset-Emh5R5hCGorTuqG0dkQe7tMf';  // 传入实际的 token
+$token = 'dataset-Emh5R5hCGorTuqG0dkQe7tMf';  // 传入实际的 toke
 $datasets = 'c08ae7fa-c4e7-4fae-8138-2097ff19e1a6';  // 传入实际的 datasets ID
 $keyword =  '';//'how to cute';  // 传入实际的查询关键字
 $PathInfo = Typecho_Widget::widget('Widget_Options')->request->getPathInfo();;
 
 
+
 // 检查请求路径是否以 '/search' 开头
 if (strpos($PathInfo, '/search') === 0)
 {
@@ -32,9 +31,7 @@ if (strpos($PathInfo, '/search') === 0)
 
 
 if(!empty($_GET['category'])) {
-
     $category_id = $_GET['category'] * 1;
-
 }
 ?>
 
@@ -125,11 +122,15 @@ $thisChild["name"] ?></a></li> <?php }  ?>
       <script>
           function toggleAnswer(index) {
               var answerDiv = document.getElementById('answer-' + index);
+              var feedbackDiv = document.getElementById('feedback-' + index);
               var icon = document.getElementById('icon-' + index);
 
               if (answerDiv.style.display === 'none') {
            
                   answerDiv.style.display = 'block';
+                  feedbackDiv.style.display = 'block';
+
+
                   //icon.innerHTML = '▲'; // 展开时显示向上箭头
                   
                   // 找到当前答案中的视频并自动播放
@@ -139,6 +140,7 @@ $thisChild["name"] ?></a></li> <?php }  ?>
                   }
               } else {
                   answerDiv.style.display = 'none';
+                  feedbackDiv.style.display = 'none';
                   //icon.innerHTML = '▼'; // 收起时显示向下箭头
                   
                   // 如果答案被隐藏,暂停视频播放
@@ -183,6 +185,10 @@ $thisChild["name"] ?></a></li> <?php }  ?>
               padding-left: 20px; /* 答案缩进 */
 
           }
+
+          .feedback-btn {
+          border: 1px solid #ddd; background: #f8f8f8; border-radius: 4px; padding: 5px 15px; margin-right: 10px; cursor: pointer; height: 32px; line-height: 1; display: inline-flex; align-items: center;
+          }
           
           /* 在手机设备上将卡片padding设为0 */
           @media (max-width: 768px) {
@@ -347,6 +353,24 @@ if (!empty($keyword)&&(strpos($PathInfo, '/search') === 0))
                 <div id="answer-<?= $index ?>" class="answer" style="display: none;white-space: pre-line;">
                     <?= $answer ?>
                 </div>
+                <!-- 添加反馈按钮 -->
+                <div  id="feedback-<?= $index ?>" class="feedback-container " style="display: none; margin-top: 30px; padding: 0 15px 15px 15px; text-align: center">
+                    <div class="feedback-question" style="font-size: 14px; color: #666; margin-bottom: 5px;">Was this article helpful to you?</div>
+                    <div class="feedback-buttons">
+                        <button class="feedback-btn  feedback-btn-<?= $index ?> helpful-btn" onclick="recordFeedback(<?= $index ?>, '<?= htmlspecialchars(addslashes($question), ENT_QUOTES, 'UTF-8') ?>', 1)"  title="YES">
+                            <i class="ri-thumb-up-line"></i>
+                        </button>
+                        <button class="feedback-btn feedback-btn-<?= $index ?> not-helpful-btn" onclick="recordFeedback(<?= $index ?>, '<?= htmlspecialchars(addslashes($question), ENT_QUOTES, 'UTF-8') ?>', 0)"  title="NO">
+                            <i class="ri-thumb-down-line"></i>
+                        </button>
+                        <button onclick="window.open('https://wa.me/8617000161888?text=Hello!', '_blank')" class="feedback-btn" title="No result ? Contact us on WhatsApp." >
+                            <i class="ri-whatsapp-line"></i>
+                            feedback
+                        </button>
+                    </div>
+                    <div id="feedback-result-<?= $index ?>" class="feedback-result" style="display: none; color: #666; margin-top: 5px;"></div>
+                </div>
+
             </div>
 
 
@@ -494,6 +518,24 @@ if (!empty($keyword)&&(strpos($PathInfo, '/search') === 0))
                 <div id="answer-<?= $index ?>" class="answer" style="display: none;white-space: pre-line;">
                     <?= $answer ?>
                 </div>
+                <!-- 添加反馈按钮 -->
+                <div  id="feedback-<?= $index ?>" class="feedback-container " style="display: none; margin-top: 30px; padding: 0 15px 15px 15px; text-align: center">
+                    <div class="feedback-question" style="font-size: 14px; color: #666; margin-bottom: 5px;">Was this article helpful to you?</div>
+                    <div class="feedback-buttons">
+                        <button class="feedback-btn  feedback-btn-<?= $index ?> helpful-btn" onclick="recordFeedback(<?= $index ?>, '<?= htmlspecialchars(addslashes($question), ENT_QUOTES, 'UTF-8') ?>', 1)"  title="YES">
+                            <i class="ri-thumb-up-line"></i>
+                        </button>
+                        <button class="feedback-btn feedback-btn-<?= $index ?> not-helpful-btn" onclick="recordFeedback(<?= $index ?>, '<?= htmlspecialchars(addslashes($question), ENT_QUOTES, 'UTF-8') ?>', 0)"  title="NO">
+                            <i class="ri-thumb-down-line"></i>
+                        </button>
+                        <button onclick="window.open('https://wa.me/8617000161888?text=Hello!', '_blank')" class="feedback-btn" title="No result ? Contact us on WhatsApp." >
+                            <i class="ri-whatsapp-line"></i>
+                            feedback
+                        </button>
+                    </div>
+                    <div id="feedback-result-<?= $index ?>" class="feedback-result" style="display: none; color: #666; margin-top: 5px;"></div>
+                </div>
+
             </div>
 
 
@@ -552,4 +594,6 @@ if (!empty($keyword)&&(strpos($PathInfo, '/search') === 0))
 </div>
 
 
+
+
 <?php $this->need('footer.php'); ?>

+ 59 - 14
usr/themes/beardocs/footer.php

@@ -18,20 +18,20 @@ $currentUrl = $_SERVER['REQUEST_URI'];
 <!--	</div>-->
 <!--</footer>-->
 
-    <footer class="uk-background-secondary uk-background-norepeat uk-background-cover uk-background-center-center uk-light uk-margin-large-top" >
-        <div class="uk-section uk-section-small uk-section-hero uk-position-relative" data-uk-scrollspy="cls: uk-animation-slide-bottom-medium; repeat: false">
-            <div class="uk-container">
-                <div class="hero-search">
-                    <div class="uk-position-relative" style="display: flex; justify-content: center; align-items: center; height: 40px;"> <!-- 设置固定高度 -->
-                <div class='lxdh'>
-                            <a href="https://wa.me/8617000161888?text=Hello!">No result ? Contact us on WhatsApp.</a>
-                   </div>
-                    </div>
-                </div>
-            </div>
-        </div>
-
-    </footer>
+<!--    <footer class="uk-background-secondary uk-background-norepeat uk-background-cover uk-background-center-center uk-light uk-margin-large-top" >-->
+<!--        <div class="uk-section uk-section-small uk-section-hero uk-position-relative" data-uk-scrollspy="cls: uk-animation-slide-bottom-medium; repeat: false">-->
+<!--            <div class="uk-container">-->
+<!--                <div class="hero-search">-->
+<!--                    <div class="uk-position-relative" style="display: flex; justify-content: center; align-items: center; height: 40px;"> <!-- 设置固定高度 -->-->
+<!--                <div class='lxdh'>-->
+<!--                            <a href="https://wa.me/8617000161888?text=Hello!">No result ? Contact us on WhatsApp.</a>-->
+<!--                   </div>-->
+<!--                    </div>-->
+<!--                </div>-->
+<!--            </div>-->
+<!--        </div>-->
+<!---->
+<!--    </footer>-->
 <?php
 }
 ?>
@@ -46,5 +46,50 @@ $currentUrl = $_SERVER['REQUEST_URI'];
 <?php echo General::Options('CustomizationFooterJsCode'); ?>
 <?php $this->footer(); ?>
 <script src="<?php $this->options->themeUrl('assets/plugins/instant.page/instantpage.min.js'); ?>"></script>
+
+<!-- 添加反馈功能的JavaScript代码 -->
+<script>
+  function recordFeedback(questionId, questionTitle, isHelpful) {
+      // 显示加载状态
+      var resultDiv = document.getElementById('feedback-result-' + questionId);
+      resultDiv.style.display = 'block';
+      resultDiv.innerHTML = 'Submitting your feedback...';
+      
+      // 准备发送的数据
+      var data = new FormData();
+      data.append('action', 'recordFeedback');
+      data.append('questionId', questionId);
+      data.append('questionTitle', questionTitle);
+      data.append('isHelpful', isHelpful);
+      
+      // 发送AJAX请求
+      fetch('/index.php/category/M288/?feedback=1', {
+          method: 'POST',
+          body: data
+      })
+      .then(response => response.json())
+      .then(data => {
+          resultDiv.innerHTML = data.message;
+          
+          // 如果提交成功,禁用按钮
+          if (data.status === 'success') {
+
+            
+              // 禁用按钮,避免重复提交
+              var buttons = document.querySelectorAll(".feedback-btn-"+questionId);
+              buttons.forEach(function(btn) {
+                  btn.disabled = true;
+                  btn.style.opacity = '0.5';
+                  btn.style.cursor = 'default';
+              });
+          }
+      })
+      .catch(error => {
+          resultDiv.innerHTML = 'Submission failed, please try again later.';
+          console.error('Error:', error);
+      });
+  }
+</script>
+
 </body>
 </html>