Sfoglia il codice sorgente

Dify的跳转项改为iframe嵌入

xuyonghao 1 anno fa
parent
commit
dcbcf5a38a

+ 4 - 2
src/base/store/use-inject.js

@@ -4,14 +4,16 @@ export const useInject = defineStore('use_injecrt', {
   state: () => ({
     user_page: {
       chat_id: '',
-      page_id: 0
+      page_id: 0,
+      type: ''
     },
     selectedFeature: null // 记录选中的功能项
   }),
   actions: {
-    updateUserPage(chat_id, page_id) {
+    updateUserPage(chat_id, page_id, type) {
       this.user_page.chat_id = chat_id;
       this.user_page.page_id = page_id;
+      this.user_page.type = type;
     },
     setSelectedFeature(feature) {
       this.selectedFeature = feature;

+ 6 - 1
src/modules/chart/df_iframe.vue

@@ -18,6 +18,11 @@ const baseurl = getConfigField("API_BASE_URL");
 // 动态计算 iframe_url
 const iframe_url = computed(() => {
   const iframe_id = store.user_page.chat_id; // 从 Pinia 状态中获取 iframe_id
-  return `${baseurl}/chatbot/${iframe_id}`;
+  const type = store.user_page.type; // 获取 type 值。
+  if (type === "work_flow"){
+   return `${baseurl}/workflow/${iframe_id}`; // 嵌入'运行'页面
+  } else {
+    return `${baseurl}/chatbot/${iframe_id}`; // 嵌入 dify 提供的iframe链接
+  }
 });
 </script>

+ 16 - 7
src/modules/home/sidebar_list.vue

@@ -45,22 +45,31 @@ const handleFeatureClick = (item, index) => {
   const type = item.type;
 
   if (type === 'workflow') {
-    const dify_token = access_token.get();
-    // 跳转页面
-    // const workflowUrl = `${baseurl}/apps?token=${dify_token}`;
-    const workflowUrl = `${baseurl}/workflow/${iframe_id}?token=${dify_token}`;
+    if (store.selectedFeature === item.label) {
+      //到主页
+      store.updateUserPage('', '', '');
+      store.setSelectedFeature(null);
+    } else {
+      // const dify_token = access_token.get();
+      // 跳转到“运行”
+      // const workflowUrl = `${baseurl}/workflow/${iframe_id}?token=${dify_token}`;
+      // window.open(workflowUrl, '_blank');
 
-    window.open(workflowUrl, '_blank');
+      // 工作流类型进行iframe嵌入
+      store.updateUserPage(iframe_id, item.label, "work_flow");
+      store.setSelectedFeature(item.label);
+    }
   } else if (type === 'link') {
     // 跳转到链接
     window.open(iframe_id, '_blank');
   } else {
     if (store.selectedFeature === item.label) {
       //到主页
-      store.updateUserPage('', '');
+      store.updateUserPage('', '', '');
       store.setSelectedFeature(null);
     } else {
-      store.updateUserPage(iframe_id, item.label);
+      // 聊天助手与agent类型,dify提供了嵌入页面
+      store.updateUserPage(iframe_id, item.label, "");
       store.setSelectedFeature(item.label);
     }
   }

+ 6 - 2
src/modules/home/x_card_window.vue

@@ -37,11 +37,15 @@ const handleCardClick = (item) => {
 
   if (type === 'workflow') {
     const dify_token = access_token.get();
-    window.open(`${baseurl}/workflow/${iframe_id}?token=${dify_token}`, '_blank');
+    // 跳转到 dify
+    // window.open(`${baseurl}/workflow/${iframe_id}?token=${dify_token}`, '_blank');
+    // iframe 嵌入
+    store.updateUserPage(iframe_id, name, 'work_flow');
+    store.setSelectedFeature(name);
   } else if (type === 'link') {
     window.open(iframe_id, '_blank');
   } else {
-    store.updateUserPage(iframe_id, name);
+    store.updateUserPage(iframe_id, name, '');
     store.setSelectedFeature(name);
   }
 };