Commit e259f8d3 by Liu

fix:获取工具列表&&提问参数增加id

parent f520e296
......@@ -7,3 +7,11 @@ import http from '@/utils/request'
export function fetchQuestionList(data: any) {
return http.post('/config-center/api/commonconfig/mobile/v1/query_config_list', data)
}
/**
* 查询工具列表
* @params
*/
export function fetchToolList() {
return http.post('/config-center/api/tool/mobile/v1/get_tool_list')
}
......@@ -8,11 +8,12 @@ import SendIcon from '@/assets/svg/send.svg?react'
import efficiencyIcon from '@/assets/efficiency-icon.png'
import { type WithAuthProps, withAuth } from '@/auth/withAuth'
import { useAppSelector } from '@/store/hook'
import { fetchToolList } from '@/api/home'
interface ChatEditorProps {
onChange?: (value: string) => void
onFocus?: () => void
onSubmit?: (value: string) => void
onSubmit?: (value: string, toolId?: string) => void
placeholders: string[]
showContentTips?: boolean
initialValue?: string
......@@ -26,6 +27,21 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const intervalRef = useRef<NodeJS.Timeout | null>(null)
const [isOpenLoginModal, isOpenLoginModalActions] = useToggle()
const isAsking = useAppSelector((state: RootState) => state.chat.isAsking)
const [toolList, setToolList] = useState<any[]>([])
const [selectedToolId, setSelectedToolId] = useState<string | null>(null)
// 获取工具列表
const getToolList = async () => {
try {
const res = await fetchToolList()
if (res?.data) {
setToolList(res.data)
}
}
catch (error) {
console.error('获取工具列表失败:', error)
}
}
const startAnimation = () => {
intervalRef.current = setInterval(() => {
......@@ -55,7 +71,18 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
return
if (checkAuth()) {
if (content.trim()) {
onSubmit?.(content.trim())
// 根据选择的工具或默认工具获取toolId
let toolId: string | undefined
if (selectedToolId) {
// 如果选择了"提质增效"工具,使用对应的toolId
toolId = selectedToolId
}
else if (toolList.length > 0) {
// 如果没有选择工具,使用第一个工具的toolId
toolId = toolList[0].toolId
}
onSubmit?.(content.trim(), toolId)
setContent('')
if (editorRef.current) {
editorRef.current.textContent = ''
......@@ -82,6 +109,21 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
document.execCommand('insertText', false, text)
}
// 处理工具按钮点击
const handleToolClick = () => {
// 查找"提质增效"工具
const efficiencyTool = toolList.find((tool: any) => tool.toolName === '提质增效')
if (efficiencyTool) {
setSelectedToolId(efficiencyTool.toolId)
}
else {
// 如果没有找到"提质增效"工具,使用第一个工具
if (toolList.length > 0) {
setSelectedToolId(toolList[0].toolId)
}
}
}
useEffect(() => {
startAnimation()
document.addEventListener('visibilitychange', handleVisibilityChange)
......@@ -101,6 +143,11 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
}
}, [content])
// 组件加载时获取工具列表
useEffect(() => {
getToolList()
}, [])
// 处理initialValue的变化
useEffect(() => {
if (initialValue && editorRef.current) {
......@@ -196,6 +243,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
radius="full"
variant="bordered"
startContent={<img src={efficiencyIcon} alt="提质增效" className="w-5 h-5" />}
onPress={handleToolClick}
>
提质增效
</Button>
......
......@@ -113,7 +113,7 @@ export const Chat: React.FC = () => {
}
/** 提交问题 */
const handleSubmitQuestion = async (question: string, productCode?: string) => {
const handleSubmitQuestion = async (question: string, productCode?: string, toolId?: string) => {
// 停止之前的请求
if (abortControllerRef.current) {
abortControllerRef.current.abort()
......@@ -162,6 +162,7 @@ export const Chat: React.FC = () => {
conversationId: currentIdRef.current,
stream: true,
productCode,
toolId,
},
(msg) => {
// 检查是否已被取消
......@@ -293,7 +294,7 @@ export const Chat: React.FC = () => {
{allItems.map((record, index) => (
<div
className="w-full chatItem mx-auto"
key={`${record.role}-${record.id || index}-${
key={`${record.role}-${index}-${
record.question || record.answerList?.[0]?.answer || ''
}`}
>
......@@ -331,7 +332,7 @@ export const Chat: React.FC = () => {
</motion.div>
</div>
<ChatEditor onSubmit={handleSubmitQuestion} placeholders={[]} />
<ChatEditor onSubmit={(question, toolId) => handleSubmitQuestion(question, undefined, toolId)} placeholders={[]} />
<div className="hidden sm:block w-full text-center mt-[12px] text-[#3333334d] text-[12px]">
内容由AI模型生成,其准确性和完整性无法保证,仅供参考
</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