Переглянути джерело

fix: 修复知识库统计数,文本编辑默认值

sheldon 2 тижнів тому
батько
коміт
0c3789ab93

+ 3 - 2
src/components/component-list/index.tsx

@@ -245,7 +245,7 @@ export default ({ components, editMode = false }: Props) => {
             ),
           };
         }
-
+        // 标题组件
         if (c.data && c.type === "title") {
           return {
             component: c,
@@ -264,6 +264,7 @@ export default ({ components, editMode = false }: Props) => {
             ),
           };
         }
+        // 文本组件
         if (c.type === "text") {
           return {
             component: c,
@@ -297,7 +298,7 @@ export default ({ components, editMode = false }: Props) => {
                     center={c.data.layout === "center"}
                     data={c}
                   >
-                    {c.data.text}
+                    {c.data.text.length <= 0 ?  c.data.placeholder : c.data.text}
                   </WidgetContent>
                 </WidgetCard>
               </>

+ 2 - 1
src/pages/component-library/components/createComponentData.ts

@@ -8,7 +8,8 @@ export function createComponentData(type: EComponentType): Record<string, any> |
   }
   if(type === EComponentType.text){
     return {
-      text: '点击编辑输入您的文本内容',
+      text: '',
+      placeholder: '点击编辑输入您的文本内容',
       layout: 'left'
     }
   }

+ 99 - 15
src/pages/dislike-messages/index.tsx

@@ -36,12 +36,33 @@ export default function Index() {
     });
     return res.data;
   };
-  const { list, loadMore, setSize, pages, pageIndex, mutate } = useLoadMoreInfinite<TVisitorChat[]>(
-    createKey(`getVisitorDislikeMessages${agentId}`),
-    fetcher
-  );
+  const { list, loadMore, setSize, pages, pageIndex, mutate } =
+    useLoadMoreInfinite<TVisitorChat[]>(
+      createKey(`getVisitorDislikeMessages${agentId}`),
+      fetcher
+    );
+  const qaList: { user?: TVisitorChat; assistant?: TVisitorChat }[] = [];
+
+  // 从数组中提取问答对
+  // 暂定奇数行是用户的提问,偶数行是助手的回答
+  // 其中有些只有用户提问,但由于错误或网络问题导致没有助手回答需要跳过
+  for (let i = 0; i < list.length; i++) {
+    const item: { user?: TVisitorChat; assistant?: TVisitorChat } = {};
+    if (list[i].role === "user") {
+      item.user = list[i];
+      if (list[i + 1]?.role === "assistant") {
+        item.assistant = list[i + 1];
+        qaList.push(item);
+        i++; // 跳过下一个元素,因为它已经被配对了
+      }else{
+        continue; // 如果下一个不是 assistant,则跳过当前 user
+      }
+    }
+  }
 
-  const dislikeList = list.filter((_item) => _item.role === 'assistant');
+  // console.log(qaList);
+
+  // const dislikeList = list.filter((_item) => _item.role === 'assistant');
 
   const handleEdit = (item: TVisitorChat) => {
     Taro.navigateTo({
@@ -51,7 +72,6 @@ export default function Index() {
 
   // 删除问答项
   const handleDeleteItem = async (item: TVisitorChat) => {
-    
     showModal({
       content: "确定删除该问答项吗?",
       onConfirm: async () => {
@@ -66,21 +86,21 @@ export default function Index() {
           // }
           // 1. 乐观更新:立即移除数据
           mutate((currentPages) => {
-            if(currentPages === undefined) return currentPages;
+            if (currentPages === undefined) return currentPages;
             // 创建全新的 pages 数组(深拷贝)
             const newPages = currentPages.map((page, index) => {
               // 如果不是目标页,直接返回原引用(避免不必要的重渲染)
               if (index !== pageIndex - 1) return page;
-              
+
               // 创建目标页的新副本
               return {
                 ...page, // 复制其他属性
-                data: page.data.filter(_item => _item.msgId !== item.msgId)
+                data: page.data.filter((_item) => _item.msgId !== item.msgId),
               };
             });
-            
+
             return newPages;
-          }, false) // 不重新验证
+          }, false); // 不重新验证
         }
       },
     });
@@ -96,7 +116,7 @@ export default function Index() {
   };
 
   useDidShow(() => {
-    mutate()
+    mutate();
   });
 
   const createCardOptions = (item: TVisitorChat) => {
@@ -126,8 +146,72 @@ export default function Index() {
           }}
         >
           <View className="pb-80">
-            {dislikeList.length <=0 ? <View className="pt-24"><EmptyData type="box" /> </View>: <></>}
-            {dislikeList.map((item) => {
+            {qaList.length <= 0 ? (
+              <View className="pt-24">
+                <EmptyData type="box" />{" "}
+              </View>
+            ) : (
+              <></>
+            )}
+            {/* {dislikeList.length <=0 ? <View className="pt-24"><EmptyData type="box" /> </View>: <></>} */}
+            {qaList.map((item) => {
+              if (!item.assistant) {
+                return <></>;
+              }
+              return (
+                <View className="flex flex-col gap-16 px-16 mb-16">
+                  <CardEditable buttons={createCardOptions(item.assistant)}>
+                    <View className="flex items-start mb-8 gap-8">
+                      <View className="flex-center h-28">
+                        <IconQ />
+                      </View>
+                      <View className="flex-1 font-medium text-14 leading-28">
+                        {item.user?.content}
+                      </View>
+                    </View>
+
+                    <View className="flex items-start gap-8">
+                      <View className="flex-center  h-28">
+                        <IconA />
+                      </View>
+                      <View className="flex-1 text-12 leading-20 text-gray-45 truncate">
+                        <View className="truncate">
+                          {item.assistant.content}
+                        </View>
+
+                        {!!item.assistant?.correctionLinks?.length && (
+                          <View className="pb-12">
+                            {item.assistant.correctionLinks.map((link) => {
+                              return (
+                                <View>
+                                  查看链接 <Text>{link}</Text>
+                                </View>
+                              );
+                            })}
+                          </View>
+                        )}
+                        {!!item?.assistant.correctionPics?.length && (
+                          <View className="pb-12">
+                            {item.assistant.correctionPics.map((pic) => {
+                              return (
+                                <View>
+                                  <Image
+                                    src={pic}
+                                    mode="widthFix"
+                                    className="w-full"
+                                  ></Image>
+                                </View>
+                              );
+                            })}
+                          </View>
+                        )}
+                      </View>
+                    </View>
+                  </CardEditable>
+                </View>
+              );
+            })}
+            {/* {dislikeList.map((item) => {
               return (
                 <View className="flex flex-col gap-16 px-16 mb-16">
                   <CardEditable buttons={createCardOptions(item)}>
@@ -180,7 +264,7 @@ export default function Index() {
                   </CardEditable>
                 </View>
               );
-            })}
+            })} */}
           </View>
         </ScrollView>
       </View>

+ 4 - 4
src/pages/editor-pages/editor-textarea/index.tsx

@@ -3,7 +3,7 @@ import { View } from "@tarojs/components";
 import PageCustom from "@/components/page-custom/index";
 import NavBarNormal from "@/components/NavBarNormal/index";
 import BottomBar from "@/components/BottomBar";
-import editorStyle from "../editor.module.less";
+import ButtonMain from "@/components/buttons/ButtonMain";
 import { useComponentStore } from "@/store/componentStore";
 import Taro, { useUnload } from "@tarojs/taro";
 import WemetaTextarea from "@/components/wemeta-textarea/index";
@@ -16,7 +16,7 @@ export default function Index() {
   const { saveComponent } = useComponentStore();
   const loading = useComponentStore((state)=> state.loading);
   const [value, setValue] = useState<string>(currentComponent?.data?.text ?? '');
-
+  const placehoder = currentComponent?.data?.placeholder ?? '点击编辑输入您的文本内容';
   
 
   const handleSubmit = async () => {
@@ -62,13 +62,13 @@ export default function Index() {
           <WemetaTextarea
               value={value}
               onInput={(value: any) => onChange(value)}
-              placeholder="文本内容"
+              placeholder={placehoder}
               cursorSpacing={100}
               maxlength={2000}
             />
         </View>
         <BottomBar>
-          <View className="button-rounded button-primary flex-1" onClick={handleSubmit}>保存</View>
+          <ButtonMain className="flex-1" disabled={!value.length} onClick={handleSubmit}>保存</ButtonMain>
         </BottomBar>
       </View>
     </PageCustom>

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

@@ -17,8 +17,9 @@ import type { TKnowledgeItem } from "@/types/knowledge";
 import { useLoadMoreInfinite, createKey } from "@/utils/loadMoreInfinite";
 export interface Iprops {
   entId: string|number
+  setTotalCount: (count: number) => void;
 }
-const Index = ({entId}:Iprops) => {
+const Index = ({entId, setTotalCount}:Iprops) => {
   
   
   const [scrollTop, setScrollTop] = useState(9999)
@@ -27,7 +28,7 @@ const Index = ({entId}:Iprops) => {
     const res = await getEntKnowledgeList({ startId: nextId, pageSize, entId });
     return res.data;
   };
-  const { list, loadMore, pageIndex, mutate } = useLoadMoreInfinite<TKnowledgeItem[]>(createKey(`getEntKnowledgeList ${entId}`, 10, [entId]),
+  const { list, loadMore, pageIndex, mutate, data } = useLoadMoreInfinite<TKnowledgeItem[]>(createKey(`getEntKnowledgeList ${entId}`, 10, [entId]),
     fetcher);
 
   const onScrollToUpper = async () => {
@@ -42,6 +43,12 @@ const Index = ({entId}:Iprops) => {
       setScrollTop(prev => prev + 1)
     }
   }, [pageIndex]);
+
+  useEffect(() => {
+    if(data &&  pageIndex === 1) {
+      setTotalCount(data?.[0].totalCount || 0)
+    }
+  }, [data, pageIndex]);
   
 
   const handleEdit = (item: TKnowledgeItem)=> {

+ 9 - 2
src/pages/knowledge/components/CompanyTab/components/ScrollListChat.tsx

@@ -24,9 +24,10 @@ import { useLoadMoreInfinite, createKey } from "@/utils/loadMoreInfinite";
 export interface Iprops {
   entId: string | number;
   assistantOnly?: boolean;
+  setTotalCount: (count: number) => void;
 }
 
-const Index = ({ entId, assistantOnly }: Iprops) => {
+const Index = ({ entId, assistantOnly, setTotalCount }: Iprops) => {
 
   const [scrollTop, setScrollTop] = useState(9999)
   const { whoami } = useUserStore();
@@ -35,7 +36,7 @@ const Index = ({ entId, assistantOnly }: Iprops) => {
     const res = await getEntKnowledgeStream({ startId: nextId, pageSize, entId });
     return res.data;
   };
-  const { list, loadMore, pageIndex, mutate } = useLoadMoreInfinite<TKnowledgeStreamResponseData[]>(
+  const { list, loadMore, pageIndex, mutate, data } = useLoadMoreInfinite<TKnowledgeStreamResponseData[]>(
     createKey(`getEntKnowledgeStream ${entId}`, 10, [entId]),
     fetcher);
 
@@ -62,6 +63,12 @@ const Index = ({ entId, assistantOnly }: Iprops) => {
       }
   }, [pageIndex]);
 
+  useEffect(() => {
+    if(data &&  pageIndex === 1) {
+      setTotalCount(data?.[0].totalCount || 0)
+    }
+  }, [data, pageIndex]);
+
   
 
   return (

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

@@ -14,15 +14,16 @@ const Index = () => {
   const [listStyle, setListStyle] = useState<TListStyle>("chat");
   const [ent, setEnt] = useState<TEntItem|null>(null)
   const [assistantOnly, setAssistantOnly] = useState(false);
+  const [totalCount, setTotalCount] = useState<number>(0);  
 
   const renderScrollList = () => {
     if (!ent?.entId) {
       return <></>;
     }
     if (listStyle === "chat") {
-      return <ScrollListChat assistantOnly entId={ent.entId} />;
+      return <ScrollListChat setTotalCount={setTotalCount}  assistantOnly entId={ent.entId} />;
     }
-    return <ScrollList entId={ent.entId} />;
+    return <ScrollList setTotalCount={setTotalCount} entId={ent.entId} />;
   };
 
   return (
@@ -31,7 +32,7 @@ const Index = () => {
 
       <StyleFilter checked={assistantOnly} setChecked={setAssistantOnly} listStyle={listStyle} setListStyle={setListStyle}>
         <View className="flex-1 text-12 leading-20 text-gray-45">
-            共 {ent?.knowledgeCnt ?? 0} 个文件
+            共 {totalCount ?? 0} 个文件
           </View>
       </StyleFilter>
       

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

@@ -24,9 +24,10 @@ import { useLoadMoreInfinite, createKey } from "@/utils/loadMoreInfinite";
 
 export interface IProps {
   types?: EKnowlegeTypes[],
+  setTotalCount: (count: number) => void;
 }
 
-const Index = ({types}: IProps) => {
+const Index = ({types, setTotalCount}: IProps) => {
   
   const [scrollTop, setScrollTop] = useState(9999)
 
@@ -34,7 +35,7 @@ const Index = ({types}: IProps) => {
     const res = await getKnowledgeList({ startId: nextId, pageSize, types });
     return res.data;
   };
-  const { list, loadMore, mutate } = useLoadMoreInfinite<TKnowledgeItem[]>( createKey('getKnowledgeList', 2, [types]), fetcher,);
+  const { list, loadMore, mutate, data, pageIndex } = useLoadMoreInfinite<TKnowledgeItem[]>( createKey('getKnowledgeList', 2, [types]), fetcher,);
 
   const onScrollToUpper = async () => {
     console.log('toUpper')
@@ -46,6 +47,11 @@ const Index = ({types}: IProps) => {
     mutate(undefined, { revalidate: true });
   })
 
+  useEffect(() => {
+    if(data &&  pageIndex === 1) {
+      setTotalCount(data?.[0].totalCount || 0)
+    }
+  }, [data, pageIndex]);
   
 
   const handleEdit = (item: TKnowledgeItem)=> {

+ 9 - 2
src/pages/knowledge/components/PersonalTab/components/ScrollListChat.tsx

@@ -26,9 +26,10 @@ import { DEFAULT_AGENT } from "@/config";
 
 interface IProps {
   assistantOnly?: boolean;
+  setTotalCount: (count: number) => void;
 }
 
-const Index = ({assistantOnly}: IProps) => {
+const Index = ({assistantOnly, setTotalCount}: IProps) => {
 
   const [scrollTop, setScrollTop] = useState(9999)
   
@@ -39,7 +40,7 @@ const Index = ({assistantOnly}: IProps) => {
   };
 
   
-  const { list, loadMore, pageIndex, mutate } = useLoadMoreInfinite<TKnowledgeStreamResponseData[]>(
+  const { list, loadMore, pageIndex, mutate ,data  } = useLoadMoreInfinite<TKnowledgeStreamResponseData[]>(
     createKey('getMyKnowledgeStream', 10),
     fetcher,
   );
@@ -84,6 +85,12 @@ const Index = ({assistantOnly}: IProps) => {
   useDidShow(()=> {
     mutate(undefined, { revalidate: true });
   })
+
+  useEffect(() => {
+    if(data &&  pageIndex === 1) {
+      setTotalCount(data?.[0].totalCount || 0)
+    }
+  }, [data, pageIndex]);
   
 
   return (

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

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

+ 6 - 1
src/pages/knowledge/components/view-style/ViewStyleListCorrection.tsx

@@ -12,6 +12,7 @@ import IconQ from "@/components/icon/IconQ";
 import CardEditable from "@/components/card/card-editable/index";
 
 import { useModalStore } from "@/store/modalStore";
+import { mutate } from "swr";
 
 export interface Iprops {
   viewStyle: 'list'|'card'
@@ -28,7 +29,7 @@ const Index = ({viewStyle, entId, setData}:Iprops) => {
   };
 
   
-  const { list, loadMore, pageIndex } = useLoadMoreInfinite<TCorrectionItem>(
+  const { list, loadMore, pageIndex, mutate } = useLoadMoreInfinite<TCorrectionItem[]>(
     createKey(`api/v1/my/correction/list${entId}`, 10, [entId]),
     fetcher);  
 
@@ -44,6 +45,10 @@ const Index = ({viewStyle, entId, setData}:Iprops) => {
     }
   }, [entId]);
 
+  useDidShow(()=> {
+    mutate(undefined, { revalidate: true });
+  })
+
 
   const handleEdit = (qaId: number | string) => {
     // Taro.navigateTo({

+ 1 - 0
src/utils/loadMoreInfinite.ts

@@ -63,6 +63,7 @@ export const useLoadMoreInfinite = <T>(getKey, fetcher, params = {}) => {
     setSize((size) => size + 1);
   }
   return {
+    data,
     list,
     pageIndex,
     isLoading,