Przeglądaj źródła

fix: 修复聊天时停止按钮误删聊天记录

王晓东 2 tygodni temu
rodzic
commit
87ec2ef1d5

+ 59 - 52
src/components/AgentPage/components/AgentSwap/index.tsx

@@ -10,21 +10,26 @@ import { TAgent } from "@/types/agent";
 import Taro from "@tarojs/taro";
 import ContactIcon from "@/components/ContactIcon";
 import { useEffect } from "react";
-import EmptyData, { EmptyDataSubInfo, EmptyDataTitle } from "@/components/EmptyData";
+import EmptyData, {
+  EmptyDataSubInfo,
+  EmptyDataTitle,
+} from "@/components/EmptyData";
 interface IProps {
   show: boolean;
   setShow: (show: boolean) => void;
 }
 export default ({ show, setShow }: IProps) => {
   const agents = useAgentStore((state) => state.agents);
-  const { setDefaultAgent, fetchAgents, clearEditAgent, fetchDefaultNewAgentInfo } = useAgentStoreActions();
+  const {
+    setDefaultAgent,
+    fetchAgents,
+    clearEditAgent,
+    fetchDefaultNewAgentInfo,
+  } = useAgentStoreActions();
   let loading = false;
   const personalAgents = agents.filter((item) => !item.isEnt);
   const entAgents = agents.filter((item) => item.isEnt);
 
-
-
-
   const handleClick = async (item: TAgent) => {
     if (loading) {
       return;
@@ -38,37 +43,37 @@ export default ({ show, setShow }: IProps) => {
     }
     loading = false;
     Taro.hideLoading();
-    setShow(false)
-
+    setShow(false);
   };
 
-  const handleCreate = async ()=> {
-    Taro.showTabBar().catch(()=> {});
+  const handleCreate = async () => {
+    Taro.showTabBar().catch(() => {});
     if (loading) {
       return;
     }
     loading = true;
-    try{
-      clearEditAgent()
+    try {
+      clearEditAgent();
       await fetchDefaultNewAgentInfo();
-      Taro.navigateTo({ url: `/pages/agent/index`});
+      Taro.navigateTo({ url: `/pages/agent/index` });
       loading = false;
-      setShow(false)
-    }catch(e:any){
+      setShow(false);
+    } catch (e: any) {
       loading = false;
     }
-  }
+  };
 
-  useEffect(()=> {
-    fetchAgents()
-  }, [show])
+  useEffect(() => {
+    fetchAgents();
+  }, [show]);
 
   const renderCard = (item: TAgent, isEnt: boolean) => {
     return (
-      <View className={item.isDefault ? style.cardActive : style.card} onClick={() => handleClick(item)}>
-        <View
-          className="flex items-start mb-12"
-        >
+      <View
+        className={item.isDefault ? style.cardActive : style.card}
+        onClick={() => handleClick(item)}
+      >
+        <View className="flex items-start mb-12">
           <View className="flex flex-col flex-1 truncate">
             <View className="flex items-end gap-8 text-gray-5 truncate">
               <View className="text-20 font-medium leading-28 text-black truncate">
@@ -97,8 +102,8 @@ export default ({ show, setShow }: IProps) => {
   };
 
   const renderAgents = () => {
-    if(agents.length <= 0){
-      return <EmptyData type='search' className="mt-44"></EmptyData>
+    if (agents.length <= 0) {
+      return <EmptyData type="search" className="mt-44"></EmptyData>;
     }
     return agents.map((item) => {
       return renderCard(item, !!item.entId);
@@ -106,15 +111,14 @@ export default ({ show, setShow }: IProps) => {
   };
 
   const renderPersonalAgents = () => {
-    if(personalAgents.length <= 0){
-      return <EmptyData type='search' className="mt-44"></EmptyData>
+    if (personalAgents.length <= 0) {
+      return <EmptyData type="search" className="mt-44"></EmptyData>;
     }
     return personalAgents.map((item) => {
       return renderCard(item, false);
     });
   };
 
-
   const renderEntAgents = () => {
     if (entAgents.length) {
       return entAgents.map((item) => {
@@ -123,20 +127,37 @@ export default ({ show, setShow }: IProps) => {
     }
     return (
       <View className={`${style.card} h-full`}>
-        <EmptyData type='box'>
+        <EmptyData type="box">
           <EmptyDataTitle>你还没有加入任何企业</EmptyDataTitle>
-          <EmptyDataSubInfo>访问公司统一知识内容,提升回复效率与专业度</EmptyDataSubInfo>
+          <EmptyDataSubInfo>
+            访问公司统一知识内容,提升回复效率与专业度
+          </EmptyDataSubInfo>
           <View
-              className="button-rounded button-primary-light button-border-primary button-inline-flex mt-20"
-              onClick={() => Taro.navigateTo({ url: "/pages/contact-us/index" })}
-            >
-              联系我们
+            className="button-rounded button-primary-light button-border-primary button-inline-flex mt-20"
+            onClick={() => Taro.navigateTo({ url: "/pages/contact-us/index" })}
+          >
+            联系我们
           </View>
         </EmptyData>
       </View>
     );
   };
 
+  const renderCreateNewButton = () => {
+    return (
+
+      <View
+        className="absolute left-0 right-0 bottom-0 z-10 bg-white pt-14"
+        onClick={handleCreate}
+      >
+        <View className="button-rounded button-primary-light gap-8 mb-15">
+          <IconPlusBlue />
+          <View>创建新智能体</View>
+        </View>
+      </View>
+    );
+  };
+
   const tabList = [
     {
       key: "all",
@@ -145,19 +166,12 @@ export default ({ show, setShow }: IProps) => {
         <>
           <View className="pt-12 relative">
             <View className={style.tabContainer}>
-              <View className="pb-66">
-                {renderAgents()}
-              </View>
-            </View>
-            <View className="absolute left-0 right-0 bottom-0 z-10 bg-white pt-14" onClick={handleCreate}>
-              <View className="button-rounded button-primary-light gap-8 mb-15">
-                <IconPlusBlue />
-                <View>创建新的智能体</View>
-              </View>
+              <View className="pb-66">{renderAgents()}</View>
             </View>
+            {renderCreateNewButton()}
           </View>
         </>
-      )
+      ),
     },
     {
       key: "personal",
@@ -166,16 +180,9 @@ export default ({ show, setShow }: IProps) => {
         <>
           <View className="pt-12 relative">
             <View className={style.tabContainer}>
-              <View className="pb-66">
-                {renderPersonalAgents()}
-              </View>
-            </View>
-            <View className="absolute left-0 right-0 bottom-0 z-10 bg-white pt-14" onClick={handleCreate}>
-              <View className="button-rounded button-primary-light gap-8 mb-15">
-                <IconPlusBlue />
-                <View>创建新的智能体</View>
-              </View>
+              <View className="pb-66">{renderPersonalAgents()}</View>
             </View>
+            {renderCreateNewButton()}
           </View>
         </>
       ),

+ 1 - 2
src/pages/agent-avatar-confirm/index.tsx

@@ -20,8 +20,7 @@ export default function Index({ avatarItem }: IProps) {
   const [enabledChatBg, setEnabledChatBg] = useState(agentEdit?.enabledChatBg ?? false)
 
   const handleConfirm = async (edit: TAvatarItem & { enabledChatBg: boolean }) => {
-    console.log('confirm')
-    console.log(edit, 2222)
+    console.log('confirm', edit)
     if (edit.avatarLogo && edit.avatarUrl) {
       updateEditAgent({...edit})
       // 如果是编辑,直接编辑形象成功

+ 1 - 1
src/pages/agent/components/AgentSetting/components/AgentSettingList/index.tsx

@@ -84,7 +84,7 @@ export default forwardRef(function Index(props, ref) {
         aiType="personality"
         defaultAiTips={defalutPolishPersonality}
         onPolishStateChange={handlePolishStateChange}
-        prefix={() => <View>人设</View>}
+        prefix={() => <View>人设 <Text className="text-red leading-22 text-14">*</Text></View>}
         placeholder="示例:你是一名汽车销售人员,拥有专业的汽车相关知识,善于耐心的解答客户提出的每一个问题,并会主动邀请客户上门试驾。"
         value={getDisplayValue('personality')}
         cursorSpacing={40}

+ 5 - 8
src/pages/agent/hooks/useConfirms.tsx

@@ -9,6 +9,7 @@ export const useConfirms = () => {
       showModal({
         content: <View className="text-black font-pingfangSCMedium font-medium text-14 leading-22">确定放弃创建智能体?</View>,
         confirmText: "我再想想",
+        cancelText: "放弃",
         onConfirm() {
           Taro.showTabBar().catch(()=> {});
           resolve(true)
@@ -45,15 +46,11 @@ export const useConfirms = () => {
       showModal({
         content: <View className="text-black font-pingfangSCMedium font-medium text-14 leading-22">在进行设置前需要先创建智能体</View>,
         confirmText: "创建",
-        cancelText: "不创建",
+        showCancelButton: false,
         onConfirm() {
           Taro.showTabBar().catch(()=> {});
           resolve(true)
         },
-        onCancel() {
-          Taro.showTabBar().catch(()=> {});
-          resolve(false)
-        },
       })
     })
   }
@@ -81,12 +78,12 @@ export const useConfirms = () => {
 
   const confirmPersonalityAndGreeting = async (personality?: string, greeting?: string):Promise<boolean> => {
     const personalityText =  (!personality || personality?.length <= 0)  ? '人设': ''
-    const greetingText =  (!greeting || greeting?.length <= 0)  ? '开场白': ''
+    // const greetingText =  (!greeting || greeting?.length <= 0)  ? '开场白': ''
     return await new Promise((resolve)=> {
       showModal({
-        content: <View className="text-black font-pingfangSCMedium font-medium text-14 leading-22">还没有设置{`${personalityText} ${greetingText}`}</View>,
+        content: <View className="text-black font-pingfangSCMedium font-medium text-14 leading-22">还没有设置{`${personalityText}`}</View>,
         confirmText: "自动生成",
-        cancelText: "暂不生成",
+        cancelText: "手动编辑",
         onConfirm() {
           Taro.showTabBar().catch(()=> {});
           resolve(true)

+ 66 - 46
src/pages/agent/index.tsx

@@ -14,6 +14,7 @@ import { useAppStore } from "@/store/appStore";
 import style from './index.module.less'
 import {restrictedPage} from '@/utils'
 import { useConfirms } from './hooks/useConfirms'
+import componentList from "@/components/component-list";
 
 export default function Index() {
   restrictedPage()
@@ -26,29 +27,41 @@ export default function Index() {
   const { fetchAgent, saveAgent, createAgent, updateEditAgent, fetchDefaultNewAgentInfo } = useAgentStoreActions();
   const { fetchMyEntList } = useUserStore();
   const { setComponentList } = useComponentStore();
+  const components = useComponentStore((state)=> state.components);
   const { confirmNavBack, confirmCreateAgent, confirmEditWebsite, confirmPersonalityAndGreeting, confirmSaveAvatar } = useConfirms();
   const { fetchAgents } = useAgentStoreActions();
 
   const [tabIndex, setTabIndex] = useState<'agent'|'website'>('agent');
 
-  // 润色方法引用
+  // 润色方法引用,层级太深后期是否考虑 provider 方式
   const agentSettingRef = useRef<{ polishAllTexts: () => Promise<void> }>(null);
 
+  const tabList = [
+    {
+      key: "agent",
+      label: "智能体",
+    },
+    {
+      key: "website",
+      label: "微官网",
+    },
+  ];
 
-
+  // tab 切换
   const handleTabIndexChange = async (index: 'agent' | 'website') => {
     // 如果要编辑微官网组件且是新建智能体,则提醒用户是否先创建智能体,只有创建智能体后才能编辑微官网
     if(index === 'website' && !agentEdit?.agentId){
       const isConfirm = await confirmCreateAgent()
-      if(isConfirm){
-        await createAgent()
-        setTabIndex(index)
-      }
+      // if(isConfirm){
+      //   await createAgent()
+      //   setTabIndex(index)
+      // }
       return
     }
     setTabIndex(index);
   };
 
+  // 获取数据
   const fetchData = async (agentId: string) => {
     const result = await fetchAgent(agentId);
     if (result) {
@@ -60,65 +73,72 @@ export default function Index() {
     fetchMyEntList()
   };
 
-  const tabList = [
-    {
-      key: "agent",
-      label: "智能体",
-    },
-    {
-      key: "website",
-      label: "微官网",
-    },
-  ];
 
 
-  const handleSave  = async () => {
-
-    if(!agentId && !agentEdit?.agentId){
-      if(!agentEdit?.avatarUrl){
-        const result  = await confirmSaveAvatar()
-        if(result){
-          return;
-        }
-      }
-      if(!agentEdit?.personality || !agentEdit?.greeting){
-        const result  = await confirmPersonalityAndGreeting(agentEdit?.personality, agentEdit?.greeting)
-        if(result){
-          if (agentSettingRef.current) {
-            if(agentEdit?.name && agentEdit?.name.length >= 2){
-              await agentSettingRef.current.polishAllTexts();
-            }
+  // 弹窗拦截判断
+  const checkHold = async () => {
+    if(!agentEdit?.personality){
+      const result  = await confirmPersonalityAndGreeting(agentEdit?.personality, agentEdit?.greeting)
+      if(result){
+        if (agentSettingRef.current) {
+          if(agentEdit?.name && agentEdit?.name.length >= 2){
+            await agentSettingRef.current.polishAllTexts();
           }
-
-        }else{
-          return;
         }
       }
-      if(!agentEdit?.voiceId){
-        console.log('创建智能体时请选择声音')
-        return
+      // 如果两个都没填,都不允许保存与创建
+      return true
+    }
+
+    if(!agentEdit?.avatarUrl){
+      const result  = await confirmSaveAvatar()
+      if(result){
+        return true;
       }
+    }
+
+    if(!agentEdit?.voiceId){
+      console.log('创建智能体时请选择声音')
+    }
+  }
+
+  // 保存智能体成功后,如果组件列表为空,则提示是否编辑组件
+  const afterSave = async () => {
+    if(components.length > 0){
+      Taro.navigateBack()
+      return
+    }
+    const goEditWebsite = await confirmEditWebsite()
+    if(goEditWebsite){
+      setTabIndex('website')
+    }else{
+      Taro.navigateBack()
+    }
+  }
+  // 保存|创建智能体
+  const handleSave  = async () => {
+    const isHold = await checkHold()
+    if(isHold){
+      return
+    }
+    if(!agentId && !agentEdit?.agentId){
       const res = await createAgent()
       if(res){
-        const goEditWebsite = await confirmEditWebsite()
-        if(goEditWebsite){
-          setTabIndex('website')
-        }else{
-          Taro.navigateBack()
-        }
+        afterSave()
       }
       return
     }
     const res = await saveAgent()
     if(res){
       Taro.showToast({title: '保存成功',icon: 'success'})
+      afterSave()
     }
   }
-
+  // 返回上一页
   const handleNavBack = async (): Promise<boolean | void> => {
 
     // 创建 智能体没有名字时拦截弹窗
-    if(!agentEdit?.agentId && !agentEdit?.name){
+    if(!agentEdit?.agentId){
       const result = await confirmNavBack()
       return !result
     }

+ 11 - 8
src/pages/chat/components/PersonalCard/index.tsx

@@ -1,5 +1,5 @@
 import { useState } from 'react'
-import Taro from '@tarojs/taro'
+import Taro, { useRouter } from '@tarojs/taro'
 import { Image, View } from '@tarojs/components'
 import IconCertificateColor from "@/components/icon/icon-certificate-color";
 import { TAgentDetail } from '@/types/agent';
@@ -22,7 +22,8 @@ interface IProps {
   onVisibleChange: (visible: boolean) => void
 }
 export default ({haveBg, agent, contextMenuVisible, onClear, onVisibleChange}:IProps) => {
-
+  const router = useRouter();
+  const { isVisitor } = router.params;
   /**
    * 之前个人卡片信息有两种样式,现在统一为一种
    */
@@ -97,12 +98,14 @@ export default ({haveBg, agent, contextMenuVisible, onClear, onVisibleChange}:IP
                   </View>
                   <View className='flex-1'>清除对话</View>
                 </View>
-                <View className='h-1' style={{backgroundColor: 'rgba(17,17,17,.15)', width: '100%'}}></View>
-                <View className='flex items-center gap-4' onClick={handleVoiceChoose}>
-                  <View className='w-16 h-16'><IconMicOutline/></View>
-                  <View className='flex-1'>音色选择</View>
-                  <View className='w-16 h-16'><IconArrowRightGray/></View>
-                </View>
+                {(isVisitor === 'false') && <>
+                  <View className='h-1' style={{backgroundColor: 'rgba(17,17,17,.15)', width: '100%'}}></View>
+                    <View className='flex items-center gap-4' onClick={handleVoiceChoose}>
+                      <View className='w-16 h-16'><IconMicOutline/></View>
+                      <View className='flex-1'>音色选择</View>
+                      <View className='w-16 h-16'><IconArrowRightGray/></View>
+                  </View>
+                </>}
               </View>
             </View>}
           </View>

+ 1 - 1
src/pages/chat/index.tsx

@@ -143,7 +143,7 @@ export default function Index() {
       onClick={handlePageClick}
     >
       <NavBarNormal blur leftColumn={renderNavLeft}>
-        {/* <>{`${scrollTop}`}--</> */}
+        {/* <>{`${isNewChat ? 'isnew': 'notnew'}`}--</> */}
       </NavBarNormal>
       <View
         className="flex flex-col w-full h-full relative z-10 flex-1"

+ 8 - 8
src/pages/personal/index.tsx

@@ -26,11 +26,11 @@ export default function Index() {
   const {fetchtMyInfo} = useUserStore()
 
   const isLogin = useIsLogin()
-  
+
 
   const [showPopup, setShowPopup] = useState(false)
   const [showSaveToDesktopTip, setSaveToDesktopTip] = useState(false)
-  
+
 
 
   const handleClick = () => {
@@ -38,7 +38,7 @@ export default function Index() {
       setShowPopup(true)
     }
   }
-  
+
   useEffect(()=>{
     fetchtMyInfo()
   }, [])
@@ -51,15 +51,15 @@ export default function Index() {
     }
   };
 
-  
+
 
   return (
     <PageCustom onClick={()=> {
       setSaveToDesktopTip(false)
     }} >
-      <NavBarNormal leftColumn={Logo} scrollFadeIn></NavBarNormal>
+      {/* <NavBarNormal leftColumn={<></>)} scrollFadeIn></NavBarNormal> */}
       <SaveToDesktopTip show={showSaveToDesktopTip}></SaveToDesktopTip>
-      
+
       <View className="w-full px-16 py-24 flex flex-col gap-16 h-full" >
         <View className="flex items-center w-full gap-12 mb-16">
           <View className="w-60 h-60">
@@ -82,7 +82,7 @@ export default function Index() {
             }}
           ></Input> */}
         </View>
-        
+
         <CardList>
           <CardListItem
             className="pl-16"
@@ -110,7 +110,7 @@ export default function Index() {
           >
             <View className="py-18 label-text">隐私设置</View>
           </CardListItem>
-          
+
           <CardListItem
             className="pl-16"
             arrow

+ 2 - 1
src/store/textChatStore.ts

@@ -233,7 +233,8 @@ export const useTextChat = create<TextChat>((set, get) => ({
       // 如果对话框是空的,则删除
       const filtered = state.list.filter((message) => {
         const isEmptyContent = message.content.length <= 0
-        return (message.msgUk !== msgUk && isEmptyContent)
+        console.log(isEmptyContent, message.msgUk, msgUk)
+        return (message.msgUk !== msgUk)
       });
       return { list: filtered, scrollTop: state.scrollTop + SCROLL_STEP }; // 返回新的状态
     });