Prechádzať zdrojové kódy

fix: 资料页显示默认形象

王晓东 3 mesiacov pred
rodič
commit
134e009b15

+ 6 - 6
project.private.config.json

@@ -9,16 +9,16 @@
     "miniprogram": {
       "list": [
         {
-          "name": "pages/component-library/index",
-          "pathName": "pages/component-library/index",
-          "query": "",
+          "name": "pages/profile/index",
+          "pathName": "pages/profile/index",
+          "query": "agentId=p_2e73c9d7efaYfDo2-agent_1034",
           "scene": null,
           "launchMode": "default"
         },
         {
-          "name": "pages/profile/index",
-          "pathName": "pages/profile/index",
-          "query": "agentId=p_cb626719d6aYig5s-agent_408",
+          "name": "pages/component-library/index",
+          "pathName": "pages/component-library/index",
+          "query": "",
           "launchMode": "default",
           "scene": null
         },

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

@@ -11,7 +11,6 @@ import { formatMessageItem } from "@/utils/messageUtils";
 import {
   TRobotMessage,
   TMessage,
-  EContentType,
   TAnyMessage,
 } from "@/types/bot";
 

+ 24 - 6
src/pages/profile/index.tsx

@@ -12,10 +12,12 @@ import IconHomeOutline from "@/components/icon/IconHomeOutline";
 import AgentActionBar from "@/components/AgentPage/components/AgentActionBar";
 import { useAgentStore } from "@/store/agentStore";
 import style from "./index.module.less";
+import {  DEFAULT_AVATAR_BG } from '@/config'
 import { sceneUnzip } from "@/service/wechat";
 import { postLog } from "./profile";
 import { useIsLogin } from "@/xiaolanbenlib/hooks/data/useAuth";
 import useSWR from "swr";
+import { TAgentDetail } from "@/types/agent";
 
 export default function Profile() {
   const { agentProfile, fetchAgentProfile, clearProfileAgent } = useAgentStore();
@@ -24,8 +26,15 @@ export default function Profile() {
 
   const [agentId, setCurrentAgentId]  = useState<null|string>(null)
   const [shareKey, setShareKey] = useState<null|string>(null)
-
+  const [bg, setBg] = useState('')
+  const [isDefaultBg, setIsDefaultBg] = useState(false)
   console.log(agentProfile, agentProfile?.status)
+
+  const setPageBg = (_agent:TAgentDetail)=> {
+    setBg(_agent?.avatarUrl ?? DEFAULT_AVATAR_BG)
+    setIsDefaultBg(!_agent?.avatarUrl)
+  }
+
   // 定时 30 秒请求一次 log 接口
   useSWR( (agentId && (agentProfile?.status === 'normal')) ? ['/blue-aiagent/api/v1/agent/visitor/log', {
     agentId: agentId, 
@@ -56,12 +65,14 @@ export default function Profile() {
         };
         if (originalScene.agentId) {
           console.log("originalScene:", originalScene);
-          fetchAgentProfile(
+          const _agent = await fetchAgentProfile(
             originalScene.agentId,
             originalScene.shareKey ?? ""
           );
+          _agent && setPageBg(_agent)
           setCurrentAgentId(originalScene.agentId)
           setShareKey(originalScene.shareKey ?? "")
+          
           // postLog(originalScene.agentId, originalScene.shareKey ?? "");
         }
       } catch (e) {
@@ -74,6 +85,13 @@ export default function Profile() {
   };
   console.log(params.scene, "场景值");
 
+
+  const fetchPageData = async (params:any)=> {
+    const _agent = await fetchAgentProfile(params.agentId, params.shareKey ?? "");
+    _agent && setPageBg(_agent)
+    setCurrentAgentId(params.agentId)
+    setShareKey(params.shareKey ?? "")
+  }
   
   useEffect(() => {
     // 通过小程序码识别打开的页面
@@ -91,12 +109,12 @@ export default function Profile() {
     }
   }, []);
 
+
+
   // 正常分享出来的页面
   useEffect(() => {
     if (params.agentId) {
-      fetchAgentProfile(params.agentId, params.shareKey ?? "");
-      setCurrentAgentId(params.agentId)
-      setShareKey(params.shareKey ?? "")
+      fetchPageData(params)
       // isLogin && postLog(params.agentId, params.shareKey);
     }
   }, [params.agentId]);
@@ -170,7 +188,7 @@ export default function Profile() {
   }
 
   return (
-    <PageCustom styleBg={agentProfile?.avatarUrl}>
+    <PageCustom styleBg={bg}>
       <View className="w-full">
         <NavBarNormal blur scrollFadeIn scrollFadeInDelta={240}  leftColumn={renderNavBarLeft}></NavBarNormal>
         {agentProfile && <View className="blur-rounded-container">