diff --git a/src/main/index.js b/src/main/index.js index 601ccbb..6513e42 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -142,6 +142,12 @@ app.whenReady().then(() => { let paramsObj = JSON.parse(paramsStr) mainWindow.webContents.send(`delFileResult`, paramsObj) }) + // 删除所有文件 + ipcMain.on('deleteFolder', (e, paramsStr) => { + try { + fs.rmdirSync(paramsStr, { recursive: true }) + } catch (e) { } + }) // 打开文件 ipcMain.on('openFile', (e, pathStr) => { let filePath = path.join("D:\\test\\", pathStr.replace("D:\\test\\", "")); @@ -168,7 +174,7 @@ app.whenReady().then(() => { let errorFolderList = [] for (let index = 0; index < pathList.length; index++) { let element = pathList[index]; - let folderPath = path.join("D:\\test\\", element); + let folderPath = path.join("D:\\test\\", element.replace("D:\\test\\", "")); folderPath = Buffer.from(folderPath, 'utf8').toString('utf8'); try { fs.mkdirSync(`${folderPath}\\`, { recursive: true }); diff --git a/src/renderer/src/views/dangan.vue b/src/renderer/src/views/dangan.vue index 69ac23b..5ea1097 100644 --- a/src/renderer/src/views/dangan.vue +++ b/src/renderer/src/views/dangan.vue @@ -311,6 +311,7 @@ export default { xiangmuList.push(key) } } + xiangmuList = _.sortBy(xiangmuList) let { pathList, treeList } = that.bulkAddXiangmu(xiangmuList) let { tableList } = that.bulkAddFile(treeList, sheetData) that.inputTreeList = _.cloneDeep(treeList) @@ -383,11 +384,13 @@ export default { // 批量新增文件 bulkAddFile(treeList, tableDataList) { - console.log(386, tableDataList); let tableList = [] for (let i = 0; i < tableDataList.length; i++) { let fileItem = tableDataList[i]; - let juanNameLIst = _.split(fileItem["文件名"], "·") + let fileNameTemp = fileItem["文件名"].replaceAll(" ", "") + let juanNameLIst = _.split(fileNameTemp, "·") + let juanNameLIstTemp = _.cloneDeep(juanNameLIst) + juanNameLIstTemp.splice(juanNameLIstTemp.length - 1, 0, i) if (juanNameLIst) { let pdfText = juanNameLIst[juanNameLIst.length - 1]; // 使用正则表达式只保留汉字 @@ -395,7 +398,13 @@ export default { let juanName = chineseCharsOnly ? chineseCharsOnly.join('') : ''; let treeItem = _.find(treeList, o => o.path === `${fileItem["项目名"]}\\${fileItem["卷名"]}\\${juanName}`) let treeItem1 = _.find(treeList, o => _.startsWith(o.path, `${fileItem["项目名"]}\\${fileItem["卷名"]}`) && juanName.includes(o.label)) + if (!treeItem1) { + treeItem1 = _.find(treeList, o => _.startsWith(o.path, `${fileItem["项目名"]}\\${fileItem["卷名"]}`)) + } let treeItem2 = _.find(treeList, o => _.startsWith(o.path, `${fileItem["项目名"]}}`) && juanName.includes(o.label)) + if (!treeItem2) { + treeItem2 = _.find(treeList, o => _.startsWith(o.path, `${fileItem["项目名"]}}`)) + } let path = _.split(fileItem["储存位置"], "_") let fileType = _.find(this.fileList, o => o.label === path[1].split(".")[1]) let prepath = _.split(fileItem["储存位置"], "uploadPath/") @@ -406,13 +415,13 @@ export default { prepretreeId: treeItem.prepreId, xiangmuName: fileItem["项目名"], juanName: `${fileItem["卷名"]}_${juanName}`, - fileName: path[1], + fileName: fileNameTemp, fileType: (fileType || {}).value, uploadTime: fileItem["上传时间"], status: fileItem["状态"], size: "", - path: `D: \\test\\${fileItem["项目名"]}\\${fileItem["卷名"]}\\${juanName}\\${path[1]}`, - prePath: `D: \\uploadPath\\${prepath[1].replaceAll("/", "\\")}`, + path: `D:\\test\\${fileItem["项目名"]}\\${fileItem["卷名"]}\\${juanName}\\${_.join(juanNameLIstTemp, ".")}`, + prePath: `D:\\uploadPath\\${prepath[1].replaceAll("/", "\\")}`, note: fileItem["备注"], create_at: dayjs().format('YYYY-MM-DD HH:mm:ss'), update_at: dayjs().format('YYYY-MM-DD HH:mm:ss'), @@ -424,13 +433,13 @@ export default { prepretreeId: treeItem1.prepreId, xiangmuName: fileItem["项目名"], juanName: `${fileItem["卷名"]}`, - fileName: path[1], + fileName: fileNameTemp, fileType: (fileType || {}).value, uploadTime: fileItem["上传时间"], status: fileItem["状态"], size: "", - path: `D: \\test\\${fileItem["项目名"]}\\${fileItem["卷名"]}\\${path[1]}`, - prePath: `D: \\uploadPath\\${prepath[1].replaceAll("/", "\\")}`, + path: `D:\\test\\${fileItem["项目名"]}\\${fileItem["卷名"]}\\${_.join(juanNameLIstTemp, ".")}`, + prePath: `D:\\uploadPath\\${prepath[1].replaceAll("/", "\\")}`, note: fileItem["备注"], create_at: dayjs().format('YYYY-MM-DD HH:mm:ss'), update_at: dayjs().format('YYYY-MM-DD HH:mm:ss'), @@ -442,13 +451,13 @@ export default { prepretreeId: treeItem2.prepreId, xiangmuName: fileItem["项目名"], juanName: `${fileItem["卷名"]}_${juanName}`, - fileName: path[1], + fileName: fileNameTemp, fileType: (fileType || {}).value, uploadTime: fileItem["上传时间"], status: fileItem["状态"], size: "", - path: `D: \\test\\${fileItem["项目名"]}\\${path[1]}`, - prePath: `D: \\uploadPath\\${prepath[1].replaceAll("/", "\\")}`, + path: `D:\\test\\${fileItem["项目名"]}\\${_.join(juanNameLIstTemp, ".")}`, + prePath: `D:\\uploadPath\\${prepath[1].replaceAll("/", "\\")}`, note: fileItem["备注"], create_at: dayjs().format('YYYY-MM-DD HH:mm:ss'), update_at: dayjs().format('YYYY-MM-DD HH:mm:ss'), @@ -670,7 +679,7 @@ export default { "一级卷名": _.split(listItem.juanName, "_")[0], "二级卷名": _.split(listItem.juanName, "_")[1], "文件名": listItem.fileName, - "文件路径": `D: \\test\\${listItem.path.replace("D:\\test\\", "")}`, + "文件路径": `D:\\test\\${listItem.path.replace("D:\\test\\", "")}`, "文件类型": _.find(this.fileList, { value: listItem.fileType }).label, "文件大小": this.genSize(listItem.size), "文件状态": listItem.status, @@ -764,29 +773,28 @@ export default { cancelButtonText: '取消', type: 'error', } - ) - .then(async () => { - // 清空数据库 - let db = await myDatabase.open(); - // 获取所有表(对象存储)名称 - let tableNames = db._storeNames - // 遍历并删除每个表及其数据 - for (let index = 0; index < tableNames.length; index++) { - let tableName = tableNames[index]; - await myDatabase[tableName].clear(); - } - await this.searchTree() - ElMessage({ - type: 'error', - message: '您已经删除数据库,数据全部清空了!!!', - }) + ).then(async () => { + // 清空数据库 + let db = await myDatabase.open(); + // 获取所有表(对象存储)名称 + let tableNames = db._storeNames + // 遍历并删除每个表及其数据 + for (let index = 0; index < tableNames.length; index++) { + let tableName = tableNames[index]; + await myDatabase[tableName].clear(); + } + window.electron.ipcRenderer.send('deleteFolder', "D:\\test") + await this.searchTree() + ElMessage({ + type: 'error', + message: '您已经删除数据库,数据全部清空了!!!', }) - .catch(() => { - ElMessage({ - type: 'success', - message: '您取消删除数据库,数据仍然存在', - }) + }).catch(() => { + ElMessage({ + type: 'success', + message: '您取消删除数据库,数据仍然存在', }) + }) }, //预览 @@ -816,8 +824,8 @@ export default { name: row.fileName, type: row.fileType, size: row.size, - path: `D: \\test\\${row.xiangmuName} \\${_.join(_.split(row.juanName, "_"), "\\")} \\${row.fileName} `, - url: `D: \\test\\${row.xiangmuName} \\${_.join(_.split(row.juanName, "_"), "\\")} \\${row.fileName} `, + path: `D:\\test\\${row.xiangmuName} \\${_.join(_.split(row.juanName, "_"), "\\")} \\${row.fileName} `, + url: `D:\\test\\${row.xiangmuName} \\${_.join(_.split(row.juanName, "_"), "\\")} \\${row.fileName} `, } ], fileType: row.fileType,