瀏覽代碼

fix: 知识库过滤助手消息

sheldon 3 周之前
父節點
當前提交
0103aa50dd

+ 1 - 1
src/app.less

@@ -280,7 +280,7 @@ page {
 
 // 空数据提示 ui
 // 飞机
-.data-empty, .data-empty1{
+.data-empty, .data-empty-plane{
   width: 120px;
   height: 120px;
   background-image: url(https://cdn.wehome.cn/cmn/png/8/META-H8UKWHWU-HGXWYHZT5H6E78JCO9YE2-OWTHCUCM-WC.png);

+ 1 - 1
src/components/empty-data/index.tsx

@@ -1,6 +1,6 @@
 import { View } from "@tarojs/components";
 interface IProps {
-  type: 'search'|'chat' | 'box' | 'whiteboard' | (string & {}),
+  type: 'plane'|'search'|'chat' | 'box' | 'whiteboard' | (string & {}),
   text?: string,
   children?: JSX.Element|JSX.Element[]
 }

+ 11 - 31
src/pages/agent-avatars/index.tsx

@@ -17,32 +17,26 @@ import { useAgentStore } from "@/store/agentStore";
 import Taro from "@tarojs/taro";
 import { isSuccess } from "@/utils";
 import IconDeleteGray16 from "@/components/icon/IconDeleteGray16";
-import { useLoadMore } from "@/utils/loadMore";
 import EmptyData from "@/components/empty-data";
 import { useModalStore } from "@/store/modalStore";
-
+import { useLoadMoreInfinite, createKey } from "@/utils/loadMoreInfinite";
 
 export default function Index() {
   const { agent, fetchAgent } = useAgentStore();
-  const [list, setList] = useState<(TAvatarItem | TAvatarItem & { deletedTmp: boolean })[]>([]);
   const [scrollTop, setScrollTop] = useState(0);
   const scrollPositionRef = useRef(0);
 
   const { showModal } = useModalStore()
 
-  const fetcher = async ([_url, _nextId, page, pageSize]) => {
-    const res = await fetchMyAvatars({ pageIndex: page, pageSize });
+  const fetcher = async ([_url, {pageIndex, pageSize}]) => {
+    const res = await fetchMyAvatars({ pageIndex, pageSize });
     return res.data;
   };
 
-  const { data, loadMore, refetch } = useLoadMore<TAvatarItem[]>({
-    url: 'fetchMyAvatars',
-    fetcher,
-  });
+  const { list, loadMore, mutate } = useLoadMoreInfinite<TAvatarItem[]>(createKey('fetchMyAvatars'), fetcher);
 
   const [current, setCurrent] = useState<TAvatarItem | null>(null);
 
-
   const handleClick = async (item: TAvatarItem) => {
     console.log(item);
     if (!agent?.agentId) {
@@ -77,28 +71,13 @@ export default function Index() {
       async onConfirm() {
         const response = await deleteAvatar(avatar.avatarId)
         if(isSuccess(response.status)){
-
-        // todo: 如何解决闪动问题? 直接操作 DOM 隐藏或删除?
-        setList(prevList => {
-          return prevList.map(item => 
-            item.avatarId === avatar.avatarId ? { ...item, deletedTmp: true } : item
-          );
-        })
-        setTimeout(()=> {
-          setScrollTop(scrollPositionRef.current)
-        }, 100)
-          
+          mutate()
         }
       }
     })
     
   }
 
-  useEffect(() => {
-    if (data?.data) {
-      setList([...list, ...data.data]);
-    }
-  }, [data]);
 
   const renderList = ()=> {
     if(!list.length){
@@ -108,19 +87,20 @@ export default function Index() {
     }
     
     return list.map((avatar) => {
+      const isCurrent = agent?.avatarUrl === avatar.avatarUrl;
       return (
         <View
           className={
-            `${current?.avatarUrl === avatar.avatarUrl
+            `${isCurrent
               ? style.gridItemActived
-              : style.gridItem} ${avatar?.deletedTmp ? style.deleted:''}`
+              : style.gridItem}`
             
           }
           onClick={() => handleClick(avatar)}
         >
-          <View className={style.deleteButton} onClick={(e)=> handleDelete(e, avatar)}>
+          {!isCurrent && <View className={style.deleteButton} onClick={(e)=> handleDelete(e, avatar)}>
             <IconDeleteGray16/>
-          </View>
+          </View>}
           <Image
             src={avatar.avatarUrl}
             mode="widthFix"
@@ -135,7 +115,7 @@ export default function Index() {
 
   return (
     <PageCustom>
-      <NavBarNormal backText="历史形象"></NavBarNormal>
+      <NavBarNormal>历史形象</NavBarNormal>
       <View className={style.container}>
       <ScrollView
         scrollY

+ 3 - 2
src/pages/knowledge/components/CompanyTab/components/ScrollList.tsx

@@ -4,7 +4,7 @@ import FigureList from "@/components/list/FigureList";
 import FigureListItem from "@/components/list/FigureListItem";
 import { useDidShow } from "@tarojs/taro";
 import { useEffect, useState } from "react";
-
+import EmptyData from "@/components/empty-data";
 import RotateLoading from "@/components/rotate-loading";
 import Taro from "@tarojs/taro";
 
@@ -20,7 +20,7 @@ export interface Iprops {
 }
 const Index = ({entId}:Iprops) => {
   
-
+  
   const [scrollTop, setScrollTop] = useState(9999)
 
   const fetcher = async ([_url, {nextId, pageSize},  [entId]]) => {
@@ -74,6 +74,7 @@ const Index = ({entId}:Iprops) => {
         height: "100%", // 高度自适应
       }}
     >
+      {list.length<=0 ? <View className="pt-46"><EmptyData type={'plane'}/></View> : <></>}
       <FigureList>
       {list.map(item => {
         return <FigureListItem

+ 15 - 4
src/pages/knowledge/components/CompanyTab/components/ScrollListChat.tsx

@@ -4,6 +4,7 @@ import MessageRich from "@/components/chat-message/MessageRich";
 
 import FigureList from "@/components/list/FigureList";
 import FigureListItem from "@/components/list/FigureListItem";
+import EmptyData from "@/components/empty-data";
 
 import { useEffect, useRef, useState } from "react";
 import Taro, { useDidShow } from "@tarojs/taro";
@@ -19,11 +20,13 @@ import type {TKnowledgeStreamResponseData } from "@/types/knowledge";
 import { DEFAULT_AGENT } from "@/config";
 import { useLoadMoreInfinite, createKey } from "@/utils/loadMoreInfinite";
 
+
 export interface Iprops {
   entId: string | number;
+  assistantOnly?: boolean;
 }
 
-const ViewStyleChatEnt = ({ entId }: Iprops) => {
+const Index = ({ entId, assistantOnly }: Iprops) => {
 
   const [scrollTop, setScrollTop] = useState(9999)
   const { whoami } = useUserStore();
@@ -36,7 +39,14 @@ const ViewStyleChatEnt = ({ entId }: Iprops) => {
     createKey(`getEntKnowledgeStream ${entId}`, 10, [entId]),
     fetcher);
 
-  
+  const getFilterList = (list: TKnowledgeStreamResponseData[]) => {
+    if(!assistantOnly) return list;
+    return list.filter((item) => {
+      return item.role === 'assistant';
+    });
+  };
+
+  const reversedList = getFilterList(list).reverse();
 
 
   const onScrollToUpper = async () => {
@@ -63,7 +73,8 @@ const ViewStyleChatEnt = ({ entId }: Iprops) => {
       }}
     >
       <View className="flex flex-col gap-20 pb-120">
-        {list.map((group) => {
+        {reversedList.length<=0 ? <View className="pt-46"><EmptyData type={'plane'}/></View> : <></>}
+        {reversedList.map((group) => {
           // 渲染自己发送的消息
           if (group.role === "user") {
             return group.knowledgeList.map((item) => {
@@ -127,4 +138,4 @@ const ViewStyleChatEnt = ({ entId }: Iprops) => {
   );
 };
 
-export default ViewStyleChatEnt;
+export default Index;

+ 4 - 4
src/pages/knowledge/components/CompanyTab/index.tsx

@@ -13,14 +13,14 @@ import StyleFilter, {TListStyle} from '../StyleFilter'
 const Index = () => {
   const [listStyle, setListStyle] = useState<TListStyle>("chat");
   const [ent, setEnt] = useState<TEntItem|null>(null)
-  
+  const [assistantOnly, setAssistantOnly] = useState(false);
 
   const renderScrollList = () => {
     if (!ent?.entId) {
       return <></>;
     }
     if (listStyle === "chat") {
-      return <ScrollListChat entId={ent.entId} />;
+      return <ScrollListChat assistantOnly entId={ent.entId} />;
     }
     return <ScrollList entId={ent.entId} />;
   };
@@ -29,9 +29,9 @@ const Index = () => {
     <View className="px-16 h-full">
       <CompanyList setCurrentEnt={setEnt} currentEnt={ent}></CompanyList>
 
-      <StyleFilter listStyle={listStyle} setListStyle={setListStyle}>
+      <StyleFilter checked={assistantOnly} setChecked={setAssistantOnly} listStyle={listStyle} setListStyle={setListStyle}>
         <View className="flex-1 text-12 leading-20 text-gray-45">
-            共 0 个文件
+            共 {ent?.knowledgeCnt ?? 0} 个文件
           </View>
       </StyleFilter>
       

+ 3 - 2
src/pages/knowledge/components/PersonalTab/components/ScrollList.tsx

@@ -23,8 +23,9 @@ import {
 import { useLoadMoreInfinite, createKey } from "@/utils/loadMoreInfinite";
 
 export interface IProps {
-  types?: EKnowlegeTypes[]
+  types?: EKnowlegeTypes[],
 }
+
 const Index = ({types}: IProps) => {
   
   const [scrollTop, setScrollTop] = useState(9999)
@@ -77,7 +78,7 @@ const Index = ({types}: IProps) => {
         height: "100%", // 高度自适应
       }}
     >
-      {list.length<=0 ? <EmptyData type={'search'}/> : <></>}
+      {list.length<=0 ? <View className="pt-46"><EmptyData type={'plane'}/></View> : <></>}
       <FigureList>
       {list.map(item => {
         return <FigureListItem

+ 14 - 3
src/pages/knowledge/components/PersonalTab/components/ScrollListChat.tsx

@@ -24,7 +24,11 @@ import {
 import { useLoadMoreInfinite, createKey } from "@/utils/loadMoreInfinite";
 import { DEFAULT_AGENT } from "@/config";
 
-const ViewStyleChat = () => {
+interface IProps {
+  assistantOnly?: boolean;
+}
+
+const Index = ({assistantOnly}: IProps) => {
 
   const [scrollTop, setScrollTop] = useState(9999)
   // const [list, setList] = useState<TKnowledgeStreamResponseData[]>([]);
@@ -40,7 +44,14 @@ const ViewStyleChat = () => {
     fetcher,
   );
 
-  const reversedList = list.reverse();
+  const getFilterList = (list: TKnowledgeStreamResponseData[]) => {
+    if(!assistantOnly) return list;
+    return list.filter((item) => {
+      return item.role === 'assistant';
+    });
+  };
+
+  const reversedList = getFilterList(list).reverse();
   
 
   
@@ -150,4 +161,4 @@ const ViewStyleChat = () => {
   );
 };
 
-export default ViewStyleChat;
+export default Index;

+ 3 - 3
src/pages/knowledge/components/PersonalTab/index.tsx

@@ -14,7 +14,7 @@ import StyleFilter, {TListStyle} from '../StyleFilter'
 const Index = () => {
   const [showAiAsistant, setShowAiAsistant] = useState(false);
   const [listStyle, setListStyle] = useState<TListStyle>("chat");
-
+  const [assistantOnly, setAssistantOnly] = useState(false);
 
   const handleShowAsistantTip = () => {
     setShowAiAsistant(true)
@@ -22,14 +22,14 @@ const Index = () => {
 
   return (
     <View className="h-full">
-      <StyleFilter listStyle={listStyle} setListStyle={setListStyle}>
+      <StyleFilter onlyAssistantButton checked={assistantOnly} setChecked={setAssistantOnly} listStyle={listStyle} setListStyle={setListStyle}>
         <View className="flex-1 text-12 leading-20 text-gray-45">
             共 0 个文件
           </View>
       </StyleFilter>
 
       <View className="px-16  h-full">
-        {listStyle === "chat" ? <ScrollListChat /> : <ScrollList />}
+        {listStyle === "chat" ? <ScrollListChat assistantOnly={assistantOnly} /> : <ScrollList />}
       </View>
 
       <View

+ 9 - 5
src/pages/knowledge/components/StyleFilter/index.tsx

@@ -12,10 +12,13 @@ interface IProps {
   listStyle?: TListStyle
   setListStyle: (style: TListStyle)=>void
   children: JSX.Element
+  checked: boolean
+  setChecked: (checked: boolean) => void;
+  onlyAssistantButton?: boolean;
 }
 
-const Index = ({listStyle = "chat", setListStyle, children}: IProps) => {
-  const [checked, setChecked] = useState(false);
+const Index = ({listStyle = "chat", setListStyle, checked, setChecked,  onlyAssistantButton = false,children}: IProps) => {
+  
   const [showPopup, setShowPopup] = useState(false);
 
 
@@ -67,7 +70,8 @@ const Index = ({listStyle = "chat", setListStyle, children}: IProps) => {
             handleListStyleChange("chat");
           }}
         >
-          <View className="border-bottom1-gray mb-12">
+
+          <View className={`${onlyAssistantButton ? 'border-bottom1-gray':''} mb-12`}>
             <View className="mb-8 text-14 font-medium leading-22">
               对话信息流
             </View>
@@ -75,7 +79,7 @@ const Index = ({listStyle = "chat", setListStyle, children}: IProps) => {
               以对话形式展示,模拟自然的对话流程。
             </View>
           </View>
-          <View className="flex items-center">
+          {onlyAssistantButton && <View className="flex items-center">
             <View className="flex-1 text-14 font-medium leading-22">
               仅显示 AI 助手信息
             </View>
@@ -83,7 +87,7 @@ const Index = ({listStyle = "chat", setListStyle, children}: IProps) => {
               checked={checked}
               onChange={(checked) => setChecked(checked)}
             ></WemetaSwitch>
-          </View>
+          </View>}
         </View>
         <View
           className={`rounded-card ${

+ 8 - 0
src/utils/loadMoreInfinite.ts

@@ -16,6 +16,14 @@ export const createKey = (query: string, pageSize: number = 10, extra: Record<st
         { nextId: undefined, pageSize },
         extra,
       ];
+      // 如果是以 pageIndex 作为分页依据
+    if (previousPageData && previousPageData.pageIndex) {
+      return [
+        query,
+        { pageSize, pageIndex: previousPageData.pageIndex+1 },
+        extra,
+      ];
+    }
     if (previousPageData && previousPageData.nextId) {
       return [
         query,