kindring 3 months ago
parent
commit
6ac6990147
3 changed files with 31 additions and 17 deletions
  1. 2 3
      src/apis/musicControl.ts
  2. 21 1
      src/components/music/musicIndex.vue
  3. 8 13
      src/main/control/magnet/music.ts

+ 2 - 3
src/apis/musicControl.ts

@@ -1,10 +1,9 @@
 import api from "./baseApi.ts"
 import {ResponseData} from "@/types/apiTypes.ts";
-import {Magnet} from "@/types/magnetType.ts";
 import {Music_Actions} from "@/apis/ApiAction.ts";
-import {MusicScanSetting} from "@/types/musicType.ts";
+import {MusicScanSetting, PlayList} from "@/types/musicType.ts";
 
-export async function fetchPlayList(): Promise< ResponseData<Magnet[]> >
+export async function fetchPlayList(): Promise< ResponseData<PlayList[]> >
 {
     let [_callId, promise] = api.sendQuery(Music_Actions.play_list_fetch, {});
     let response = await promise;

+ 21 - 1
src/components/music/musicIndex.vue

@@ -1,10 +1,12 @@
 <script setup lang="ts">
-import {defineComponent, Ref, ref} from "vue";
+import {defineComponent, onBeforeMount, Ref, ref} from "vue";
 import IconSvg from "@/components/public/icon/iconSvg.vue";
 import {PlayList} from "@/types/musicType.ts";
 import PlayListInfo from "./common/playListInfo.vue";
 import message from "@/components/public/kui/message";
 import MusicSetting from "@/components/music/common/musicSetting.vue";
+import {fetchPlayList} from "@/apis/musicControl.ts";
+import {ErrorCode} from "@/types/apiTypes.ts";
 
 defineComponent({
   name: "musicIndex"
@@ -78,12 +80,30 @@ function changePlayList(index: number) {
   musicViewShow.value = showPlayList;
 }
 
+async function loadPlayList()
+{
+  let responseData = await fetchPlayList();
+  if (responseData.code === ErrorCode.success)
+  {
+    playList.value = responseData.data;
+  } else
+  {
+    message.error(responseData.msg);
+  }
+}
+
+onBeforeMount(()=>{
+  loadPlayList();
+})
+
 function showMusicSetting()
 {
   message.info("show music setting");
   musicViewShow.value = showSetting;
   selectIndex.value = -1;
 }
+
+
 </script>
 
 <template>

+ 8 - 13
src/main/control/magnet/music.ts

@@ -1,10 +1,10 @@
 import {dialog} from "electron"
-import {ApiType, ErrorCode, RequestData, ResponseData} from "@/types/apiTypes.ts";
+import { ErrorCode, RequestData, ResponseData} from "@/types/apiTypes.ts";
 import Logger from "@/util/logger.ts";
 import {MusicScanSetting} from "@/types/musicType.ts";
 import {
     addScanConfig,
-    deleteScanConfig,
+    deleteScanConfig, getPlayList,
     getScanConfig,
     getScanConfigByPath,
     updateScanConfig
@@ -17,17 +17,13 @@ let logger = Logger.logger('music', 'info');
 
 export async function c_fetchPlayList(requestData: RequestData<null>)
 {
-    let responseData: ResponseData<any>
-    responseData = {
-        type: ApiType.res,
-        code: ErrorCode.success,
-        callId: requestData.callId,
-        action: requestData.action,
-        msg: '暂无歌单',
-        data: [],
+    let [err, playList] = await getPlayList();
+    if (err)
+    {
+        logger.error(`[获取扫描设置列表失败] ${err.message}`)
+        return t_gen_res(requestData, ErrorCode.db, '获取扫描设置列表失败', [])
     }
-
-    return responseData;
+    return t_gen_res(requestData, ErrorCode.success, '', playList);
 }
 
 /**
@@ -37,7 +33,6 @@ export async function c_fetchPlayList(requestData: RequestData<null>)
 export async function c_scanMusicSelect(requestData: RequestData<string>): Promise<ResponseData<string>>
 {
     let defaultPath = requestData.data;
-    logger.info(`select scan dir`);
     let result = await dialog.showOpenDialog({
         defaultPath: defaultPath,
         properties: ['openDirectory'],