Commit 6a029a0e by Liu

fix:点击工具时新建会话

parent 187e8a25
......@@ -6,8 +6,9 @@ import { LoginModal } from '../LoginModal'
import type { RootState } from '@/store'
import SendIcon from '@/assets/svg/send.svg?react'
import { type WithAuthProps, withAuth } from '@/auth/withAuth'
import { useAppSelector } from '@/store/hook'
import { useAppDispatch, useAppSelector } from '@/store/hook'
import { fetchToolList } from '@/api/home'
import { createConversation } from '@/store/conversationSlice'
interface ChatEditorProps {
onChange?: (value: string) => void
......@@ -22,6 +23,7 @@ interface ChatEditorProps {
const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, onChange, onFocus, onSubmit, onToolClick, placeholders, showContentTips = false, initialValue = '' }) => {
// const dispatch = useAppDispatch()
const [content, setContent] = useState(initialValue)
const dispatch = useAppDispatch()
const editorRef = useRef<HTMLDivElement>(null)
const [currentPlaceholder, setCurrentPlaceholder] = useState(0)
const intervalRef = useRef<NodeJS.Timeout | null>(null)
......@@ -118,21 +120,42 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
document.execCommand('insertText', false, text)
}
// 处理通用模式按钮点击
const handleGeneralClick = () => {
// 切换到通用模式(true 表示通用模式,恢复默认不切换左侧)
setIsToolBtnActive(true)
// 清除选中的工具ID
setSelectedToolId(null)
// 调用父组件的回调函数,传递通用模式状态和工具ID,以及是否需要改变样式
onToolClick?.(true, undefined, false)
// 处理通用模式按钮点击:先创建新会话
const handleGeneralClick = async () => {
if (!checkAuth())
return
try {
await dispatch(createConversation({
conversationData: {},
shouldNavigate: true,
shouldSendQuestion: '',
})).unwrap()
setIsToolBtnActive(true)
setSelectedToolId(null)
onToolClick?.(true, undefined, false)
}
catch (error) {
console.error('创建会话失败:', error)
}
}
// 处理工具按钮点击
const handleToolClick = (tool: any) => {
setSelectedToolId(tool.toolId)
setIsToolBtnActive(false)
onToolClick?.(false, tool.toolId, true)
// 处理工具按钮点击:先创建新会话,再切换工具
const handleToolClick = async (tool: any) => {
if (!checkAuth())
return
try {
await dispatch(createConversation({
conversationData: {},
shouldNavigate: true,
shouldSendQuestion: '',
})).unwrap()
setSelectedToolId(tool.toolId)
setIsToolBtnActive(false)
onToolClick?.(false, tool.toolId, true)
}
catch (error) {
console.error('创建会话失败:', error)
}
}
useEffect(() => {
......@@ -240,8 +263,17 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
{toolList && toolList.length > 0 && (
<div className="absolute left-4 bottom-2 flex items-center gap-3 pointer-events-auto pl-[16px]">
{toolList.map((tool: any, index: number) => {
// index === 2 的按钮(通用模式)在默认状态下高亮
const isSelected = (selectedToolId === tool.toolId && !isToolBtnActive) || (index === 2 && isToolBtnActive)
// index === 1 的按钮(通用模式)在默认状态下高亮
const isSelected = (selectedToolId === tool.toolId && !isToolBtnActive) || (index === 1 && isToolBtnActive)
const handleButtonPress = async () => {
// 高亮状态直接返回,避免重复触发
if (isSelected)
return
if (index === 1)
await handleGeneralClick()
else
await handleToolClick(tool)
}
return (
<Button
key={tool.toolId || `tool-${index}`}
......@@ -252,7 +284,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
}`}
radius="full"
variant="bordered"
onPress={() => index === 2 ? handleGeneralClick() : handleToolClick(tool)}
onPress={handleButtonPress}
>
{tool.toolIcon && (
<img
......
......@@ -13,7 +13,7 @@ export const ChatWelcome: React.FC<ChatWelcomeProps> = ({ isEfficiencyMode = fal
// 根据模式显示不同的提示语
const getWelcomeText = () => {
if (isEfficiencyMode) {
return 'HI~ 我是您的提质增效助手,有什么可以帮您?'
return 'HI~我是您的数据助手,可以帮你查询业务数据哦'
}
return '您好,有什么我可以帮您的吗?'
}
......
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