fix(ai-web): 修复页面失去焦点的时候没有断开对话的连接
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import {ClearOutlined, UserOutlined} from '@ant-design/icons'
|
import {ClearOutlined, UserOutlined} from '@ant-design/icons'
|
||||||
import {Bubble, Sender, useXAgent, useXChat, Welcome} from '@ant-design/x'
|
import {Bubble, Sender, useXAgent, useXChat, Welcome} from '@ant-design/x'
|
||||||
import {fetchEventSource} from '@echofly/fetch-event-source'
|
import {fetchEventSource} from '@echofly/fetch-event-source'
|
||||||
|
import {useUnmount} from 'ahooks'
|
||||||
import {Button, Collapse, Flex, Typography} from 'antd'
|
import {Button, Collapse, Flex, Typography} from 'antd'
|
||||||
import {isStrBlank, trim} from 'licia'
|
import {isStrBlank, trim} from 'licia'
|
||||||
import {useRef, useState} from 'react'
|
import {useRef, useState} from 'react'
|
||||||
@@ -40,6 +41,11 @@ function Conversation() {
|
|||||||
const abortController = useRef<AbortController | null>(null)
|
const abortController = useRef<AbortController | null>(null)
|
||||||
const [input, setInput] = useState<string>('')
|
const [input, setInput] = useState<string>('')
|
||||||
|
|
||||||
|
useUnmount(() => {
|
||||||
|
console.log('Page Unmount')
|
||||||
|
abortController.current?.abort()
|
||||||
|
})
|
||||||
|
|
||||||
const [agent] = useXAgent<ChatMessage>({
|
const [agent] = useXAgent<ChatMessage>({
|
||||||
request: async (info, callbacks) => {
|
request: async (info, callbacks) => {
|
||||||
await fetchEventSource(`${commonInfo.baseAiUrl}/chat/async`, {
|
await fetchEventSource(`${commonInfo.baseAiUrl}/chat/async`, {
|
||||||
@@ -55,6 +61,7 @@ function Conversation() {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
onclose: () => callbacks.onSuccess([]),
|
onclose: () => callbacks.onSuccess([]),
|
||||||
|
onerror: error => callbacks.onError(error),
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user