refactor(frontend): 重构前端代码以优化类型定义和组件逻辑
- 修改 ResponseData 类型定义,统一返回格式为数组类型 - 更新 API 函数签名以包含正确的返回类型注解 - 简化 AboutView 组件中的统计数据显示逻辑 - 移除未使用的变量和方法,精简组件代码 - 修复 HomeView 中的事件监听器类型定义问题 - 替换接口泛型中的 any 类型为 unknown 提高类型安全 - 注释掉未使用的全局变量避免潜在错误
This commit is contained in:
@@ -20,10 +20,10 @@ interface messageItem {
|
||||
interface BtnItem {
|
||||
id: number
|
||||
title: string
|
||||
handle?: () => Promise<any>
|
||||
handle?: () => Promise<never>
|
||||
}
|
||||
|
||||
let loading = ref(false)
|
||||
const loading = ref(false)
|
||||
let eventSource: EventSource // 保存 EventSource 实例
|
||||
const status = ref('closed') // 连接状态:closed, connecting, connected
|
||||
const messages = ref<messageItem[]>([{id: Date.now(), text: '输出结果'}])
|
||||
@@ -74,7 +74,7 @@ const connect = (url: string) => {
|
||||
}
|
||||
eventSource = new EventSource(url)
|
||||
// 连接成功
|
||||
eventSource.addEventListener("open", (event) => {
|
||||
eventSource.addEventListener("open", () => {
|
||||
console.log('SSE 连接已打开')
|
||||
status.value = 'connected'
|
||||
})
|
||||
@@ -88,7 +88,7 @@ const connect = (url: string) => {
|
||||
closeConnection()
|
||||
})
|
||||
// 错误处理
|
||||
eventSource.addEventListener('error', (event) => {
|
||||
eventSource.addEventListener('error', () => {
|
||||
console.log('连接断开或失败', new Date());
|
||||
// 如果这里也频繁触发,确认了是断连重连
|
||||
if (eventSource.readyState === EventSource.CLOSED) {
|
||||
|
||||
Reference in New Issue
Block a user