Commit 0ace2d9a by Liu

feat:工单参数逻辑

parent 2514136e
...@@ -23,6 +23,7 @@ export const ChatAnswerOperate: React.FC<ChatAnswerOperateProps> = ({ answer }) ...@@ -23,6 +23,7 @@ export const ChatAnswerOperate: React.FC<ChatAnswerOperateProps> = ({ answer })
// 读取路由参数 from // 读取路由参数 from
const from = searchParams.get('from') const from = searchParams.get('from')
const fromValues = searchParams.getAll('from')
// 兜底读取缓存的 tacticsMeta(会话从 tactics 打开的元信息) // 兜底读取缓存的 tacticsMeta(会话从 tactics 打开的元信息)
const tacticsMetaFromStorage = useMemo(() => { const tacticsMetaFromStorage = useMemo(() => {
...@@ -50,8 +51,11 @@ export const ChatAnswerOperate: React.FC<ChatAnswerOperateProps> = ({ answer }) ...@@ -50,8 +51,11 @@ export const ChatAnswerOperate: React.FC<ChatAnswerOperateProps> = ({ answer })
} }
}, []) }, [])
// 规则:当 sessionStorage 中存在 userMeta 或 tacticsMeta 时,或路由参数 from=tactics 时,统一隐藏收藏按钮 // 检查路由参数中是否有 from=order
const shouldHideCollect = !!userMetaFromStorage || !!tacticsMetaFromStorage || from === 'tactics' const hasOrderFromRoute = fromValues.includes('order')
// 规则:当 sessionStorage 中存在 userMeta 或 tacticsMeta 时,或路由参数 from=tactics 或 from=order 时,统一隐藏收藏按钮
const shouldHideCollect = !!userMetaFromStorage || !!tacticsMetaFromStorage || from === 'tactics' || hasOrderFromRoute
const [isCollect, setIsCollect] = useState(answer.collectionFlag) const [isCollect, setIsCollect] = useState(answer.collectionFlag)
const [isLike, setIsLike] = useState(answer.feedbackStatus === '01') const [isLike, setIsLike] = useState(answer.feedbackStatus === '01')
......
...@@ -23,13 +23,23 @@ export const ChatAnswerRecommend: React.FC<ChatAnswerRecommendProps> = ({ answer ...@@ -23,13 +23,23 @@ export const ChatAnswerRecommend: React.FC<ChatAnswerRecommendProps> = ({ answer
// 仅在 from=tactics 场景下,按照要求补充 busiType / recordType 参数 // 仅在 from=tactics 场景下,按照要求补充 busiType / recordType 参数
const from = searchParams.get('from') const from = searchParams.get('from')
const place = searchParams.get('place') const place = searchParams.get('place')
const fromValues = searchParams.getAll('from')
const shouldAttachBusiParams = from === 'tactics' const shouldAttachBusiParams = from === 'tactics'
const busiType = shouldAttachBusiParams ? '02' : undefined const busiType = shouldAttachBusiParams ? '02' : undefined
let recordType: string | undefined let recordType: string | undefined
if (shouldAttachBusiParams) { if (shouldAttachBusiParams) {
// from=tactics 且 from=order → recordType=A11
// from=tactics 且 place=user → recordType=A03 // from=tactics 且 place=user → recordType=A03
// from=tactics 且 place!=user/无 → recordType=A01 // from=tactics 且 place!=user/无 → recordType=A01
recordType = place === 'user' ? 'A03' : 'A01' if (fromValues.includes('order')) {
recordType = 'A11'
}
else if (place === 'user') {
recordType = 'A03'
}
else {
recordType = 'A01'
}
} }
try { try {
const res = await fetchQueryRecommendQuestion( const res = await fetchQueryRecommendQuestion(
......
...@@ -59,23 +59,40 @@ export const TacticsHome: React.FC = () => { ...@@ -59,23 +59,40 @@ export const TacticsHome: React.FC = () => {
} }
}, [searchParams]) }, [searchParams])
// 读取 from=order 时的 orderMeta 参数(直接从 query 读取,不再使用 sessionStorage)
const orderMeta = useMemo(() => {
const fromValues = searchParams.getAll('from')
if (!fromValues.includes('order')) {
return undefined
}
return {
workOrderIds: searchParams.get('workOrderIds') || undefined,
}
}, [searchParams])
// 仅用于创建会话的额外参数(对应 create_conversation) // 仅用于创建会话的额外参数(对应 create_conversation)
const getConversationExtra = useCallback(() => { const getConversationExtra = useCallback(() => {
if (orderMeta) {
return {
busiType: '02',
// from=order 场景下,不传 busiId
} as Partial<any>
}
if (userMeta?.place === 'user') { if (userMeta?.place === 'user') {
return { return {
busiType: '02', busiType: '02',
// place=user 场景下,业务方要求 busiId 取 numberType // place=user 场景下,业务方要求 busiId 取 numberType
busiId: userMeta.numberType, busiId: userMeta.numberType,
} } as Partial<any>
} }
if (tacticsMeta) { if (tacticsMeta) {
return { return {
busiType: '02', busiType: '02',
busiId: tacticsMeta.taskId, busiId: tacticsMeta.taskId,
} } as Partial<any>
} }
return {} return {} as Partial<any>
}, [tacticsMeta, userMeta]) }, [orderMeta, tacticsMeta, userMeta])
const initTacticsConversation = () => { const initTacticsConversation = () => {
const fromCollect = location.state?.fromCollect const fromCollect = location.state?.fromCollect
...@@ -94,7 +111,14 @@ export const TacticsHome: React.FC = () => { ...@@ -94,7 +111,14 @@ export const TacticsHome: React.FC = () => {
const from = searchParams.get('from') const from = searchParams.get('from')
const place = searchParams.get('place') const place = searchParams.get('place')
if (conversationId && from === 'tactics') { if (conversationId && from === 'tactics') {
const storageKey = place === 'user' ? 'tactics_user_conversation_id' : 'tactics_conversation_id' const fromValues = searchParams.getAll('from')
let storageKey = 'tactics_conversation_id'
if (fromValues.includes('order')) {
storageKey = 'tactics_order_conversation_id'
}
else if (place === 'user') {
storageKey = 'tactics_user_conversation_id'
}
window.localStorage.setItem(storageKey, conversationId) window.localStorage.setItem(storageKey, conversationId)
} }
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
......
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