Jelajahi Sumber

fix: 访问详情加载更多

王晓东 1 Minggu lalu
induk
melakukan
5998ae7bef

+ 9 - 2
project.private.config.json

@@ -9,12 +9,19 @@
     "miniprogram": {
       "list": [
         {
-          "name": "pages/dashboard/index",
-          "pathName": "pages/dashboard/index",
+          "name": "pages/knowledge/index",
+          "pathName": "pages/knowledge/index",
           "query": "",
           "scene": null,
           "launchMode": "default"
         },
+        {
+          "name": "pages/dashboard/index",
+          "pathName": "pages/dashboard/index",
+          "query": "",
+          "launchMode": "default",
+          "scene": null
+        },
         {
           "name": "pages/contact/index",
           "pathName": "pages/contact/index",

+ 1 - 2
src/components/DigitalCard/DigitalCardBasic.tsx

@@ -22,8 +22,7 @@ const DigitalCardBasic = ({
         </View>
         <View className="flex items-center gap-2">
           <View className="text-12 leading-20 truncate max-w-[188px]">
-            {entName}
-            {/* {entName}{certificated && <IconCertificateColor />} */}
+            {entName || ''} {certificated && <IconCertificateColor />}
           </View>
         </View>
       </View>

+ 5 - 3
src/components/WemetaSwitch/index.tsx

@@ -5,13 +5,15 @@ interface Props {
   onChange: (checked: boolean) => void;
 }
 const index = ({ checked = false, onChange }: Props) => {
-  const handleSwitchChange = () => {
+
+  const handleClick = (e:any) => {
+    e.stopPropagation()
     onChange(!checked);
-  };
+  }
   return (
     <View
       className={checked ? style.switchChecked : style.switch}
-      onClick={handleSwitchChange}
+      onClick={(e)=> handleClick(e)}
     ></View>
   );
 };

+ 2 - 2
src/components/slide-contact/index.wxss

@@ -5,13 +5,13 @@
 .wrap .content {
   position: relative;
   z-index: 1;
-  border-radius: 24rpx;
+  
   overflow: hidden;
 }
 
 .wrap .content.animate {
   transition: transform 0.3s;
-  background: #F6F8FB;
+  background:rgb(12, 65, 145);
 }
 
 .wrap .action-wrap {

+ 0 - 1
src/components/slide-delete/index.js

@@ -47,7 +47,6 @@ Component({
      * 处理touchstart事件
      */
     handleTouchStart(e) {
-      console.log(33334)
       // touch事件初始时,组件禁掉transition动画
       this.setData(
         {

+ 1 - 14
src/components/slide-delete/index.wxss

@@ -5,7 +5,6 @@
 .wrap .content {
   position: relative;
   z-index: 1;
-  border-radius: 24rpx;
   overflow: hidden;
 }
 
@@ -17,11 +16,10 @@
 .wrap .action-wrap {
   position: absolute;
   display: flex;
-  width: 240rpx;
+  width: 120rpx;
   top: 0;
   bottom: 0;
   right: 0;
-  border-radius: 0 24rpx 24rpx 0;
   overflow: hidden;
 }
 
@@ -37,17 +35,6 @@
 .wrap .delete {
   background: #FF8200;
 }
-.wrap .action.cancel {
-  display: flex;
-  flex-direction: column;
-  gap: 0;
-  width: 120rpx;
-  height: 100%;
-  justify-content: center;
-  align-items: center;
-  background: #FF4747;
-}
-
 .wrap .action text {
   font-size: 24rpx;
   color: #fff;

+ 1 - 2
src/pages/contact/components/contact-card/index.module.less

@@ -3,10 +3,9 @@
   padding: 16px;
   align-items: center;
   gap: 8px;
-  border-radius: 12px;
+  // border-radius: 12px;
   color: #262626;
   font-family: "PingFang SC";
-  background-color: white;
 }
 
 .avatar{

+ 3 - 2
src/pages/contact/components/contact-card/index.tsx

@@ -10,8 +10,9 @@ interface Props {
   deleteable?: boolean
   refresh: () => void
   fromContact?: boolean
+  className?: string
 }
-const Index = ({data, deleteable, refresh, fromContact}: Props)=> {
+const Index = ({data, deleteable, className, refresh, fromContact}: Props)=> {
   const handleClick = (data: TContactItem)=>{
     console.log(data, fromContact)
     Taro.navigateTo({
@@ -21,7 +22,7 @@ const Index = ({data, deleteable, refresh, fromContact}: Props)=> {
   
 
   return (
-    <View className={style.contactCard} onClick={()=>{handleClick(data)}}>
+    <View className={`${style.contactCard} ${className}`} onClick={()=>{handleClick(data)}}>
       <View className={style.avatar}>
         <AvatarMedia source={data.avatarUrl || ''} mode="aspectFill" className={style.avatar}></AvatarMedia>
       </View>

+ 1 - 1
src/pages/contact/index.config.ts

@@ -1,5 +1,5 @@
 export default definePageConfig({
-  navigationBarTitleText: '分类页',
+  navigationBarTitleText: '联系人',
   navigationStyle: 'custom',
   onReachBottomDistance: 20,
   usingComponents: {

+ 3 - 2
src/pages/contact/index.tsx

@@ -116,13 +116,14 @@ export default function Index() {
       pinned={item.isTop}
       onAction={handleHello}
     >
-    <View className={`rounded-12 overflow-hidden ${item.isTop ? "bg-[#EDF1FF]" : "bg-white"}`}>
+    <View className={``}>
         <ContactCard
           refresh={mutate}
           deleteable={true}
           key={item.contactId}
           data={item}
           fromContact
+          className={`${item.isTop ? "bg-[#EDF1FF]" : "bg-white"}`}
         ></ContactCard>
       </View>
     </slide-contact>
@@ -131,7 +132,7 @@ export default function Index() {
   const renderContent = () => {
     if (list?.length) {
       return list.map((item) => (
-        <View className="rounded-24 bg-white">
+        <View className={`rounded-12 overflow-hidden`}>
           {renderItem(item)}
         </View>
       ));

+ 17 - 21
src/pages/dashboard/components/VisitorList/index.tsx

@@ -7,34 +7,30 @@ import { getVisitorList } from "@/service/visitor";
 import { useLoadMoreInfinite, createKey } from "@/utils/loadMoreInfinite";
 import { useEffect } from "react";
 interface IProps {
-  agentId?: string | number;
+  agentId?: string;
+  list: TVisitorAgent[]
 }
 
-export default ({ agentId }: IProps) => {
+export default ({ agentId, list }: IProps) => {
 
-  const fetcher = async ([_url, {nextId, pageSize}, [agentId]]) => {
-    const res = await getVisitorList({ startId: nextId, pageSize, agentId });
-    return res.data;
-  };
-  const { list, loadMore, mutate } = useLoadMoreInfinite<TVisitorAgent[]>(
-    createKey(`getVisitorList${agentId}`, 20, [agentId]),
-    fetcher);
+  
 
-  useEffect(() => {
-    const handler = () => {
-      loadMore();
-    }
+  // useEffect(() => {
+  //   const handler = () => {
+  //     console.log('loadmore', )
+  //     loadMore();
+  //   }
     
-    eventBus.on(BUS_EVENTS.REACH_BOTTOM, handler)
+  //   eventBus.on(BUS_EVENTS.REACH_BOTTOM, handler)
     
-    return () => {
-      eventBus.off(BUS_EVENTS.REACH_BOTTOM, handler)
-    }
-  }, [])
+  //   return () => {
+  //     eventBus.off(BUS_EVENTS.REACH_BOTTOM, handler)
+  //   }
+  // }, [])
 
-  useDidShow(()=> {
-    mutate(undefined, {revalidate: true})
-  })
+  // useDidShow(()=> {
+  //   mutate(undefined, {revalidate: true})
+  // })
 
   
 

+ 21 - 3
src/pages/dashboard/index.tsx

@@ -11,7 +11,10 @@ import { useAgentStore } from "@/store/agentStore";
 import { getVisitorSummary, type TVisitorSummary } from '@/service/visitor'
 import { isSuccess } from "@/utils";
 import { TAgent } from "@/types/agent";
-import eventBus, {BUS_EVENTS} from '@/utils/EventBus'
+// import eventBus, {BUS_EVENTS} from '@/utils/EventBus'
+import { TVisitorAgent } from "@/types/visitor";
+import { getVisitorList } from "@/service/visitor";
+import { useLoadMoreInfinite, createKey } from "@/utils/loadMoreInfinite";
 
 export default () => {
   
@@ -22,6 +25,15 @@ export default () => {
   const [currentAgent, setCurrentAgent] = useState<TAgent|null>(null)
   const [summary, setSummary] = useState<TVisitorSummary>()
 
+  const fetcher = async ([_url, {nextId, pageSize}, [agentId]]) => {
+    console.log(nextId, agentId)
+    const res = await getVisitorList({ startId: nextId, pageSize, agentId});
+    return res.data;
+  };
+  const { list, loadMore, mutate } = useLoadMoreInfinite<TVisitorAgent[]>(
+    createKey(`getVisitorList ${currentAgent?.agentId}`, 20, [currentAgent?.agentId]),
+    fetcher);
+
 
   const fetchSummary = async () => {
     const response = await getVisitorSummary(currentAgent?.agentId)
@@ -44,14 +56,20 @@ export default () => {
     fetchInitData()
   })
 
+  
 
 
   if(!agents) {
     return <View>...</View>
   }
   useReachBottom(() => {
-    eventBus.trigger(BUS_EVENTS.REACH_BOTTOM)
+    loadMore()
+  })
+
+  useDidShow(()=> {
+    mutate(undefined, {revalidate: true})
   })
+
   const unprocessedDislikeCnt = summary?.unprocessedDislikeCnt ?? 0
 
   return (
@@ -92,7 +110,7 @@ export default () => {
           }} text="待处理差评" unitText="条" value={unprocessedDislikeCnt} arrow />
         </View>
 
-        <VisitorList agentId={currentAgent?.agentId}></VisitorList>
+        <VisitorList list={list} agentId={currentAgent?.agentId}></VisitorList>
         
         <AgentList show={show} setShow={setShow} currentAgent={currentAgent} setCurrentAgent={setCurrentAgent}></AgentList>
         

+ 1 - 1
src/pages/knowledge/components/CompanyTab/components/ScrollListChat.tsx

@@ -37,7 +37,7 @@ const Index = ({ entId, assistantOnly, setTotalCount }: Iprops) => {
     return res.data;
   };
   const { list, loadMore, pageIndex, mutate, data } = useLoadMoreInfinite<TKnowledgeStreamResponseData[]>(
-    createKey(`getEntKnowledgeStream ${entId}`, 10, [entId]),
+    createKey(`getEntKnowledgeStream ${entId}`, 20, [entId]),
     fetcher);
 
   const getFilterList = (list: TKnowledgeStreamResponseData[]) => {

+ 146 - 0
src/pages/knowledge/components/PersonalTab/components/ScrollList-slide-delete.tsx

@@ -0,0 +1,146 @@
+import { ScrollView, View, Image } from "@tarojs/components";
+
+import FigureList from "@/components/list/FigureList";
+import FigureListItem from "@/components/list/FigureListItem";
+import { useDidShow } from "@tarojs/taro";
+import { useEffect, useState } from "react";
+
+import RotateLoading from "@/components/rotate-loading";
+import Taro from "@tarojs/taro";
+
+import { EKnowlegeTypes } from "@/consts/enum";
+import KnowledgeIcon from "@/components/KnowledgeIcon";
+import EmptyData from "@/components/empty-data";
+
+import type { TKnowledgeItem } from "@/types/knowledge";
+
+import { deleteMyKnowledge, getKnowledgeList } from "@/service/knowledge";
+
+import { useLoadMoreInfinite, createKey } from "@/utils/loadMoreInfinite";
+import { isSuccess } from "@/utils";
+
+export interface IProps {
+  types?: EKnowlegeTypes[];
+  setTotalCount: (count: number) => void;
+}
+
+const Index = ({ types, setTotalCount }: IProps) => {
+  const fetcher = async ([_url, { nextId, pageSize }, [types]]) => {
+    const res = await getKnowledgeList({ startId: nextId, pageSize, types });
+    return res.data;
+  };
+  const { list, loadMore, mutate, data, pageIndex } = useLoadMoreInfinite<
+    TKnowledgeItem[]
+  >(createKey("getKnowledgeList", 2, [types]), fetcher);
+
+  const onScrollToLower = async () => {
+    loadMore();
+  };
+
+  useDidShow(() => {
+    mutate(undefined, { revalidate: true });
+  });
+
+  useEffect(() => {
+    if (data && pageIndex === 1) {
+      setTotalCount(data?.[0].totalCount || 0);
+    }
+  }, [data, pageIndex]);
+
+  const handleEdit = (item: TKnowledgeItem) => {
+    if (item.parseStatus !== "parsed") {
+      return;
+    }
+    Taro.navigateTo({
+      url: `/pages/knowledge-item/index?knowledgeId=${item.knowledgeId}`,
+    });
+  };
+
+  const handleDelete = async (id: string | number) => {
+    Taro.showModal({
+      content: "确认删除该知识?",
+      async success(result) {
+        if (result.confirm) {
+          const response = await deleteMyKnowledge(id);
+          if (isSuccess(response.status)) {
+            Taro.showToast({
+              title: "删除成功",
+              icon: "none",
+            });
+            mutate();
+          }
+        }
+      },
+    });
+  };
+
+  const handleHello = async (e: any) => {
+    const detail = e.detail as { type: string; id: string };
+    console.log(detail);
+    // 置顶与取消置顶
+    if (detail.type === "delete") {
+      handleDelete(detail.id);
+    }
+  };
+
+  const renderItem = (item: TKnowledgeItem) => {
+    // @ts-ignore
+    return (<slide-delete pid={item.knowledgeId} onAction={handleHello}>
+        <View className="px-16">
+        <FigureListItem
+          figure={() => <KnowledgeIcon data={item} />}
+          arrow={item.parseStatus === "parsed"}
+          onClick={() => handleEdit(item)}
+          rightRenderer={() => rightRenderer(item)}
+        >
+          <View className="flex flex-col flex-1 gap-2 w-full">
+            <View className="text-14 leading-22">{item.title}</View>
+            <View className="text-12 leading-20 text-gray-45">
+              {item.createTime} | {item.fileSize}
+            </View>
+          </View>
+        </FigureListItem>
+        </View>
+      </slide-delete>
+    );
+  };
+
+  const rightRenderer = (item: TKnowledgeItem) => {
+    if (!item.isParsing) {
+      return <></>;
+    }
+
+    return (
+      <View className="flex items-center gap-4">
+        <RotateLoading />
+        <View className="text-primary text-12">解析中</View>
+      </View>
+    );
+  };
+
+  return (
+    <ScrollView
+      scrollY
+      onScrollToLower={onScrollToLower}
+      style={{
+        flex: 1,
+        height: "100%", // 高度自适应
+      }}
+    >
+      {list.length <= 0 ? (
+        <View className="pt-46">
+          <EmptyData type={"plane"} />
+        </View>
+      ) : (
+        <></>
+      )}
+      <View className="rounded-8 flex flex-col gap-12 bg-white">
+        {list.map((item) => {
+          return renderItem(item);
+        })}
+      </View>
+    </ScrollView>
+  );
+};
+
+export default Index;

+ 56 - 69
src/pages/knowledge/components/PersonalTab/components/ScrollList.tsx

@@ -8,114 +8,75 @@ import { useEffect, useState } from "react";
 import RotateLoading from "@/components/rotate-loading";
 import Taro from "@tarojs/taro";
 
-
 import { EKnowlegeTypes } from "@/consts/enum";
 import KnowledgeIcon from "@/components/KnowledgeIcon";
 import EmptyData from "@/components/empty-data";
 
-
 import type { TKnowledgeItem } from "@/types/knowledge";
 
-import {
-  deleteMyKnowledge,
-  getKnowledgeList,
-} from "@/service/knowledge";
+import { deleteMyKnowledge, getKnowledgeList } from "@/service/knowledge";
 
 import { useLoadMoreInfinite, createKey } from "@/utils/loadMoreInfinite";
 import { isSuccess } from "@/utils";
 
 export interface IProps {
-  types?: EKnowlegeTypes[],
+  types?: EKnowlegeTypes[];
   setTotalCount: (count: number) => void;
 }
 
-const Index = ({types, setTotalCount}: IProps) => {
-
-  const fetcher = async ([_url, {nextId, pageSize}, [types]]) => {
+const Index = ({ types, setTotalCount }: IProps) => {
+  const fetcher = async ([_url, { nextId, pageSize }, [types]]) => {
     const res = await getKnowledgeList({ startId: nextId, pageSize, types });
     return res.data;
   };
-  const { list, loadMore, mutate, data, pageIndex } = useLoadMoreInfinite<TKnowledgeItem[]>( createKey('getKnowledgeList', 2, [types]), fetcher,);
+  const { list, loadMore, mutate, data, pageIndex } = useLoadMoreInfinite<
+    TKnowledgeItem[]
+  >(createKey("getKnowledgeList", 20, [types]), fetcher);
 
   const onScrollToLower = async () => {
-    loadMore()
-  }
-
+    loadMore();
+  };
 
-  useDidShow(()=> {
+  useDidShow(() => {
     mutate(undefined, { revalidate: true });
-  })
+  });
 
   useEffect(() => {
-    if(data &&  pageIndex === 1) {
-      setTotalCount(data?.[0].totalCount || 0)
+    if (data && pageIndex === 1) {
+      setTotalCount(data?.[0].totalCount || 0);
     }
   }, [data, pageIndex]);
-  
 
-  const handleEdit = (item: TKnowledgeItem)=> {
-    if(item.parseStatus !== 'parsed'){
-      return ;
+  const handleEdit = (item: TKnowledgeItem) => {
+    if (item.parseStatus !== "parsed") {
+      return;
     }
     Taro.navigateTo({
-      url: `/pages/knowledge-item/index?knowledgeId=${item.knowledgeId}`
-    })
-  }
+      url: `/pages/knowledge-item/index?knowledgeId=${item.knowledgeId}`,
+    });
+  };
 
-  const handleDelete = async (id: string|number)=> {
+  const handleLongPress = async (id: string | number) => {
     Taro.showModal({
       content: "确认删除该知识?",
       async success(result) {
         if (result.confirm) {
           const response = await deleteMyKnowledge(id);
-          if(isSuccess(response.status)) {
+          if (isSuccess(response.status)) {
             Taro.showToast({
               title: "删除成功",
-              icon: 'none',
+              icon: "none",
             });
             mutate();
           }
         }
       },
     });
-  }
-
-  const handleHello = async (e: any) => {
-    const detail = e.detail as { type: string; id: string };
-    console.log(detail);
-    // 置顶与取消置顶
-    if (detail.type === "delete") {
-      handleDelete(detail.id);
-    }
   };
 
-  const renderItem = (item: TKnowledgeItem)=> {
-      // @ts-ignore
-    return <slide-delete
-        pid={item.knowledgeId}
-        onAction={handleHello}
-      >
-        111
-        <FigureListItem
-              figure={()=> <KnowledgeIcon data={item}/>}
-              underline
-              arrow={item.parseStatus === 'parsed'}
-              onClick={()=> handleEdit(item)}
-              rightRenderer={()=> rightRenderer(item)}
-            >
-              <View className="flex flex-col flex-1 gap-2 w-full">
-                <View className="text-14 leading-22">{item.title}</View>
-                <View className="text-12 leading-20 text-gray-45">
-                {item.createTime} | {item.fileSize}
-                </View>
-              </View>
-            </FigureListItem>
-      </slide-delete>
-    }
-
   const rightRenderer = (item: TKnowledgeItem) => {
-    if(!item.isParsing){
-      return <></>
+    if (!item.isParsing) {
+      return <></>;
     }
 
     return (
@@ -135,12 +96,38 @@ const Index = ({types, setTotalCount}: IProps) => {
         height: "100%", // 高度自适应
       }}
     >
-      {list.length<=0 ? <View className="pt-46"><EmptyData type={'plane'}/></View> : <></>}
-      <FigureList>
-      {list.map(item => {
-        return renderItem(item)
-      })}
-      </FigureList>
+      <View className="px-16">
+        {list.length <= 0 ? (
+          <View className="pt-46">
+            <EmptyData type={"plane"} />
+          </View>
+        ) : (
+          <></>
+        )}
+        <FigureList>
+          {list.map((item) => {
+            return (
+              <FigureListItem
+                figure={() => <KnowledgeIcon data={item} />}
+                underline
+                arrow={item.parseStatus === "parsed"}
+                onClick={() => handleEdit(item)}
+                rightRenderer={() => rightRenderer(item)}
+              >
+                <View
+                  className="flex flex-col flex-1 gap-2 w-full"
+                  onLongPress={() => handleLongPress(item.knowledgeId)}
+                >
+                  <View className="text-14 leading-22">{item.title}</View>
+                  <View className="text-12 leading-20 text-gray-45">
+                    {item.createTime} | {item.fileSize}
+                  </View>
+                </View>
+              </FigureListItem>
+            );
+          })}
+        </FigureList>
+      </View>
     </ScrollView>
   );
 };

+ 1 - 1
src/pages/knowledge/components/PersonalTab/components/ScrollListChat.tsx

@@ -123,7 +123,7 @@ const Index = ({assistantOnly, setTotalCount}: IProps) => {
         height: "100%", // 高度自适应
       }}
     >
-      <View className="flex flex-col gap-20 pb-80">
+      <View className="flex flex-col gap-20 pb-80 px-16">
         {/* 欢迎语 */}
         {(reversedList.length <= 0) && <MessageRobotRich data={DEFAULT_AGENT}><WelcomeCard /></MessageRobotRich>}
 

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

@@ -29,7 +29,7 @@ const Index = () => {
           </View>
       </StyleFilter>
 
-      <View className="px-16  h-full">
+      <View className="h-full">
         {listStyle === "chat" ? <ScrollListChat setTotalCount={setTotalCount} assistantOnly={assistantOnly} /> : <ScrollList setTotalCount={setTotalCount} />}
       </View>
 

+ 1 - 0
src/pages/knowledge/components/StyleFilter/index.tsx

@@ -24,6 +24,7 @@ const Index = ({listStyle = "chat", setListStyle, checked, setChecked,  onlyAssi
 
   const handleListStyleChange = (listStyle: TListStyle) => {
     setListStyle(listStyle);
+    setShowPopup(false)
   };
 
   return (

+ 3 - 2
src/utils/loadMoreInfinite.ts

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