|
|
@@ -1,6 +1,6 @@
|
|
|
import PageCustom from "@/components/page-custom/index";
|
|
|
import { View, Image } from "@tarojs/components";
|
|
|
-import { useEffect, useRef, useState } from "react";
|
|
|
+import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
|
import ComponentList from "@/components/component-list";
|
|
|
|
|
|
import NavBarNormal from "@/components/NavBarNormal/index";
|
|
|
@@ -10,63 +10,73 @@ import { isSuccess } from "@/utils";
|
|
|
import IconArrowLeft from "@/components/icon/icon-arrow-left";
|
|
|
import IconHomeOutline from "@/components/icon/IconHomeOutline";
|
|
|
import AgentActionBar from "@/components/AgentPage/components/AgentActionBar";
|
|
|
-import {
|
|
|
- getAgent,
|
|
|
-} from "@/service/agent";
|
|
|
+import { getAgent } from "@/service/agent";
|
|
|
import style from "./index.module.less";
|
|
|
-import { DEFAULT_AVATAR_BG } from '@/config'
|
|
|
+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 type { TAgentDetail } from "@/types/agent";
|
|
|
-import { useAppStore } from "@/store/appStore";
|
|
|
+import { useAppStore, useAppStoreActions } from "@/store/appStore";
|
|
|
|
|
|
export default function Profile() {
|
|
|
- const [agentProfile, setAgentProfile] = useState<TAgentDetail|null>(null)
|
|
|
+ const [agentProfile, setAgentProfile] = useState<TAgentDetail | null>(null);
|
|
|
// const { agentProfile, clearProfileAgent } = useAgentStore();
|
|
|
const params = useRouter().params;
|
|
|
const isLogin = useIsLogin();
|
|
|
- const windowHeight = useAppStore((state)=> state.windowHeight);
|
|
|
- const headerHeight = useAppStore((state)=> state.headerHeight);
|
|
|
+ const { syncWindowHeight } = useAppStoreActions();
|
|
|
|
|
|
- const components = agentProfile?.components ?? []
|
|
|
+ const windowHeight = useAppStore((state) => state.windowHeight);
|
|
|
+ const headerHeight = useAppStore((state) => state.headerHeight);
|
|
|
|
|
|
- const [agentId, setCurrentAgentId] = useState<null|string>(null)
|
|
|
- const [shareKey, setShareKey] = useState<null|string>(null)
|
|
|
- const [bg, setBg] = useState('')
|
|
|
+ const components = agentProfile?.components ?? [];
|
|
|
+
|
|
|
+ const [agentId, setCurrentAgentId] = useState<null | string>(null);
|
|
|
+ const [shareKey, setShareKey] = useState<null | string>(null);
|
|
|
+ const [bg, setBg] = useState("");
|
|
|
const [marginTop, setMarginTop] = useState(0);
|
|
|
|
|
|
- console.log(agentProfile, agentProfile?.status)
|
|
|
+ // console.log(agentProfile, agentProfile?.status);
|
|
|
+
|
|
|
+ useLayoutEffect(() => {
|
|
|
+ syncWindowHeight();
|
|
|
+ }, [agentId]);
|
|
|
|
|
|
- const fetchAgentProfile = async (agentId: string, shareKey?:string) => {
|
|
|
- if(shareKey){
|
|
|
- shareKey = decodeURIComponent(shareKey)
|
|
|
+ const fetchAgentProfile = async (agentId: string, shareKey?: string) => {
|
|
|
+ if (shareKey) {
|
|
|
+ shareKey = decodeURIComponent(shareKey);
|
|
|
}
|
|
|
const response = await getAgent(agentId, shareKey);
|
|
|
- const result = isSuccess(response.status)
|
|
|
- const agent = response.data
|
|
|
+ const result = isSuccess(response.status);
|
|
|
+ const agent = response.data;
|
|
|
if (result && agent) {
|
|
|
- agent.components = (agent.components ?? []).filter(item => item.enabled)
|
|
|
- setAgentProfile(agent)
|
|
|
+ agent.components = (agent.components ?? []).filter(
|
|
|
+ (item) => item.enabled
|
|
|
+ );
|
|
|
+ setAgentProfile(agent);
|
|
|
}
|
|
|
- return agent
|
|
|
- }
|
|
|
+ return agent;
|
|
|
+ };
|
|
|
|
|
|
- const setPageBg = (_agent:TAgentDetail)=> {
|
|
|
- setBg(_agent?.avatarUrl ?? DEFAULT_AVATAR_BG)
|
|
|
- }
|
|
|
+ const setPageBg = (_agent: TAgentDetail) => {
|
|
|
+ setBg(_agent?.avatarUrl ?? DEFAULT_AVATAR_BG);
|
|
|
+ };
|
|
|
|
|
|
// 定时 30 秒请求一次 log 接口
|
|
|
- useSWR( (agentId && (agentProfile?.status === 'normal')) ? ['/blue-aiagent/api/v1/agent/visitor/log', {
|
|
|
- agentId: agentId,
|
|
|
- shareKey: shareKey,
|
|
|
- }] : false
|
|
|
- ,
|
|
|
+ useSWR(
|
|
|
+ agentId && agentProfile?.status === "normal"
|
|
|
+ ? [
|
|
|
+ "/blue-aiagent/api/v1/agent/visitor/log",
|
|
|
+ {
|
|
|
+ agentId: agentId,
|
|
|
+ shareKey: shareKey,
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ : false,
|
|
|
([_url, data]) => {
|
|
|
-
|
|
|
- if(isLogin){
|
|
|
- postLog(data.agentId, data.shareKey ?? '')
|
|
|
+ if (isLogin) {
|
|
|
+ postLog(data.agentId, data.shareKey ?? "");
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
@@ -91,9 +101,9 @@ export default function Profile() {
|
|
|
originalScene.agentId,
|
|
|
originalScene.shareKey ?? ""
|
|
|
);
|
|
|
- _agent && setPageBg(_agent)
|
|
|
- setCurrentAgentId(originalScene.agentId)
|
|
|
- setShareKey(originalScene.shareKey ?? "")
|
|
|
+ _agent && setPageBg(_agent);
|
|
|
+ setCurrentAgentId(originalScene.agentId);
|
|
|
+ setShareKey(originalScene.shareKey ?? "");
|
|
|
|
|
|
// postLog(originalScene.agentId, originalScene.shareKey ?? "");
|
|
|
}
|
|
|
@@ -107,13 +117,15 @@ 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 ?? "")
|
|
|
- }
|
|
|
+ const fetchPageData = async (params: any) => {
|
|
|
+ const _agent = await fetchAgentProfile(
|
|
|
+ params.agentId,
|
|
|
+ params.shareKey ?? ""
|
|
|
+ );
|
|
|
+ _agent && setPageBg(_agent);
|
|
|
+ setCurrentAgentId(params.agentId);
|
|
|
+ setShareKey(params.shareKey ?? "");
|
|
|
+ };
|
|
|
|
|
|
useEffect(() => {
|
|
|
// 通过小程序码识别打开的页面
|
|
|
@@ -124,43 +136,44 @@ export default function Profile() {
|
|
|
decodeSceneValue(scene);
|
|
|
}
|
|
|
|
|
|
- return ()=> {
|
|
|
- setCurrentAgentId(null)
|
|
|
- setShareKey(null)
|
|
|
- }
|
|
|
+ return () => {
|
|
|
+ setCurrentAgentId(null);
|
|
|
+ setShareKey(null);
|
|
|
+ };
|
|
|
}, []);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// 正常分享出来的页面
|
|
|
useEffect(() => {
|
|
|
if (params.agentId) {
|
|
|
- fetchPageData(params)
|
|
|
+ fetchPageData(params);
|
|
|
}
|
|
|
}, [params.agentId]);
|
|
|
|
|
|
-
|
|
|
- useEffect(()=> {
|
|
|
+ useEffect(() => {
|
|
|
const query = Taro.createSelectorQuery();
|
|
|
// 获取滚动容器高度
|
|
|
query
|
|
|
- .select('#BlurRoundedContainer')
|
|
|
+ .select("#BlurRoundedContainer")
|
|
|
.boundingClientRect((rect: any) => {
|
|
|
if (rect) {
|
|
|
- console.log('ScrollView height:', rect.height, windowHeight, headerHeight)
|
|
|
- if(rect.height + 296 < windowHeight - headerHeight){
|
|
|
+ console.log(
|
|
|
+ "ScrollView height:",
|
|
|
+ rect.height,
|
|
|
+ windowHeight,
|
|
|
+ headerHeight
|
|
|
+ );
|
|
|
+ if (rect.height + 296 < windowHeight - headerHeight) {
|
|
|
setMarginTop(windowHeight - headerHeight - rect.height);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
setMarginTop(296);
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
.exec();
|
|
|
- }, [components])
|
|
|
+ }, [components]);
|
|
|
|
|
|
const renderNavBarLeft = () => {
|
|
|
const pages = getCurrentPages();
|
|
|
- console.log(pages, "当前页面");
|
|
|
// 有后退页,则不显示 home 按钮
|
|
|
|
|
|
if (pages.length > 1 && pages[0].route !== "pages/profile/index") {
|
|
|
@@ -193,35 +206,49 @@ export default function Profile() {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
- const renderButton = ()=> {
|
|
|
+ const renderButton = () => {
|
|
|
// 如果智能体交接了,则可以跳去新智能体
|
|
|
- if(agentProfile?.toAgentId){
|
|
|
- return <View className="button-rounded-big" onClick={()=> {
|
|
|
- Taro.redirectTo({
|
|
|
- url: `/pages/profile/index?agentId=${agentProfile?.toAgentId}`
|
|
|
- });
|
|
|
- }}>前往访问</View>
|
|
|
+ if (agentProfile?.toAgentId) {
|
|
|
+ return (
|
|
|
+ <View
|
|
|
+ className="button-rounded-big"
|
|
|
+ onClick={() => {
|
|
|
+ Taro.redirectTo({
|
|
|
+ url: `/pages/profile/index?agentId=${agentProfile?.toAgentId}`,
|
|
|
+ });
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 前往访问
|
|
|
+ </View>
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
// 下线了
|
|
|
- return <View className="button-rounded-big" onClick={()=> {
|
|
|
- Taro.navigateBack()
|
|
|
- }}>知道了</View>
|
|
|
- }
|
|
|
+ return (
|
|
|
+ <View
|
|
|
+ className="button-rounded-big"
|
|
|
+ onClick={() => {
|
|
|
+ Taro.navigateBack();
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 知道了
|
|
|
+ </View>
|
|
|
+ );
|
|
|
+ };
|
|
|
|
|
|
- // 如果智能体被删除或其它异常情况
|
|
|
- if (agentProfile?.status === "deleted" || agentProfile?.deletedTip?.length) {
|
|
|
+ // 如果智能体被删除或其它异常情况
|
|
|
+ if (agentProfile?.status === "deleted" || agentProfile?.deletedTip?.length) {
|
|
|
return (
|
|
|
<PageCustom fullPage>
|
|
|
<View className="w-full h-full">
|
|
|
<NavBarNormal leftColumn={renderNavBarLeft}></NavBarNormal>
|
|
|
- <View className="w-full h-full flex flex-col items-center justify-center">
|
|
|
- <View className="max-w-[280px]">
|
|
|
- <View className="mb-12">{agentProfile?.deletedTip}</View>
|
|
|
- {renderButton()}
|
|
|
+ <View className="w-full h-full flex flex-col items-center justify-center">
|
|
|
+ <View className="max-w-[280px]">
|
|
|
+ <View className="mb-12">{agentProfile?.deletedTip}</View>
|
|
|
+ {renderButton()}
|
|
|
+ </View>
|
|
|
</View>
|
|
|
</View>
|
|
|
- </View>
|
|
|
</PageCustom>
|
|
|
);
|
|
|
}
|
|
|
@@ -229,15 +256,24 @@ export default function Profile() {
|
|
|
return (
|
|
|
<PageCustom styleBg={bg}>
|
|
|
<View className="w-full">
|
|
|
- <NavBarNormal blur scrollFadeIn scrollFadeInDelta={240} leftColumn={renderNavBarLeft}></NavBarNormal>
|
|
|
- {agentProfile && <View className="blur-rounded-container" id="BlurRoundedContainer" style={{marginTop: `${marginTop}px`}}>
|
|
|
- <AgentActionBar isVisitor agent={agentProfile}></AgentActionBar>
|
|
|
- <View className="flex flex-col w-full p-16 gap-12">
|
|
|
- <ComponentList
|
|
|
- components={components}
|
|
|
- ></ComponentList>
|
|
|
+ <NavBarNormal
|
|
|
+ blur
|
|
|
+ scrollFadeIn
|
|
|
+ scrollFadeInDelta={240}
|
|
|
+ leftColumn={renderNavBarLeft}
|
|
|
+ ></NavBarNormal>
|
|
|
+ {agentProfile && (
|
|
|
+ <View
|
|
|
+ className="blur-rounded-container"
|
|
|
+ id="BlurRoundedContainer"
|
|
|
+ style={{ marginTop: `${marginTop}px` }}
|
|
|
+ >
|
|
|
+ <AgentActionBar isVisitor agent={agentProfile}></AgentActionBar>
|
|
|
+ <View className="flex flex-col w-full p-16 gap-12">
|
|
|
+ <ComponentList components={components}></ComponentList>
|
|
|
+ </View>
|
|
|
</View>
|
|
|
- </View>}
|
|
|
+ )}
|
|
|
</View>
|
|
|
</PageCustom>
|
|
|
);
|