浏览代码

feat: 增加扫描路径功能
1. 增加扫描路径配置功能

kindring 3 月之前
父节点
当前提交
a048f07eb4
共有 3 个文件被更改,包括 61 次插入4 次删除
  1. 2 1
      src/apis/ApiAction.ts
  2. 6 0
      src/apis/musicControl.ts
  3. 53 3
      src/components/music/dialog/addScan.vue

+ 2 - 1
src/apis/ApiAction.ts

@@ -6,6 +6,7 @@ export enum Magnet_Actions {
 
 
 export enum Music_Actions {
-  play_list_fetch= 'play_list_fetch',
+  play_list_fetch = 'play_list_fetch',
   scan_music_select = 'scan_music_select',
+  scan_music_add = 'scan_music_add'
 }

+ 6 - 0
src/apis/musicControl.ts

@@ -2,6 +2,7 @@ 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";
 
 export async function fetchPlayList(): Promise< ResponseData<Magnet[]> >
 {
@@ -18,4 +19,9 @@ export async function selectScanDir(defaultPath: string): Promise< ResponseData<
     return await promise;
 }
 
+export async function addScanDir(scanSetting: MusicScanSetting)
+{
+    let [_callId, promise] = api.sendQuery(Music_Actions.scan_music_add, scanSetting);
+    return await promise;
+}
 

+ 53 - 3
src/components/music/dialog/addScan.vue

@@ -3,6 +3,8 @@ import {defineComponent, ref} from "vue";
 import KuiInput from "@/components/public/kui/kui-input.vue";
 import message from "@/components/public/kui/message";
 import {selectScanDir} from "@/apis/musicControl.ts";
+import KuiCheckbox from "@/components/public/kui/kui-checkbox.vue";
+import {MusicScanSetting} from "@/types/musicType.ts";
 
 defineComponent({
   name: "addScanDialog"
@@ -13,7 +15,10 @@ const emits = defineEmits<{
     (e: 'submit'): void
 }>()
 
+const name = ref('');
 const dirPath = ref('');
+const scanSubDir = ref(false);
+const isFileRepeat = ref(false);
 
 function closeDialog() {
   emits('close');
@@ -23,13 +28,39 @@ async function selectPathHandle() {
   let responseData = await selectScanDir(dirPath.value);
   // console.log(responseData)
   if (responseData.code === 0) {
-    dirPath.value = responseData.data;
+
+    dirPath.value = responseData.data ? responseData.data : dirPath.value;
     // message.success(`选择目录: ${responseData.data}`);
   } else {
     message.error(responseData.msg);
   }
 }
 
+async function submitHandle() {
+  let param: MusicScanSetting = {
+    name: name.value,
+    dirPath: dirPath.value,
+    scanSubDir: scanSubDir.value,
+    isFileRepeat: isFileRepeat.value
+  }
+  if (!param.dirPath)
+  {
+    message.warning('请选择需要扫描的子目录');
+    return;
+  }
+  if (!param.name)
+  {
+    param.name = param.dirPath;
+  }
+  let responseData = await addScanDir(param);
+  if (responseData.code === 0) {
+    message.success('添加扫描配置成功');
+    emits('close');
+  } else {
+    message.error(responseData.msg);
+  }
+}
+
 </script>
 
 <template>
@@ -45,6 +76,12 @@ async function selectPathHandle() {
 
     <div class="dialog-show">
       <div class="form-row" >
+        <kui-input label="文件名称"
+                   placeholder="扫描配置名称"
+                   v-model:value="name"
+        />
+      </div>
+      <div class="form-row mt-1" >
         <kui-input label="扫描路径"
                    placeholder="点击选择文件"
                    @firstClick="selectPathHandle"
@@ -52,10 +89,22 @@ async function selectPathHandle() {
         />
       </div>
 
+      <div class="form-row mt-1">
+        <kui-checkbox id="scanSubDir" v-model:value="scanSubDir" >
+          扫描子目录
+        </kui-checkbox>
+      </div>
+
+      <div class="form-row mt-1">
+        <kui-checkbox id="isFileRepeat" v-model:value="isFileRepeat" >
+          文件是否允许重复
+        </kui-checkbox>
+      </div>
+
     </div>
     <div class="dialog-footer">
       <div class="btn cancel-btn mr-2" @click="closeDialog()">取消</div>
-      <div class="btn primary-btn" @click="emits('submit')">确定</div>
+      <div class="btn primary-btn" @click="submitHandle">确定</div>
     </div>
 
   </div>
@@ -63,9 +112,10 @@ async function selectPathHandle() {
 
 <style scoped>
 .form-row{
-  width: 100%;
+  width: 90%;
   height: 40px;
   display: flex;
   align-items: center;
+  margin: 0 auto;
 }
 </style>