Commit 5e4d7627 by Liu

fix:注释工具按钮!!!

parent f0801acf
...@@ -5,11 +5,8 @@ import { useLocalStorageState, useToggle } from 'ahooks' ...@@ -5,11 +5,8 @@ import { useLocalStorageState, useToggle } from 'ahooks'
import { LoginModal } from '../LoginModal' import { LoginModal } from '../LoginModal'
import type { RootState } from '@/store' import type { RootState } from '@/store'
import SendIcon from '@/assets/svg/send.svg?react' import SendIcon from '@/assets/svg/send.svg?react'
import efficiencyIcon from '@/assets/efficiency-icon.png'
import generalIcon from '@/assets/general-icon.png'
import { type WithAuthProps, withAuth } from '@/auth/withAuth' import { type WithAuthProps, withAuth } from '@/auth/withAuth'
import { useAppSelector } from '@/store/hook' import { useAppSelector } from '@/store/hook'
import { fetchToolList } from '@/api/home'
interface ChatEditorProps { interface ChatEditorProps {
onChange?: (value: string) => void onChange?: (value: string) => void
...@@ -20,8 +17,8 @@ interface ChatEditorProps { ...@@ -20,8 +17,8 @@ interface ChatEditorProps {
showContentTips?: boolean showContentTips?: boolean
initialValue?: string initialValue?: string
} }
// onToolClick
const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, onChange, onFocus, onSubmit, onToolClick, placeholders, showContentTips = false, initialValue = '' }) => { const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, onChange, onFocus, onSubmit, placeholders, showContentTips = false, initialValue = '' }) => {
// const dispatch = useAppDispatch() // const dispatch = useAppDispatch()
const [content, setContent] = useState(initialValue) const [content, setContent] = useState(initialValue)
const editorRef = useRef<HTMLDivElement>(null) const editorRef = useRef<HTMLDivElement>(null)
...@@ -29,22 +26,22 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -29,22 +26,22 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const intervalRef = useRef<NodeJS.Timeout | null>(null) const intervalRef = useRef<NodeJS.Timeout | null>(null)
const [isOpenLoginModal, isOpenLoginModalActions] = useToggle() const [isOpenLoginModal, isOpenLoginModalActions] = useToggle()
const isAsking = useAppSelector((state: RootState) => state.chat.isAsking) const isAsking = useAppSelector((state: RootState) => state.chat.isAsking)
const [toolList, setToolList] = useState<any[]>([]) // const [toolList, setToolList] = useState<any[]>([])
const [selectedToolId, setSelectedToolId] = useState<string | null>(null) // const [selectedToolId, setSelectedToolId] = useState<string | null>(null)
const [isToolBtnActive, setIsToolBtnActive] = useState<boolean>(true) // const [isToolBtnActive, setIsToolBtnActive] = useState<boolean>(true)
// 获取工具列表 // 获取工具列表
const getToolList = async () => { // const getToolList = async () => {
try { // try {
const res = await fetchToolList() // const res = await fetchToolList()
if (res?.data) { // if (res?.data) {
setToolList(res.data) // setToolList(res.data)
} // }
} // }
catch (error) { // catch (error) {
console.error('获取工具列表失败:', error) // console.error('获取工具列表失败:', error)
} // }
} // }
const startAnimation = () => { const startAnimation = () => {
intervalRef.current = setInterval(() => { intervalRef.current = setInterval(() => {
...@@ -77,18 +74,18 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -77,18 +74,18 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
// 只在提质增效模式下传递 toolId,通用模式不传 // 只在提质增效模式下传递 toolId,通用模式不传
let toolId: string | undefined let toolId: string | undefined
if (!isToolBtnActive && selectedToolId) { // if (!isToolBtnActive && selectedToolId) {
// 提质增效模式:使用选中的 toolId // // 提质增效模式:使用选中的 toolId
toolId = selectedToolId // toolId = selectedToolId
// eslint-disable-next-line no-console // // eslint-disable-next-line no-console
console.log('📤 [ChatEditor] 提质增效模式提交,toolId:', toolId) // console.log('📤 [ChatEditor] 提质增效模式提交,toolId:', toolId)
} // }
else { // else {
// 通用模式:不传递 toolId // // 通用模式:不传递 toolId
toolId = undefined // toolId = undefined
// eslint-disable-next-line no-console // // eslint-disable-next-line no-console
console.log('📤 [ChatEditor] 通用模式提交,不传递 toolId') // console.log('📤 [ChatEditor] 通用模式提交,不传递 toolId')
} // }
onSubmit?.(content.trim(), toolId) onSubmit?.(content.trim(), toolId)
setContent('') setContent('')
if (editorRef.current) { if (editorRef.current) {
...@@ -117,36 +114,36 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -117,36 +114,36 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
} }
// 处理提质增效按钮点击 // 处理提质增效按钮点击
const handleEfficiencyClick = () => { // const handleEfficiencyClick = () => {
// 查找"提质增效"工具 // // 查找"提质增效"工具
const efficiencyTool = toolList.find((tool: any) => tool.toolName === '提质增效') // const efficiencyTool = toolList.find((tool: any) => tool.toolName === '提质增效')
let currentToolId = null // let currentToolId = null
if (efficiencyTool) { // if (efficiencyTool) {
setSelectedToolId(efficiencyTool.toolId) // setSelectedToolId(efficiencyTool.toolId)
currentToolId = efficiencyTool.toolId // currentToolId = efficiencyTool.toolId
} // }
else { // else {
// 如果没有找到"提质增效"工具,使用第一个工具 // // 如果没有找到"提质增效"工具,使用第一个工具
if (toolList.length > 0) { // if (toolList.length > 0) {
setSelectedToolId(toolList[0].toolId) // setSelectedToolId(toolList[0].toolId)
currentToolId = toolList[0].toolId // currentToolId = toolList[0].toolId
} // }
} // }
// 切换到工具模式(false 表示工具模式,会切换左侧展示) // // 切换到工具模式(false 表示工具模式,会切换左侧展示)
setIsToolBtnActive(false) // setIsToolBtnActive(false)
// 调用父组件的回调函数,传递工具模式状态和工具ID,以及是否需要改变样式 // // 调用父组件的回调函数,传递工具模式状态和工具ID,以及是否需要改变样式
onToolClick?.(false, currentToolId, true) // onToolClick?.(false, currentToolId, true)
} // }
// 处理通用模式按钮点击 // 处理通用模式按钮点击
const handleGeneralClick = () => { // const handleGeneralClick = () => {
// 切换到通用模式(true 表示通用模式,恢复默认不切换左侧) // // 切换到通用模式(true 表示通用模式,恢复默认不切换左侧)
setIsToolBtnActive(true) // setIsToolBtnActive(true)
// 清除选中的工具ID // // 清除选中的工具ID
setSelectedToolId(null) // setSelectedToolId(null)
// 调用父组件的回调函数,传递通用模式状态和工具ID,以及是否需要改变样式 // // 调用父组件的回调函数,传递通用模式状态和工具ID,以及是否需要改变样式
onToolClick?.(true, undefined, false) // onToolClick?.(true, undefined, false)
} // }
useEffect(() => { useEffect(() => {
startAnimation() startAnimation()
...@@ -164,9 +161,9 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -164,9 +161,9 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
}, [content]) }, [content])
// 组件加载时获取工具列表 // 组件加载时获取工具列表
useEffect(() => { // useEffect(() => {
getToolList() // getToolList()
}, []) // }, [])
// 处理initialValue的变化 // 处理initialValue的变化
useEffect(() => { useEffect(() => {
...@@ -194,9 +191,9 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -194,9 +191,9 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
background: '#FFFFFF', background: '#FFFFFF',
border: '1px solid #0a0a0a78', border: '1px solid #0a0a0a78',
boxShadow: '0 8px 12px 0 rgba(235,235,235,0.30)', boxShadow: '0 8px 12px 0 rgba(235,235,235,0.30)',
height: '102px',
}} }}
> >
{/* height: '102px', */}
<div <div
ref={editorRef} ref={editorRef}
contentEditable contentEditable
...@@ -213,9 +210,9 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -213,9 +210,9 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
style={{ style={{
resize: 'none', resize: 'none',
maxHeight: '48px', maxHeight: '48px',
marginBottom: '40px',
}} }}
> >
{/* marginBottom: '40px', */}
</div> </div>
<Tooltip isOpen={Boolean(token) && showContentTips && !isAsking && !content} color="foreground" content="请输入您的问题📖" placement="top-end"> <Tooltip isOpen={Boolean(token) && showContentTips && !isAsking && !content} color="foreground" content="请输入您的问题📖" placement="top-end">
<Button className="ask-send" onPress={handleSubmit} radius="full" isDisabled={!content || isAsking} isIconOnly color="primary"> <Button className="ask-send" onPress={handleSubmit} radius="full" isDisabled={!content || isAsking} isIconOnly color="primary">
...@@ -258,7 +255,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -258,7 +255,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
> >
数据助手 数据助手
</Button> */} </Button> */}
<Button {/* <Button
className={`w-[96px] h-[32px] px-3 rounded-full shadow-none text-[12px] transition-all duration-200 ${ className={`w-[96px] h-[32px] px-3 rounded-full shadow-none text-[12px] transition-all duration-200 ${
!isToolBtnActive !isToolBtnActive
? 'bg-[#F3F7FF] border-[#F3F7FF] text-[#165DFF]' ? 'bg-[#F3F7FF] border-[#F3F7FF] text-[#165DFF]'
...@@ -283,7 +280,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -283,7 +280,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
onPress={handleGeneralClick} onPress={handleGeneralClick}
> >
通用模式 通用模式
</Button> </Button> */}
</div> </div>
<LoginModal onClose={handleCloseLoginModal} isOpen={isOpenLoginModal} /> <LoginModal onClose={handleCloseLoginModal} isOpen={isOpenLoginModal} />
</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