Commit 2b1e4e52 by Liu

feat: 用户分析传参

parent 3895ddce
......@@ -60,6 +60,37 @@ export const TacticsHome: React.FC = () => {
}, [])
const tacticsMeta = useMemo(() => tacticsMetaFromSearch || tacticsMetaFromStorage, [tacticsMetaFromSearch, tacticsMetaFromStorage])
// 读取 place=user 时的 userMeta 参数
const userMetaFromSearch = useMemo(() => {
const place = searchParams.get('place')
if (place !== 'user') {
return undefined
}
return {
place,
cstId: searchParams.get('cstId') || undefined,
userId: searchParams.get('userId') || undefined,
numberType: searchParams.get('numberType') || undefined,
}
}, [searchParams])
const userMetaFromStorage = useMemo(() => {
const raw = sessionStorage.getItem('userMeta')
if (!raw) {
return undefined
}
try {
const parsed = JSON.parse(raw)
if (parsed?.place === 'user') {
return parsed
}
}
catch {
// ignore
}
return undefined
}, [])
const userMeta = useMemo(() => userMetaFromSearch || userMetaFromStorage, [userMetaFromSearch, userMetaFromStorage])
// 同步到 sessionStorage,便于跳转后读取;仅在有 meta 时写入,避免覆盖重定向缓存
useEffect(() => {
if (tacticsMeta) {
......@@ -67,6 +98,13 @@ export const TacticsHome: React.FC = () => {
}
}, [tacticsMeta])
// 同步 userMeta 到 sessionStorage
useEffect(() => {
if (userMeta) {
sessionStorage.setItem('userMeta', JSON.stringify(userMeta))
}
}, [userMeta])
const initTacticsConversation = () => {
const fromCollect = location.state?.fromCollect
// 只有在访问问答首页时才创建新对话
......@@ -93,6 +131,7 @@ export const TacticsHome: React.FC = () => {
state: {
shouldSendQuestion: question,
tacticsMeta,
userMeta,
},
})
return
......@@ -105,7 +144,7 @@ export const TacticsHome: React.FC = () => {
shouldSendQuestion: question,
}),
)
}, [dispatch, currentConversationId, navigate, tacticsMeta])
}, [dispatch, currentConversationId, navigate, tacticsMeta, userMeta])
// 监听导航到新对话
useEffect(() => {
......@@ -115,12 +154,13 @@ export const TacticsHome: React.FC = () => {
state: {
shouldSendQuestion,
tacticsMeta,
userMeta,
},
replace: true,
})
dispatch(clearTacticsNavigationFlag())
}
}, [shouldNavigateToNewConversation, currentConversationId, shouldSendQuestion, navigate, dispatch, tacticsMeta])
}, [shouldNavigateToNewConversation, currentConversationId, shouldSendQuestion, navigate, dispatch, tacticsMeta, userMeta])
const login = useCallback(async () => {
if (hasFetched.current) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment