Commit 8b542a3f authored by 文旺-丰林-DEV's avatar 文旺-丰林-DEV

add loading

parent 9be9b6fb
......@@ -37,11 +37,13 @@ const Chat: React.FC = () => {
const [selectSiderTabs, setSelectSiderTabs] = useState('');
const { data: glmToken } = useRequest(GetChatGLMToken);
const [answer, setAnswer] = useState('');
const [loading, setLoading] = useState(true);
const messageHistory = useRef<IHistory[]>([]);
const { sendMessage } = useWebSocket('wss://glm-api.baibaomen.com/ws', {
onMessage: (event) => {
const text = event.data;
if (text == '{{BBMCPLT}}') {
setLoading(false);
} else {
setAnswer(text);
window.scrollTo(0, document.body.scrollHeight);
......@@ -49,8 +51,10 @@ const Chat: React.FC = () => {
},
onOpen: () => {
console.log('连接成功!');
setLoading(false);
},
onError: () => {
setLoading(false);
message.error('连接失败了,请稍后再试!');
},
});
......@@ -61,6 +65,7 @@ const Chat: React.FC = () => {
return messageHistory.current;
}, [answer]);
async function handleSendMessage() {
setLoading(true);
sendMessage &&
sendMessage(
JSON.stringify({
......@@ -265,7 +270,7 @@ const Chat: React.FC = () => {
<Col span={4} push={isMobile ? 0 : 4}>
<div className={styles.outputButtonWrapper}>
<Item name="outputButton">
<Button htmlType="submit" type="primary" size="large">
<Button htmlType="submit" type="primary" size="large" loading={loading}>
发送
</Button>
</Item>
......
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