mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-03-15 23:46:51 +08:00
fix(web): 统一 API 请求语义并修复鼠标移动发送间隔
- 新增统一 request:同时处理 HTTP 非 2xx 与 success=false,并用 i18n toast 提示错误 - api/index.ts 与 api/config.ts 统一使用同一 request,避免错误处理不一致 - "发送间隔" 仅控制鼠标移动事件频率,WebRTC/WS 行为一致,不影响点击/滚轮
This commit is contained in:
@@ -31,28 +31,7 @@ import type {
|
||||
TtydStatus,
|
||||
} from '@/types/generated'
|
||||
|
||||
const API_BASE = '/api'
|
||||
|
||||
/**
|
||||
* 通用请求函数
|
||||
*/
|
||||
async function request<T>(endpoint: string, options: RequestInit = {}): Promise<T> {
|
||||
const response = await fetch(`${API_BASE}${endpoint}`, {
|
||||
...options,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers,
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ message: 'Request failed' }))
|
||||
throw new Error(error.message || `HTTP ${response.status}`)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
import { request } from './request'
|
||||
|
||||
// ===== 全局配置 API =====
|
||||
export const configApi = {
|
||||
|
||||
Reference in New Issue
Block a user