Pārlūkot izejas kodu

多级目录创建

dsy 2 nedēļas atpakaļ
vecāks
revīzija
c18125b0a1
2 mainītis faili ar 24 papildinājumiem un 0 dzēšanām
  1. 17 0
      preload.js
  2. 7 0
      src/views/project_manage/org/offlinepackauth/index.vue

+ 17 - 0
preload.js

@@ -88,4 +88,21 @@ contextBridge.exposeInMainWorld('fileAPI', {
    * @returns {Promise} 文件路径
    */
   openFileDialog: (opts) => ipcRenderer.invoke('dialog:openFiles', opts),
+
+  /**
+   * 检查文件路径是否存在
+   * @param {string} filePath 文件路径
+   * @returns {boolean} 是否存在
+   */
+  existsSync: (filePath) => fs.existsSync(filePath),
+
+  /**
+   * 创建目录(递归)
+   * @param {string} dirPath 目录路径
+   */
+  mkdirSync: (dirPath) => {
+    if (!fs.existsSync(dirPath)) {
+      fs.mkdirSync(dirPath, { recursive: true });
+    }
+  },
 });

+ 7 - 0
src/views/project_manage/org/offlinepackauth/index.vue

@@ -380,6 +380,13 @@ export default {
 
       file_info_list.forEach((fileInfo) => {
         const { file_name, file_url, dir_name } = fileInfo;
+        // 如果有子目录,则判断是否有,没有就创建子目录
+        if (dir_name.split('/').length > 1) {
+          if (!window.fileAPI.existsSync(`${this.tempDir}\\${dir_name}`)) {
+            window.fileAPI.mkdirSync(`${this.tempDir}\\${dir_name}`);
+          }
+        }
+
         window.fileAPI.downloadFile(file_url, `${this.tempDir}\\${dir_name}\\${file_name}`).then(() => {
           this.downloadCompleted += 1;
         });