Commit 12e28b73 by Liu

fix:工具按钮使用数据渲染

parent 55979b51
...@@ -13,7 +13,7 @@ export function fetchQuestionList(data: any) { ...@@ -13,7 +13,7 @@ export function fetchQuestionList(data: any) {
* @params * @params
*/ */
export function fetchToolList() { export function fetchToolList() {
return http.post('/config-center/api/tool/mobile/v1/get_tool_list') return http.post('/config-center/api/tool/mobile/v1/get_tool_list', { toolType: '03' })
} }
/** /**
......
...@@ -8,9 +8,6 @@ import SendIcon from '@/assets/svg/send.svg?react' ...@@ -8,9 +8,6 @@ import SendIcon from '@/assets/svg/send.svg?react'
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' import { fetchToolList } from '@/api/home'
import dataIcon from '@/assets/data-icon.png'
import efficiencyIcon from '@/assets/efficiency-icon.png'
import generalIcon from '@/assets/general-icon.png'
interface ChatEditorProps { interface ChatEditorProps {
onChange?: (value: string) => void onChange?: (value: string) => void
...@@ -39,7 +36,11 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -39,7 +36,11 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
try { try {
const res = await fetchToolList() const res = await fetchToolList()
if (res?.data) { if (res?.data) {
setToolList(res.data) // 根据 toolId 去重,防止重复渲染
const uniqueList = res.data.filter((tool: any, index: number, self: any[]) =>
index === self.findIndex((t: any) => t.toolId === tool.toolId),
)
setToolList(uniqueList)
} }
} }
catch (error) { catch (error) {
...@@ -117,28 +118,6 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -117,28 +118,6 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
document.execCommand('insertText', false, text) document.execCommand('insertText', false, text)
} }
// 处理提质增效按钮点击
const handleEfficiencyClick = () => {
// 查找"提质增效"工具
const efficiencyTool = toolList.find((tool: any) => tool.toolName === '提质增效')
let currentToolId = null
if (efficiencyTool) {
setSelectedToolId(efficiencyTool.toolId)
currentToolId = efficiencyTool.toolId
}
else {
// 如果没有找到"提质增效"工具,使用第一个工具
if (toolList.length > 0) {
setSelectedToolId(toolList[0].toolId)
currentToolId = toolList[0].toolId
}
}
// 切换到工具模式(false 表示工具模式,会切换左侧展示)
setIsToolBtnActive(false)
// 调用父组件的回调函数,传递工具模式状态和工具ID,以及是否需要改变样式
onToolClick?.(false, currentToolId, true)
}
// 处理通用模式按钮点击 // 处理通用模式按钮点击
const handleGeneralClick = () => { const handleGeneralClick = () => {
// 切换到通用模式(true 表示通用模式,恢复默认不切换左侧) // 切换到通用模式(true 表示通用模式,恢复默认不切换左侧)
...@@ -149,6 +128,13 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -149,6 +128,13 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
onToolClick?.(true, undefined, false) onToolClick?.(true, undefined, false)
} }
// 处理工具按钮点击
const handleToolClick = (tool: any) => {
setSelectedToolId(tool.toolId)
setIsToolBtnActive(false)
onToolClick?.(false, tool.toolId, true)
}
useEffect(() => { useEffect(() => {
startAnimation() startAnimation()
document.addEventListener('visibilitychange', handleVisibilityChange) document.addEventListener('visibilitychange', handleVisibilityChange)
...@@ -253,40 +239,32 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -253,40 +239,32 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
</div> </div>
{toolList && toolList.length > 0 && ( {toolList && toolList.length > 0 && (
<div className="absolute left-4 bottom-2 flex items-center gap-3 pointer-events-auto pl-[16px]"> <div className="absolute left-4 bottom-2 flex items-center gap-3 pointer-events-auto pl-[16px]">
<Button {toolList.map((tool: any, index: number) => {
className="w-[96px] h-[32px] px-3 rounded-full bg-white border border-[#E6E8EB] shadow-none text-[#111827] text-[12px]" // index === 2 的按钮(通用模式)在默认状态下高亮
radius="full" const isSelected = (selectedToolId === tool.toolId && !isToolBtnActive) || (index === 2 && isToolBtnActive)
variant="bordered" return (
startContent={<img src={dataIcon} alt="数据助手" className="w-5 h-5" />} <Button
> key={tool.toolId || `tool-${index}`}
数据助手 className={`w-auto h-[32px] px-3 rounded-full shadow-none text-[12px] flex items-center gap-2 transition-all duration-200 ${
</Button> isSelected
<Button ? 'bg-[#F3F7FF] border-[#F3F7FF] text-[#165DFF]'
className={`w-[96px] h-[32px] px-3 rounded-full shadow-none text-[12px] transition-all duration-200 ${ : 'bg-white border border-[#E6E8EB] text-[#111827]'
!isToolBtnActive }`}
? 'bg-[#F3F7FF] border-[#F3F7FF] text-[#165DFF]' radius="full"
: 'bg-white border border-[#E6E8EB] text-[#111827]' variant="bordered"
}`} onPress={() => index === 2 ? handleGeneralClick() : handleToolClick(tool)}
radius="full" >
variant="bordered" {tool.toolIcon && (
startContent={<img src={efficiencyIcon} alt="提质增效" className="w-5 h-5" />} <img
onPress={handleEfficiencyClick} src={tool.toolIcon}
> alt={tool.toolName}
提质增效 className="w-4 h-4 flex-shrink-0"
</Button> />
<Button )}
className={`w-[96px] h-[32px] px-3 rounded-full shadow-none text-[12px] transition-all duration-200 ${ {tool.toolName}
isToolBtnActive </Button>
? 'bg-[#F3F7FF] border-[#F3F7FF] text-[#165DFF]' )
: 'bg-white border border-[#E6E8EB] text-[#111827]' })}
}`}
radius="full"
variant="bordered"
startContent={<img src={generalIcon} alt="通用模式" className="w-5 h-5" />}
onPress={handleGeneralClick}
>
通用模式
</Button>
</div> </div>
)} )}
<LoginModal onClose={handleCloseLoginModal} isOpen={isOpenLoginModal} /> <LoginModal onClose={handleCloseLoginModal} isOpen={isOpenLoginModal} />
......
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