|
@@ -436,6 +436,14 @@
|
|
|
|
|
|
<!--目录文件合并/提取 -->
|
|
|
<div v-show="menuIndex == '8'">
|
|
|
+ <div class="handle-item">
|
|
|
+ <label class="handle-label">保存位置:</label>
|
|
|
+ <el-input :title="mergeData.newPath" ref="upload-merge" size="small" @focus="pickPath('mergeData', 'upload-merge')" placeholder="请选择保存位置" v-model="mergeData.newPath" readonly style="width:150px;" prefix-icon="el-icon-folder"></el-input>
|
|
|
+ <el-popover placement="bottom" popper-class="popper-open" trigger="hover" content="打开保存位置">
|
|
|
+ <i class="el-icon-folder-opened" slot="reference" style="width: 18px;cursor: pointer; font-size: 22px; vertical-align: middle;" @click="openFolder('mergeData')"></i>
|
|
|
+ </el-popover>
|
|
|
+ </div>
|
|
|
+
|
|
|
<div class="handle-item" >
|
|
|
<label class="handle-label">操作类型:</label>
|
|
|
<el-select v-model="mergeData.type" style="width:150px;" size="small">
|
|
@@ -444,14 +452,14 @@
|
|
|
</el-select>
|
|
|
</div>
|
|
|
|
|
|
- <div class="handle-item">
|
|
|
- <label class="handle-label">保存位置:</label>
|
|
|
- <el-input :title="mergeData.newPath" ref="upload-merge" size="small" @focus="pickPath('mergeData', 'upload-merge')" placeholder="请选择保存位置" v-model="mergeData.newPath" readonly style="width:150px;" prefix-icon="el-icon-folder"></el-input>
|
|
|
+ <div class="handle-item" >
|
|
|
+ <label class="handle-label">同名文件:</label>
|
|
|
+ <el-checkbox v-model="mergeData.isCover">覆盖原文件</el-checkbox>
|
|
|
</div>
|
|
|
|
|
|
<template v-if="mergeData.type == 'extract'">
|
|
|
<div class="handle-item">
|
|
|
- <label class="handle-label">提取设置:</label>
|
|
|
+ <label class="handle-label">提取方式:</label>
|
|
|
<el-select v-model="mergeData.extractType" style="width:150px;" size="small" >
|
|
|
<el-option value="1" label="全部提取"></el-option>
|
|
|
<el-option value="2" label="按类型提取"></el-option>
|
|
@@ -988,6 +996,7 @@ export default {
|
|
|
fileType: '1',
|
|
|
fileName: '',
|
|
|
suffixName: '',
|
|
|
+ isCover: false
|
|
|
},
|
|
|
|
|
|
dowloadModel: false,
|
|
@@ -1122,6 +1131,17 @@ export default {
|
|
|
path = path + separator + pjson.softInfo.softName;
|
|
|
}
|
|
|
}
|
|
|
+ if(str == 'mergeData'){
|
|
|
+ if(!this.mergeData.newPath){
|
|
|
+ this.$notify({
|
|
|
+ title: '提示',
|
|
|
+ message: '请先选择保存位置',
|
|
|
+ type: 'warning'
|
|
|
+ });
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ path = this.mergeData.newPath;
|
|
|
+ }
|
|
|
electronApi.call('showItemInfolder',[path+'\\tty.tty'])
|
|
|
},
|
|
|
// 拖拽事件
|
|
@@ -1944,22 +1964,15 @@ export default {
|
|
|
}
|
|
|
|
|
|
for(let i=0;i < this.dirList.length; i++){
|
|
|
+ this.dirList[i].status = '2';
|
|
|
+ this.dirList[i].total = 0;
|
|
|
+ this.dirList[i].error = 0;
|
|
|
+ this.dirList[i].searchList = [];
|
|
|
let item = this.dirList[i];
|
|
|
|
|
|
if(this.mergeData.type == 'merge'){ // 合并目录
|
|
|
- fs.mkdir(this.mergeData.newPath + separator + item.name, (err) => {
|
|
|
- if(err){
|
|
|
- this.dirList[i].status = '5';
|
|
|
- if(err.toString().indexOf('EBUSY') > -1){
|
|
|
- this.$notify({title: '提示', message: "文件被占用,请关闭后重试!", type: 'warning'});
|
|
|
- thisdirList[i].status = '3';
|
|
|
- }else if(err.toString().indexOf('EXIST') > -1){
|
|
|
- this.dirList[i].status = '2';
|
|
|
- }
|
|
|
- }else{
|
|
|
- this.dirList[i].status = '2';
|
|
|
- }
|
|
|
- });
|
|
|
+ this.dirList[i].status = '6';
|
|
|
+ this.traverseDirectoryIteratively(i, this.mergeData.newPath, 'merge').catch(console.error);
|
|
|
}else if(this.mergeData.type == 'extract'){ // 提取文件
|
|
|
this.dirList[i].status = '6';
|
|
|
switch(this.mergeData.extractType){
|
|
@@ -2033,35 +2046,102 @@ export default {
|
|
|
size = 5;
|
|
|
}
|
|
|
|
|
|
- const fs = require('fs').promises;
|
|
|
+ const fsp = require('fs').promises;
|
|
|
if(!this.dirList[index].total){
|
|
|
this.dirList[index].total = 0;
|
|
|
}
|
|
|
|
|
|
- if(type == 'folder'){ //提取目录里面的文件
|
|
|
+ if(type == 'folder' || type == 'merge'){ //提取目录里面的文件,合并文件夹
|
|
|
let directoryPath = this.dirList[index].path + this.dirList[index].name;
|
|
|
const queue = [directoryPath]; // 使用数组作为队列
|
|
|
const visited = new Set(); // 用于跟踪已访问的目录,防止循环引用
|
|
|
|
|
|
while (queue.length > 0) {
|
|
|
- const currentPath = queue.shift();
|
|
|
-
|
|
|
+ const currentPath = queue.shift();
|
|
|
+
|
|
|
if (!visited.has(currentPath)) {
|
|
|
visited.add(currentPath);
|
|
|
+
|
|
|
+ if(type == 'merge' && !fs.existsSync(newPath + separator + this.dirList[index].name)){
|
|
|
+ fs.mkdirSync(newPath + separator + this.dirList[index].name);
|
|
|
+ }
|
|
|
|
|
|
try {
|
|
|
- const entries = await fs.readdir(currentPath,{ withFileTypes: true });
|
|
|
- for (const entry of entries) {
|
|
|
- const fullPath = path.join(currentPath, entry.name);
|
|
|
-
|
|
|
- if (entry.isDirectory()) {
|
|
|
+ const entries = await fsp.readdir(currentPath,{ withFileTypes: true });
|
|
|
+ for (const entry of entries) {
|
|
|
+ const fullPath = path.join(currentPath, entry.name);
|
|
|
+
|
|
|
+ if (entry.isDirectory()) {
|
|
|
+ if(type == 'merge'){
|
|
|
+ let beforePath = this.dirList[index].path;
|
|
|
+ let slicePath = fullPath.slice(beforePath.length);
|
|
|
+ let targetPath = newPath + separator + slicePath;
|
|
|
+ if(!fs.existsSync(targetPath)){
|
|
|
+ fs.mkdirSync(targetPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
queue.push(fullPath); // 将子目录添加到队列中以便后续遍历
|
|
|
- } else if (entry.isFile()) {
|
|
|
+ } else if (entry.isFile()) {
|
|
|
// 处理文件 console.log(`Found file: ${fullPath}`);
|
|
|
- let targetPath = newPath + separator + entry.name;
|
|
|
- if(this.dirList[index].total < size){
|
|
|
- await fs.copyFile(fullPath, targetPath);
|
|
|
- this.dirList[index].total += 1;
|
|
|
+ if(type == 'merge'){
|
|
|
+ let beforePath = this.dirList[index].path;
|
|
|
+ let slicePath = fullPath.slice(beforePath.length);
|
|
|
+ let targetPath = newPath + separator + slicePath;
|
|
|
+ if(this.dirList[index].total < size){
|
|
|
+ if(this.mergeData.isCover){ // 覆盖原文件
|
|
|
+ await fsp.copyFile(fullPath, targetPath);
|
|
|
+ this.dirList[index].total += 1;
|
|
|
+ }else{
|
|
|
+ try {
|
|
|
+ await fsp.access(targetPath, fs.constants.F_OK);
|
|
|
+ // 文件存在
|
|
|
+ let lastIndex = targetPath.lastIndexOf('.');
|
|
|
+ let beforePath = targetPath.slice(0, lastIndex);
|
|
|
+ let suffix = targetPath.slice(lastIndex);
|
|
|
+ let newFilePath = beforePath + '-重复文件' + uuidv4().substr(0, 18) + index.toString() + suffix;
|
|
|
+ await fsp.copyFile(fullPath, newFilePath);
|
|
|
+ this.dirList[index].total += 1;
|
|
|
+ } catch (err) {
|
|
|
+ if (err.code === 'ENOENT') {// 文件不存在
|
|
|
+ await fsp.copyFile(fullPath, targetPath);
|
|
|
+ this.dirList[index].total += 1;
|
|
|
+ } else {
|
|
|
+ // 抛出其他类型的错误
|
|
|
+ this.dirList[index].error += 1;
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ let targetPath = newPath + separator + entry.name;
|
|
|
+ if(this.dirList[index].total < size){
|
|
|
+ if(this.mergeData.isCover){ // 覆盖原文件
|
|
|
+ await fsp.copyFile(fullPath, targetPath);
|
|
|
+ this.dirList[index].total += 1;
|
|
|
+ }else{
|
|
|
+ try {
|
|
|
+ await fsp.access(targetPath, fs.constants.F_OK);
|
|
|
+ // 文件存在
|
|
|
+ let lastIndex = targetPath.lastIndexOf('.');
|
|
|
+ let beforePath = targetPath.slice(0, lastIndex);
|
|
|
+ let suffix = targetPath.slice(lastIndex);
|
|
|
+ let newFilePath = beforePath + '-重复文件' + uuidv4().substr(0, 18) + index.toString() + suffix;
|
|
|
+ await fsp.copyFile(fullPath, newFilePath);
|
|
|
+ this.dirList[index].total += 1;
|
|
|
+ } catch (err) {
|
|
|
+ if (err.code === 'ENOENT') {// 文件不存在
|
|
|
+ await fsp.copyFile(fullPath, targetPath);
|
|
|
+ this.dirList[index].total += 1;
|
|
|
+ } else {
|
|
|
+ // 抛出其他类型的错误
|
|
|
+ this.dirList[index].error += 1;
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -2069,7 +2149,7 @@ export default {
|
|
|
} catch (err) {
|
|
|
this.dirList[index].error += 1;
|
|
|
console.error(`Unable to scan directory: ${currentPath}, Error: ${err}`);
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}else if(type == 'files'){
|
|
@@ -2078,8 +2158,31 @@ export default {
|
|
|
let filename = entry.substr(entry.lastIndexOf('/')+1);
|
|
|
let targetPath = newPath + separator + filename;
|
|
|
if(this.dirList[index].total < size){
|
|
|
- await fs.copyFile(entry, targetPath);
|
|
|
- this.dirList[index].total += 1;
|
|
|
+ if(this.mergeData.isCover){ //覆盖原文件
|
|
|
+ await fsp.copyFile(entry, targetPath);
|
|
|
+ this.dirList[index].total += 1;
|
|
|
+ }else{
|
|
|
+ try {
|
|
|
+ await fsp.access(targetPath, fs.constants.F_OK);
|
|
|
+ // 文件存在
|
|
|
+ let lastIndex = targetPath.lastIndexOf('.');
|
|
|
+ let beforePath = targetPath.slice(0, lastIndex);
|
|
|
+ let suffix = targetPath.slice(lastIndex);
|
|
|
+ let newFilePath = beforePath + '-重复文件' + uuidv4().substr(0, 18) + index.toString() + suffix;
|
|
|
+ await fsp.copyFile(entry, newFilePath);
|
|
|
+ this.dirList[index].total += 1;
|
|
|
+ } catch (err) {
|
|
|
+ if (err.code === 'ENOENT') {// 文件不存在
|
|
|
+ await fsp.copyFile(entry, targetPath);
|
|
|
+ this.dirList[index].total += 1;
|
|
|
+ } else {
|
|
|
+ // 抛出其他类型的错误
|
|
|
+ this.dirList[index].error += 1;
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if(this.dirList[index].total > this.dirList[index].searchList.length){
|
|
|
this.dirList[index].total = this.dirList[index].searchList.length;
|
|
|
}
|