refactor: 创建统一 API 封装层,前端不再直接调用 invoke

- 新增 src/api.ts,按职责分为 MusicApi/AudioApi/DeviceApi/DownloadApi/AppApi 五个命名空间
- 替换 15 个文件中所有 invoke 调用为 API 层方法
- 后端接口变更只需修改 api.ts 一处,便于后期迭代维护
This commit is contained in:
2026-05-29 22:02:42 +08:00
parent 68f29c8ea8
commit e40f82cc51
19 changed files with 302 additions and 116 deletions
+3 -3
View File
@@ -216,7 +216,7 @@ import { usePlayerStore, PlayMode } from '../stores/player';
import { useDownload } from '../composables/useDownload';
import { formatTime } from '../utils/format';
import { getCoverUrl } from '../utils/song';
import { invoke } from '@tauri-apps/api/core';
import { AudioApi } from '../api';
import { showToast } from '../composables/useToast';
import { listen } from '@tauri-apps/api/event';
import { useRouter } from 'vue-router';
@@ -292,7 +292,7 @@ function toggleMute() {
} else {
player.volume = prevVolume.value || 100;
}
invoke('set_volume', { vol: player.volume / 100 });
AudioApi.setVolume(player.volume / 100);
}
let onDocMove: ((e: MouseEvent) => void) | null = null;
@@ -418,7 +418,7 @@ async function handleVolumeChange(e: Event) {
const target = e.target as HTMLInputElement;
const val = parseInt(target.value, 10);
player.volume = val;
await invoke('set_volume', { vol: val / 100 });
await AudioApi.setVolume(val / 100);
}
const volumeBarBg = computed(() => {