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

View File

@ -42,7 +42,7 @@
<script setup lang="ts">
import { ref, watch, onMounted, onBeforeUnmount, nextTick } from 'vue'
import { invoke } from '@tauri-apps/api/core'
import { MusicApi } from '../api'
import IconMessageSquare from '~icons/lucide/message-square'
import IconHeart from '~icons/lucide/heart'
@ -77,13 +77,11 @@ async function fetchComments(reset = false) {
}
try {
const jsonStr: string = await invoke('comment_hot', {
query: {
type: props.type,
id: props.id,
limit: pageSize,
offset: (pageNo.value - 1) * pageSize
}
const jsonStr: string = await MusicApi.commentHot({
type: props.type,
id: props.id,
limit: pageSize,
offset: (pageNo.value - 1) * pageSize
})
const data = JSON.parse(jsonStr)
const list = data.hotComments || []
@ -116,13 +114,11 @@ async function likeComment(cid: number) {
const liked = !!target.liked
likingSet.value.add(cid)
try {
await invoke('comment_like', {
query: {
t: liked ? 0 : 1,
type: props.type,
id: props.id,
cid
}
await MusicApi.commentLike({
t: liked ? 0 : 1,
type: props.type,
id: props.id,
cid
})
target.liked = !liked
target.likedCount += liked ? -1 : 1