Commit 67778be6 by Liu

fix:还原点赞点踩复制操作部分!

parent 92f7d450
import { Avatar, Button } from '@heroui/react' import { Avatar, Button } from '@heroui/react'
import { useEffect, useMemo, useState } from 'react' import { useEffect, useState } from 'react'
import { ChatAnswerShower } from './ChatAnswerShower' import { ChatAnswerShower } from './ChatAnswerShower'
import { ChatAnswerParser } from './ChatAnswerParser' import { ChatAnswerParser } from './ChatAnswerParser'
import { ChatAnswerRecommend } from './ChatAnswerRecommend' import { ChatAnswerRecommend } from './ChatAnswerRecommend'
...@@ -49,34 +49,11 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex, ...@@ -49,34 +49,11 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex,
setInnerRecord(record) setInnerRecord(record)
}, [record]) }, [record])
// 检查 sessionStorage 中是否存在 from=tactics
const hasFromTactics = useMemo(() => {
try {
const raw = sessionStorage.getItem('tacticsMeta')
if (!raw) {
return false
}
const parsed = JSON.parse(raw)
return parsed?.from === 'tactics'
}
catch {
return false
}
}, [])
/**
* 当当前 AI 记录没有对应的问题文本时(例如策略页进入会话后的自动分析、
* 点击「重新分析」触发的自动问题),需要隐藏点赞 / 点踩 / 复制按钮。
* 对于正常问答(有用户问题)则保持原有行为。
* 当 recordType 为 A01 且 sessionStorage 中存在 from=tactics 时,也需要隐藏点赞 / 点踩 / 复制按钮。
*/
const hideOperateForRecord = !innerRecord.question
return ( return (
<div> <div>
{innerRecord.answerList.map((item, index) => { {innerRecord.answerList.map((item, index) => {
// 检查当前项的 recordType,如果是 A01 且 sessionStorage 中存在 from=tactics 则隐藏操作按钮 // 当前默认始终展示点赞 / 点踩 / 复制等操作区(是否展示由下层基于卡片类型自行决定)
const shouldHideOperate = hideOperateForRecord || (hasFromTactics && item.recordType === 'A01') const shouldHideOperate = false
return ( return (
index === showIndex && ( index === showIndex && (
<div className="chatItemBotContainer w-full" key={`${item.recordId}-${index}`}> <div className="chatItemBotContainer w-full" key={`${item.recordId}-${index}`}>
......
...@@ -15,12 +15,8 @@ import { UnLikeModal } from '@/components/UnLikeModal' ...@@ -15,12 +15,8 @@ import { UnLikeModal } from '@/components/UnLikeModal'
interface ChatAnswerOperateProps { interface ChatAnswerOperateProps {
answer: Answer answer: Answer
/**
* 是否隐藏点赞 / 点踩 / 复制按钮(用于策略页自动分析、重新分析等场景)
*/
hideFeedbackAndCopy?: boolean
} }
export const ChatAnswerOperate: React.FC<ChatAnswerOperateProps> = ({ answer, hideFeedbackAndCopy }) => { export const ChatAnswerOperate: React.FC<ChatAnswerOperateProps> = ({ answer }) => {
const showToast = useToast() const showToast = useToast()
// 兜底读取缓存的 tacticsMeta(会话从 tactics 打开的元信息) // 兜底读取缓存的 tacticsMeta(会话从 tactics 打开的元信息)
const tacticsMetaFromStorage = useMemo(() => { const tacticsMetaFromStorage = useMemo(() => {
...@@ -153,27 +149,25 @@ export const ChatAnswerOperate: React.FC<ChatAnswerOperateProps> = ({ answer, hi ...@@ -153,27 +149,25 @@ export const ChatAnswerOperate: React.FC<ChatAnswerOperateProps> = ({ answer, hi
} }
return ( return (
<div className="sm:mt-[12px] flex gap-[4px] justify-end"> <div className="sm:mt-[12px] flex gap-[4px] justify-end">
{/* 点赞 / 点踩 / 复制:在自动分析 / 重新分析等场景下整体隐藏 */} {/* 点赞 / 点踩 / 复制:默认始终展示 */}
{!hideFeedbackAndCopy && ( {/* 点赞 */}
<> <Tooltip color="foreground" content={isLike ? '取消点赞' : '点赞'} className="capitalize">
{/* 点赞 */} <Button variant="light" isIconOnly aria-label="LikeIcon" onPress={handleLike.run}>
<Tooltip color="foreground" content={isLike ? '取消点赞' : '点赞'} className="capitalize"> {isLike ? <LikeIconA /> : <LikeIcon />}
<Button variant="light" isIconOnly aria-label="LikeIcon" onPress={handleLike.run}> </Button>
{isLike ? <LikeIconA /> : <LikeIcon />} </Tooltip>
</Button> {/* 点踩 */}
</Tooltip> <Tooltip color="foreground" content={isUnLike ? '取消点踩' : '点踩'} className="capitalize">
{/* 点踩 */} <Button variant="light" isIconOnly aria-label="UnLikeIcon" onPress={handleUnLike}>
<Tooltip color="foreground" content={isUnLike ? '取消点踩' : '点踩'} className="capitalize"> {isUnLike ? <UnLikeIconA /> : <UnLikeIcon />}
<Button variant="light" isIconOnly aria-label="UnLikeIcon" onPress={handleUnLike}> </Button>
{isUnLike ? <UnLikeIconA /> : <UnLikeIcon />} </Tooltip>
</Button> {/* 复制 */}
</Tooltip> <Tooltip color="foreground" content="复制" className="capitalize">
{/* 复制 */} <Button variant="light" isIconOnly aria-label="CopyIcon" onPress={handleCopy}>
<Tooltip color="foreground" content="复制" className="capitalize"> <CopyIcon />
<Button variant="light" isIconOnly aria-label="CopyIcon" onPress={handleCopy}><CopyIcon /></Button> </Button>
</Tooltip> </Tooltip>
</>
)}
{/* 收藏(当路由未标记 from=tactics 且不存在 userMeta 缓存时才展示) */} {/* 收藏(当路由未标记 from=tactics 且不存在 userMeta 缓存时才展示) */}
{!shouldHideCollect && ( {!shouldHideCollect && (
<Tooltip color="foreground" content={isCollect ? '取消收藏' : '收藏'} className="capitalize"> <Tooltip color="foreground" content={isCollect ? '取消收藏' : '收藏'} className="capitalize">
......
...@@ -202,9 +202,17 @@ export const ChatAnswerParser: React.FC<ChatAnswerParserProps> = ({ isLastAnswer ...@@ -202,9 +202,17 @@ export const ChatAnswerParser: React.FC<ChatAnswerParserProps> = ({ isLastAnswer
{!isTyping {!isTyping
&& answer.cardList && answer.cardList
&& answer.cardList?.length !== 0 && answer.cardList?.length !== 0
&& <ChatAnswerAttachment fromParser isLastAnswer={isLastAnswer} onSubmitQuestion={onSubmitQuestion} answer={answer} />} && (
<ChatAnswerAttachment
fromParser
isLastAnswer={isLastAnswer}
onSubmitQuestion={onSubmitQuestion}
answer={answer}
/>
)}
{!isTyping && !shouldHideOperate && <ChatAnswerOperate answer={answer} hideFeedbackAndCopy={hideOperate} />} {/* 操作区:仅根据卡片类型 / 上层显式 hideOperate 控制是否展示 */}
{!isTyping && !shouldHideOperate && <ChatAnswerOperate answer={answer} />}
{!isTyping && <div className="flex text-[10px] right-[16px] text-[#d0d1d2] bottom-[4px]">AI生成</div>} {!isTyping && <div className="flex text-[10px] right-[16px] text-[#d0d1d2] bottom-[4px]">AI生成</div>}
</div> </div>
......
...@@ -24,9 +24,11 @@ export const ChatAnswerShower: React.FC<ChatAnswerShowerProps> = ({ answer, isLa ...@@ -24,9 +24,11 @@ export const ChatAnswerShower: React.FC<ChatAnswerShowerProps> = ({ answer, isLa
</MarkdownDetail> </MarkdownDetail>
</div> </div>
)} )}
{answer.cardList && answer.cardList?.length !== 0 && <ChatAnswerAttachment onSubmitQuestion={onSubmitQuestion} isLastAnswer={isLastAnswer} answer={answer} />} {answer.cardList && answer.cardList?.length !== 0 && (
{/* {} */} <ChatAnswerAttachment onSubmitQuestion={onSubmitQuestion} isLastAnswer={isLastAnswer} answer={answer} />
{!hideOperate && <ChatAnswerOperate answer={answer} hideFeedbackAndCopy={hideOperateProp} />} )}
{/* 操作区:仅根据卡片类型 / 上层显式 hideOperate 控制是否展示 */}
{!hideOperate && <ChatAnswerOperate answer={answer} />}
<div className="flex text-[10px] right-[16px] text-[#d0d1d2] bottom-[4px]">AI生成</div> <div className="flex text-[10px] right-[16px] text-[#d0d1d2] bottom-[4px]">AI生成</div>
</div> </div>
) )
......
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