|
@@ -1,6 +1,6 @@
|
|
|
import PageCustom from "@/components/page-custom/index";
|
|
|
import { View, Image } from "@tarojs/components";
|
|
|
-import { useEffect, useState } from "react";
|
|
|
+import { useEffect, useRef, useState } from "react";
|
|
|
import ComponentList from "@/components/component-list";
|
|
|
|
|
|
import NavBarNormal from "@/components/NavBarNormal/index";
|
|
@@ -15,12 +15,36 @@ import style from "./index.module.less";
|
|
|
import { sceneUnzip } from "@/service/wechat";
|
|
|
import { postLog } from "./profile";
|
|
|
import { useIsLogin } from "@/xiaolanbenlib/hooks/data/useAuth";
|
|
|
+import useSWR from "swr";
|
|
|
|
|
|
export default function Profile() {
|
|
|
- const { agentProfile, fetchAgentProfile, createAgent } = useAgentStore();
|
|
|
+ const { agentProfile, fetchAgentProfile, clearProfileAgent } = useAgentStore();
|
|
|
const params = useRouter().params;
|
|
|
const isLogin = useIsLogin();
|
|
|
|
|
|
+ const [agentId, setCurrentAgentId] = useState<null|string>(null)
|
|
|
+ const [shareKey, setShareKey] = useState<null|string>(null)
|
|
|
+
|
|
|
+ console.log(agentProfile, agentProfile?.status)
|
|
|
+ // 定时 30 秒请求一次 log 接口
|
|
|
+ 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 ?? '')
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ refreshInterval: 30000,
|
|
|
+ revalidateOnFocus: false,
|
|
|
+ shouldRetryOnError: false,
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
// 解码
|
|
|
const decodeSceneValue = async (sceneValue: string) => {
|
|
|
const response = await sceneUnzip(sceneValue);
|
|
@@ -36,7 +60,9 @@ export default function Profile() {
|
|
|
originalScene.agentId,
|
|
|
originalScene.shareKey ?? ""
|
|
|
);
|
|
|
- postLog(originalScene.agentId, originalScene.shareKey ?? "");
|
|
|
+ setCurrentAgentId(originalScene.agentId)
|
|
|
+ setShareKey(originalScene.shareKey ?? "")
|
|
|
+ // postLog(originalScene.agentId, originalScene.shareKey ?? "");
|
|
|
}
|
|
|
} catch (e) {
|
|
|
Taro.showToast({
|
|
@@ -47,21 +73,31 @@ export default function Profile() {
|
|
|
}
|
|
|
};
|
|
|
console.log(params.scene, "场景值");
|
|
|
- // 通过小程序码识别打开的页面
|
|
|
+
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
+ // 通过小程序码识别打开的页面
|
|
|
const scene = decodeURIComponent(params.scene ?? "");
|
|
|
if (scene.length <= 32 && scene.length > 0) {
|
|
|
// 有值,且小于 32 位,说明需要解码
|
|
|
// 判断是否需要解压 shareKey
|
|
|
decodeSceneValue(scene);
|
|
|
}
|
|
|
+
|
|
|
+ return ()=> {
|
|
|
+ setCurrentAgentId(null)
|
|
|
+ setShareKey(null)
|
|
|
+ clearProfileAgent()
|
|
|
+ }
|
|
|
}, []);
|
|
|
|
|
|
// 正常分享出来的页面
|
|
|
useEffect(() => {
|
|
|
if (params.agentId) {
|
|
|
fetchAgentProfile(params.agentId, params.shareKey ?? "");
|
|
|
- isLogin && postLog(params.agentId, params.shareKey);
|
|
|
+ setCurrentAgentId(params.agentId)
|
|
|
+ setShareKey(params.shareKey ?? "")
|
|
|
+ // isLogin && postLog(params.agentId, params.shareKey);
|
|
|
}
|
|
|
}, [params.agentId]);
|
|
|
|
|
@@ -98,50 +134,6 @@ export default function Profile() {
|
|
|
</View>
|
|
|
</View>
|
|
|
);
|
|
|
- // return (
|
|
|
- // <View className={style.navButtons}>
|
|
|
- // {pages.length > 1 && (
|
|
|
- // <>
|
|
|
- // <View
|
|
|
- // className="flex-center"
|
|
|
- // onClick={() => {
|
|
|
- // Taro.navigateBack();
|
|
|
- // }}
|
|
|
- // >
|
|
|
- // <IconArrowLeft></IconArrowLeft>
|
|
|
- // </View>
|
|
|
- // <View className={style.navGapLine}></View>
|
|
|
- // </>
|
|
|
- // )}
|
|
|
-
|
|
|
- // <View
|
|
|
- // className="flex-center"
|
|
|
- // onClick={() => {
|
|
|
- // Taro.switchTab({
|
|
|
- // url: "/pages/index/index",
|
|
|
- // });
|
|
|
- // }}
|
|
|
- // >
|
|
|
- // <IconHomeOutline></IconHomeOutline>
|
|
|
- // </View>
|
|
|
- // </View>
|
|
|
- // );
|
|
|
- };
|
|
|
-
|
|
|
- const handleCreate = async () => {
|
|
|
- try {
|
|
|
- const agentDetail = await createAgent();
|
|
|
- if (agentDetail) {
|
|
|
- if (agentDetail) {
|
|
|
- Taro.navigateTo({
|
|
|
- url: `/pages/agent/index?agentId=${agentDetail.agentId}`,
|
|
|
- });
|
|
|
- }
|
|
|
- // Taro.navigateTo({
|
|
|
- // url: `/pages/agent/index?agentId=${agentDetail.agentId}`
|
|
|
- // })
|
|
|
- }
|
|
|
- } catch (e) {}
|
|
|
};
|
|
|
|
|
|
const renderButton = ()=> {
|