优化:底部导航菜单
This commit is contained in:
@@ -3,7 +3,7 @@ import {Textarea} from '@tarojs/components';
|
||||
import Taro from '@tarojs/taro';
|
||||
import {Button} from '@nutui/nutui-react-taro';
|
||||
import {User, Home} from '@nutui/icons-react-taro';
|
||||
import {sendAiMessage} from '@/api/ai';
|
||||
import {sendAiMessage, stopAiMessage} from '@/api/ai';
|
||||
import {createWebSocket} from '@/utils/websocket';
|
||||
import {getAiToken} from '@/utils/aiToken';
|
||||
import MarkdownRenderer from '@/components/MarkdownRenderer';
|
||||
@@ -11,7 +11,6 @@ import MarkdownRenderer from '@/components/MarkdownRenderer';
|
||||
import {View, RichText} from '@tarojs/components'
|
||||
import './index.scss';
|
||||
import {WSS_API_URL} from "@/utils/server";
|
||||
import SimpleH5TabBar from "@/components/SimpleH5TabBar";
|
||||
|
||||
// 消息类型
|
||||
interface Message {
|
||||
@@ -31,7 +30,7 @@ const AiChat = () => {
|
||||
const [messages, setMessages] = useState<Message[]>([]);
|
||||
const [inputValue, setInputValue] = useState('');
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
// const [currentTaskId, setCurrentTaskId] = useState<string>('');
|
||||
const [currentTaskId, setCurrentTaskId] = useState<string>('');
|
||||
const [wsConnected, setWsConnected] = useState(false);
|
||||
const [isInitialized, setIsInitialized] = useState(false);
|
||||
const messagesEndRef = useRef<HTMLDivElement>(null);
|
||||
@@ -79,8 +78,8 @@ const AiChat = () => {
|
||||
wsRef.current = createWebSocket(WSS_API_URL + "/chat/" + userToken);
|
||||
|
||||
wsRef.current.onMessage((data: any) => {
|
||||
console.log('收到WebSocket消息:', data);
|
||||
|
||||
console.log('收到WebSocket消息:', data.taskId);
|
||||
setCurrentTaskId(data.taskId)
|
||||
if (data.answer) {
|
||||
if (data.answer === '__END__') {
|
||||
// 消息结束,移除typing状态
|
||||
@@ -275,20 +274,24 @@ const AiChat = () => {
|
||||
};
|
||||
|
||||
// 停止AI回复
|
||||
// const handleStopMessage = async () => {
|
||||
// if (currentTaskId) {
|
||||
// try {
|
||||
// await stopAiMessage({taskId: currentTaskId});
|
||||
// setIsLoading(false);
|
||||
// setCurrentTaskId('');
|
||||
// setMessages(prev => prev.map(msg =>
|
||||
// msg.isTyping ? {...msg, isTyping: false} : msg
|
||||
// ));
|
||||
// } catch (error) {
|
||||
// console.error('停止消息失败:', error);
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
const handleStop = async () => {
|
||||
if (currentTaskId) {
|
||||
try {
|
||||
await stopAiMessage({
|
||||
taskId: currentTaskId,
|
||||
authCode: '1fbfa21a-a3df-445e-9ca5-2c1a9eead7f4',
|
||||
user: `${Taro.getStorageSync('AI_TOKEN') || 'anonymous'}`
|
||||
});
|
||||
setIsLoading(false);
|
||||
setCurrentTaskId('');
|
||||
setMessages(prev => prev.map(msg =>
|
||||
msg.isTyping ? {...msg, isTyping: false} : msg
|
||||
));
|
||||
} catch (error) {
|
||||
console.error('停止消息失败:', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 处理快捷问题点击
|
||||
const handleQuickQuestion = (question: string) => {
|
||||
@@ -385,7 +388,8 @@ const AiChat = () => {
|
||||
|
||||
<View className="input-container">
|
||||
<div className="input-wrapper flex justify-between items-center">
|
||||
<Home size={26} className={'bg-white'} onClick={() => Taro.reLaunch({url: '/pages/index/index'})}/>
|
||||
<Home size={26} className={'bg-white'}
|
||||
onClick={() => Taro.reLaunch({url: '/pages/index/index'})}/>
|
||||
<div className={'w-full mx-2'}>
|
||||
<Textarea
|
||||
className="message-input"
|
||||
@@ -405,10 +409,11 @@ const AiChat = () => {
|
||||
className={'flex justify-center items-center pr-1'}
|
||||
onClick={() => handleSendMessage(inputValue)}
|
||||
>
|
||||
<img alt={'发送'} src={'https://oss.wsdns.cn/20250709/13424d78bb004352864051d61afe9f0e.png'} width={'30px'} />
|
||||
<img alt={'发送'} src={'https://oss.wsdns.cn/20250709/13424d78bb004352864051d61afe9f0e.png'}
|
||||
width={'30px'}/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Button onClick={handleStop}>停止</Button>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user