Przeglądaj źródła

fix: 访问页独立

王晓东 1 miesiąc temu
rodzic
commit
deab3adfed

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

@@ -8,12 +8,10 @@
 }
 
 .avatar{
-  display: flex;
   width: 48px;
   height: 48px;
-  justify-content: center;
-  align-items: center;
   border-radius: 100%;
+  flex-shrink: 0;
   overflow: hidden;
 }
 .infoColumn{

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

@@ -1,17 +1,20 @@
 import PageCustom from "@/components/page-custom/index";
-import { View,Image } from "@tarojs/components";
 import { useEffect, useState } from "react";
 import DefaultAgent from '@/components/AgentPage'
 import InitView from './components/InitView'
 import { TAgent } from "@/types/agent";
-import NavBarNormal from "@/components/nav-bar-normal/index";
-import LogoImage from '@/images/logo.png'
+import { useDidShow } from "@tarojs/taro";
+import { useAgentStore } from "@/store/agentStore";
 
 export default function Index() {
-
+  const { fetchAgent } = useAgentStore()
   const [defaultAgent, setDefaultAgent] = useState<TAgent|null>(null)
 
-
+  useDidShow(()=> {
+    if(defaultAgent?.agentId){
+      fetchAgent(defaultAgent?.agentId)
+    }
+  })
   
   return (
     <PageCustom>

+ 7 - 7
src/pages/profile/index.tsx

@@ -16,7 +16,7 @@ import { sceneUnzip } from "@/service/wechat";
 import { postLog } from "./profile";
 
 export default function Profile() {
-  const { agent, fetchAgent } = useAgentStore();
+  const { agentProfile, fetchAgentProfile } = useAgentStore();
   const params = useRouter().params;
 
   // 解码
@@ -30,7 +30,7 @@ export default function Profile() {
         };
         if (originalScene.agentId) {
           console.log(originalScene,111)
-          fetchAgent(originalScene.agentId);
+          fetchAgentProfile(originalScene.agentId);
           postLog(originalScene.agentId, originalScene.shareKey ?? "");
         }
       } catch (e) {
@@ -55,7 +55,7 @@ export default function Profile() {
   // 正常分享出来的页面
   useEffect(() => {
     if (params.agentId) {
-      fetchAgent(params.agentId);
+      fetchAgentProfile(params.agentId);
       postLog(params.agentId, params.shareKey);
     }
   }, [params.agentId]);
@@ -64,7 +64,7 @@ export default function Profile() {
     const pages = getCurrentPages();
     return (
       <View className={style.navButtons}>
-        {pages.length > 2 && (
+        {pages.length > 1 && (
           <>
             <View
               className="flex-center"
@@ -99,12 +99,12 @@ export default function Profile() {
           showBgColor
           leftColumn={renderNavBarLeft}
         ></NavBarNormal>
-        {agent && (
+        {agentProfile && (
           <>
-            <SummaryBar isVisitor agent={agent}></SummaryBar>
+            <SummaryBar isVisitor agent={agentProfile}></SummaryBar>
             <View className="flex flex-col w-full p-16 gap-12">
               <ComponentList
-                components={agent.components ?? []}
+                components={agentProfile.components ?? []}
               ></ComponentList>
             </View>
           </>

+ 8 - 2
src/pages/voice/components/MyVoiceList/index.tsx

@@ -14,6 +14,7 @@ import { EVoiceStatus, TVoiceItem } from "@/types/voice";
 import { TAgentDetail } from "@/types/agent";
 
 import { getVoiceStatus } from "@/service/voice";
+import ThinkingAnimation from "@/components/think-animation";
 
 interface Props {
   agent: TAgentDetail | null;
@@ -34,6 +35,11 @@ export default ({ onPlay, agent }: Props) => {
   const { getVoices } = useVoiceStore();
   const myVoices = useVoiceStore((state) => state.myVoices);
 
+  // {
+  //   message: '生成中',
+  //   taskId: 'abc',
+  //   status: 'processing'
+  // }
   const [cloning, setCloning] = useState<TTask>();
 
   const handleSelect = (item: TVoiceItem) => {
@@ -111,7 +117,7 @@ export default ({ onPlay, agent }: Props) => {
 
     return <></>;
   };
-
+  
   // 克隆状态栏
   const renderCloneStatus = (item: TTask) => {
     if (item.status === "success") {
@@ -121,7 +127,7 @@ export default ({ onPlay, agent }: Props) => {
     }
     if (item.status === "processing") {
       return (
-        <View className={`text-12 leading-20 text-primary`}>{item.message}</View>
+        <View className={`text-12 leading-20 text-primary`}>{item.message}<ThinkingAnimation /></View>
       );
     }
 

+ 29 - 1
src/store/agentStore.ts

@@ -19,17 +19,20 @@ import {
   TEditAgentCharacter,
   TComponentItem,
 } from "@/types/agent";
-import { isSuccess, pickNonEmpty } from "@/utils";
+import { isSuccess } from "@/utils";
 import Taro from "@tarojs/taro";
 
 export interface AgentStoreState {
   agents: TAgent[];
   agent: TAgentDetail | null;
+  agentProfile: TAgentDetail | null;
   agentContactCard: TAgentContactCard | null;
+  agentProfileContactCard: TAgentContactCard | null;
   agentCharacter: TEditAgentCharacter | null;
   ents: {entName: string, entId: string|number}[]
   fetchAgents: () => Promise<TAgent[]>;
   fetchAgent: (agentId: string) => Promise<TAgentDetail | null>;
+  fetchAgentProfile: (agentId: string) => Promise<TAgentDetail | null>;
   createAgent: () => Promise<TAgentDetail | null>;
   setDefaultAgent: (agentId: string) => Promise<TAgentDetail | null>;
   editAgentCharacter: (
@@ -50,7 +53,9 @@ export interface AgentStoreState {
 export const useAgentStore = create<AgentStoreState>((set, get) => ({
   agents: [],
   agent: null,
+  agentProfile: null,
   agentContactCard: null,
+  agentProfileContactCard: null,
   agentCharacter: null,
   ents: [],
   fetchAgents: async () => {
@@ -100,6 +105,29 @@ export const useAgentStore = create<AgentStoreState>((set, get) => ({
     }
     return null;
   },
+  fetchAgentProfile: async (agentId: string, shareKey?:string) => {
+    // 如果自己的智能体列表中有 对应的 agentId,则请求自己的 agent, 否则请求无需登录的 getAgent 接口
+    const response = await _getAgent(agentId, shareKey);
+    const result = isSuccess(response.status)
+    if (result && response.data) {
+      const agent = response.data;
+      set({
+        agentProfile: response.data,
+        agentProfileContactCard: {
+          address: agent.address ?? "",
+          email: agent.email ?? "",
+          entName: agent.entName ?? "",
+          mobile: agent.mobile ?? "",
+          name: agent.name ?? "",
+          position: agent.position ?? "",
+          qrCodeUrl: agent.qrCodeUrl ?? "",
+        },
+      });
+
+      return response.data;
+    }
+    return null;
+  },
   setDefaultAgent: async (agentId: string) => {
     const response = await _setDefaultAgent(agentId);
     const result = isSuccess(response.status)