Răsfoiți Sursa

feat: 完善对话板块的错误处理

1. 优化对话历史记录的展示
zhupei@smartai.com 1 an în urmă
părinte
comite
2b2435efd3

+ 1 - 1
src/base/storage.js

@@ -12,8 +12,8 @@ export const localST_Theme = new MyLocalStorage('theme'); // 主题
 export const localST_Locale = new MyLocalStorage('locale'); // 多语言
 export const localST_RecentAgent = new MyLocalStorage('recent_agent'); // 近期使用的agent
 export const localST_AllAgent = new MyLocalStorage('full_agent'); // 所有可用的agent
-
 export const localST_UserInfo = new MyLocalStorage('user_info'); // 所有可用的agent
+export const localST_RecentSearchType = new MyLocalStorage('recent_search_type'); // 最近的
 
 /**
  * session storage定义

+ 58 - 0
src/base/store/use-recent-history-search-type.js

@@ -0,0 +1,58 @@
+import { defineStore } from 'pinia';
+import { localST_RecentSearchType } from '../storage';
+import { jsonStringify, jsonParse } from '../../utils/utils';
+
+function recentLocalSet(item) {
+  // 在本地保存记录
+  const result_str = jsonStringify(item);
+
+  localST_RecentSearchType.setItem(result_str);
+}
+
+function recentLocalGet() {
+  const result_str = localST_RecentSearchType.getItem();
+
+  const result_list = jsonParse(result_str);
+
+  if (result_list === null) {
+    // json解析发生了错误
+    return [];
+  } else {
+    return result_list;
+  }
+}
+
+/**
+ * 最近使用的搜索类型
+ */
+export const useRecentSearchTypeStore = defineStore('recent_history_search_type', {
+  state: () => {
+    return {
+      search_type: recentLocalGet()
+    };
+  },
+  actions: {
+    /**
+     * 获取记录
+     * @returns
+     */
+    getType() {
+      const cur_type = this.search_type;
+
+      if (cur_type.length === 0) {
+        this.search_type = recentLocalGet();
+
+        return this.search_type;
+      }
+
+      return this.search_type;
+    },
+    /**
+     * 保存记录
+     */
+    setType(item) {
+      this.search_type = item;
+      recentLocalSet(item);
+    }
+  }
+});

+ 1 - 1
src/modules/conversation-board/use-agent-list-4-history.js

@@ -55,7 +55,7 @@ export default function useAgentList4History(onSuccess) {
           const res_list = res.data; // 历史记录列表
           if (res_list.length !== 0) {
             if (typeof onSuccess === 'function') {
-              onSuccess(res_list[0]);
+              onSuccess(res_list);
             }
           }
 

+ 31 - 7
src/modules/conversation-history/HistoryTypeDropdown.vue

@@ -1,14 +1,15 @@
 <template>
-  <a-dropdown trigger="hover">
-    <a-button v-if="api_status === 1" class="history-type-btn" type="text">{{ btn_label }}</a-button>
+  <a-dropdown trigger="hover" :defaultValue="btn_label_str">
+    <a-button v-if="api_status === 1" class="history-type-btn" type="text">{{ btn_label_str }}</a-button>
     <a-button v-if="api_status === 2" class="history-type-btn" type="text"><a-spin :size="16" /></a-button>
-    <a-button v-if="api_status === 3" class="history-type-btn" type="text">{{ btn_label }}</a-button>
+    <a-button v-if="api_status === 3" class="history-type-btn" type="text">{{ btn_label_str }}</a-button>
 
     <template #content>
       <a-doption
         v-for="(item, index) of list_agents"
         :key="item.id"
         :disabled="disabled_options"
+        :value="item.name"
         @click="handleChatTypeConfirm(item)"
         >{{ item.name }}</a-doption
       >
@@ -20,6 +21,7 @@
 import { ref, computed, onMounted } from 'vue';
 
 import useAgentList4History from '../conversation-board/use-agent-list-4-history';
+import { useRecentSearchTypeStore } from '../../base/store/use-recent-history-search-type';
 
 const props = defineProps({
   /**
@@ -29,14 +31,36 @@ const props = defineProps({
   list_status: Number
 });
 
-const btn_label = ref('');
+const recentSearchType = useRecentSearchTypeStore();
 
-const { api_status, api_message, list_agents, getAgentList } = useAgentList4History((item) => {
-  handleChatTypeConfirm(item);
+const { api_status, api_message, list_agents, getAgentList } = useAgentList4History((agent_list) => {
+  const cur_id = recentSearchType?.search_type?.id || '';
+
+  let item = null;
+
+  const len = agent_list.length;
+  for (let i = 0; i < len; i++) {
+    const agent = agent_list[i];
+
+    if (agent.id === cur_id) {
+      item = agent;
+      break;
+    }
+  }
+
+  if (item) {
+    handleChatTypeConfirm(item);
+  } else {
+    handleChatTypeConfirm(agent_list[0]);
+  }
 });
 
 const emit = defineEmits(['typeSelected']);
 
+const btn_label_str = computed(() => {
+  return recentSearchType?.search_type?.name || '';
+});
+
 /**
  * 是否禁用下拉菜单
  * 当列表正在加载时,应该禁用下拉菜单
@@ -49,7 +73,7 @@ const disabled_options = computed(() => {
  * 已经确定类型
  */
 const handleChatTypeConfirm = (item) => {
-  btn_label.value = item.name;
+  recentSearchType.setType(item);
 
   emit('typeSelected', item);
 };

+ 6 - 1
src/views/conversation/ConversationChatContainer.vue

@@ -509,7 +509,12 @@ function handleWSMessage(e) {
  * 处理websocket错误
  * @param e
  */
-function handleWSError(e) {}
+function handleWSError(e) {
+  console.log('socket-error-8jfdksagjsfdjaklnfsdajkl', e);
+  handleChatRequestionException({
+    message: e.message
+  });
+}
 
 /**
  * 处理websocket关闭事件

+ 4 - 0
src/views/conversation/ConversationHistoryContainer.vue

@@ -260,6 +260,10 @@ const handleTypeSelected = (type_item) => {
     return;
   }
 
+  if (!type_item) {
+    return;
+  }
+
   // 统计数据归位
   count_today.value = 0;
   count_month.value = 0;