Parcourir la source

fix: 视频提取

lxf il y a 12 heures
Parent
commit
f0f8a64a4f

+ 27 - 9
src/views/old_mini/home/components/knowledgeCard.vue

@@ -34,8 +34,10 @@
 <script setup>
 import { onMounted, ref } from "vue";
 import { useRouter } from "vue-router";
+import { useStore } from "vuex";
 
 const router = useRouter();
+const store = useStore();
 const activeKnowledgeId = ref(6);
 
 // 按 topicId 缓存知识列表,避免每次切换都请求接口
@@ -74,18 +76,34 @@ const formatDate = (dateString) => {
     return dateString.split("T")[0];
 };
 
-const getKnowledgeList = () => {
-    const params = {
-        page: 1,
-        limit: 10,
-        topicId: activeKnowledgeId.value,
-    };
-    VE_API.home.warningPageList(params).then(({ data }) => {
-        knowledgeList.value = data;
+const getKnowledgeList = async () => {
+    try {
+        let data = [];
+        
+        if (activeKnowledgeId.value === 6) {
+            // 种植知识库:使用新接口
+            const { data: result } = await VE_API.user.listWithAnswer({ 
+                farmId: store.state.home.gardenId 
+            });
+            data = result || [];
+        } else {
+            // 实战知识库:使用原接口
+            const params = {
+                page: 1,
+                limit: 10,
+                topicId: activeKnowledgeId.value,
+            };
+            const { data: result } = await VE_API.home.warningPageList(params);
+            data = result || [];
+        }
 
+        knowledgeList.value = data;
         // 按当前 topicId 缓存,后续切换直接读取
         knowledgeCache.value[activeKnowledgeId.value] = data;
-    });
+    } catch (error) {
+        console.error("获取知识列表失败:", error);
+        knowledgeList.value = [];
+    }
 };
 </script>
 

+ 41 - 1
src/views/old_mini/home/subPages/warningDetail.vue

@@ -42,7 +42,7 @@
             </div> -->
 
             <div class="article-text">
-                <span v-html="warningDetail.content"></span>
+                <span v-html="processedContent"></span>
             </div>
 
             <div class="article-box" :style="{ bottom: isLink ? '10px' : '70px' }" v-if="pageParams.questTitle && showArticleBox">
@@ -122,6 +122,35 @@ import { ElMessage } from "element-plus";
 import { Popup } from "vant";
 import wx from "weixin-js-sdk";
 
+// 处理内容中的 iframe 视频标签,转换为 video 标签
+const processVideoContent = (content) => {
+    if (!content) return "";
+    
+    // 匹配 iframe 标签,提取 mp4 视频链接(支持各种属性顺序)
+    const iframeRegex = /<iframe[^>]*class=["']ql-video["'][^>]*src=["']([^"']+\.mp4[^"']*)["'][^>]*><\/iframe>/gi;
+    
+    return content.replace(iframeRegex, (match, videoUrl) => {
+        // 清理视频 URL(去除可能的双斜杠)
+        const cleanUrl = videoUrl.replace(/([^:]\/)\/+/g, "$1");
+        
+        // 将 iframe 替换为 video 标签,小程序可以播放
+        return `<video 
+            src="${cleanUrl}" 
+            controls 
+            style="width: 100%; max-width: 100%; height: auto; border-radius: 5px; margin: 10px 0;"
+            preload="metadata"
+            playsinline
+            webkit-playsinline
+            x5-playsinline
+        ></video>`;
+    });
+};
+
+// 处理后的内容
+const processedContent = computed(() => {
+    return processVideoContent(warningDetail.value.content || "");
+});
+
 const showQuestionPopup = ref(false);
 const handleEdit = () => {
     VE_API.monitor
@@ -367,6 +396,17 @@ const handleEditQuestion = () => {
                     border-radius: 5px;
                     object-fit: cover;
                 }
+                video {
+                    width: 100%;
+                    max-width: 100%;
+                    height: auto;
+                    border-radius: 5px;
+                    margin: 10px 0;
+                    display: block;
+                }
+                iframe {
+                    display: none;
+                }
             }
         }