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
+4 -4
View File
@@ -20,7 +20,7 @@
<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue';
import { invoke } from '@tauri-apps/api/core';
import { MusicApi } from '../api';
import { useRouter } from 'vue-router';
import { useUserStore } from '../stores/user';
import QRCode from 'qrcode';
@@ -52,7 +52,7 @@ async function refreshQr() {
qrError.value = '';
if (pollTimer) clearInterval(pollTimer);
try {
qrKey = await invoke('get_qr_key');
qrKey = await MusicApi.getQrKey();
if (!qrKey) {
qrError.value = '未获取到登录密钥';
qrLoading.value = false;
@@ -76,7 +76,7 @@ async function refreshQr() {
function startPolling() {
pollTimer = setInterval(async () => {
try {
const jsonStr: string = await invoke('check_qr_status', { query: { key: qrKey } });
const jsonStr: string = await MusicApi.checkQrStatus(qrKey);
const data = JSON.parse(jsonStr);
const code = data.code;
if (code === 800) {
@@ -104,7 +104,7 @@ function startPolling() {
async function fetchUserProfile() {
try {
const profileJson: string = await invoke('get_login_status');
const profileJson: string = await MusicApi.getLoginStatus();
const profile = JSON.parse(profileJson);
if (profile.profile) {
userStore.setUser({