mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-06-14 19:51:58 +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:
@@ -23,7 +23,6 @@ import { MousePointer, Move, Loader2, RefreshCw } from 'lucide-vue-next'
|
||||
import HelpTooltip from '@/components/HelpTooltip.vue'
|
||||
import { configApi } from '@/api'
|
||||
import { useSystemStore } from '@/stores/system'
|
||||
import { setMouseThrottle } from '@/composables/useHidWebSocket'
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean
|
||||
@@ -39,9 +38,24 @@ const emit = defineEmits<{
|
||||
const { t } = useI18n()
|
||||
const systemStore = useSystemStore()
|
||||
|
||||
const DEFAULT_MOUSE_MOVE_SEND_INTERVAL_MS = 16
|
||||
|
||||
function clampMouseMoveSendIntervalMs(ms: number): number {
|
||||
if (!Number.isFinite(ms)) return DEFAULT_MOUSE_MOVE_SEND_INTERVAL_MS
|
||||
return Math.max(0, Math.min(1000, Math.floor(ms)))
|
||||
}
|
||||
|
||||
function loadMouseMoveSendIntervalFromStorage(): number {
|
||||
const raw = localStorage.getItem('hidMouseThrottle')
|
||||
const parsed = raw === null ? NaN : Number(raw)
|
||||
return clampMouseMoveSendIntervalMs(
|
||||
Number.isFinite(parsed) ? parsed : DEFAULT_MOUSE_MOVE_SEND_INTERVAL_MS
|
||||
)
|
||||
}
|
||||
|
||||
// Mouse Settings (real-time)
|
||||
const mouseThrottle = ref<number>(
|
||||
Number(localStorage.getItem('hidMouseThrottle')) || 0
|
||||
loadMouseMoveSendIntervalFromStorage()
|
||||
)
|
||||
const showCursor = ref<boolean>(
|
||||
localStorage.getItem('hidShowCursor') !== 'false' // default true
|
||||
@@ -105,9 +119,7 @@ async function loadDevices() {
|
||||
// Initialize from current config
|
||||
function initializeFromCurrent() {
|
||||
// Re-sync real-time settings from localStorage
|
||||
const storedThrottle = Number(localStorage.getItem('hidMouseThrottle')) || 0
|
||||
mouseThrottle.value = storedThrottle
|
||||
setMouseThrottle(storedThrottle)
|
||||
mouseThrottle.value = loadMouseMoveSendIntervalFromStorage()
|
||||
|
||||
const storedCursor = localStorage.getItem('hidShowCursor') !== 'false'
|
||||
showCursor.value = storedCursor
|
||||
@@ -138,11 +150,14 @@ function toggleMouseMode() {
|
||||
// Update mouse throttle (real-time)
|
||||
function handleThrottleChange(value: number[] | undefined) {
|
||||
if (!value || value.length === 0 || value[0] === undefined) return
|
||||
const throttleValue = value[0]
|
||||
const throttleValue = clampMouseMoveSendIntervalMs(value[0])
|
||||
mouseThrottle.value = throttleValue
|
||||
setMouseThrottle(throttleValue)
|
||||
// Save to localStorage
|
||||
localStorage.setItem('hidMouseThrottle', String(throttleValue))
|
||||
// Notify ConsoleView (storage event doesn't fire in same tab)
|
||||
window.dispatchEvent(new CustomEvent('hidMouseSendIntervalChanged', {
|
||||
detail: { intervalMs: throttleValue },
|
||||
}))
|
||||
}
|
||||
|
||||
// Handle backend change
|
||||
@@ -273,7 +288,7 @@ watch(() => props.open, (isOpen) => {
|
||||
@update:model-value="handleThrottleChange"
|
||||
:min="0"
|
||||
:max="1000"
|
||||
:step="10"
|
||||
:step="1"
|
||||
class="py-2"
|
||||
/>
|
||||
<div class="flex justify-between text-xs text-muted-foreground">
|
||||
|
||||
Reference in New Issue
Block a user