diff --git a/src/views/main_web/workspace/workspace.new.vue b/src/views/main_web/workspace/workspace.new.vue
index e6be5e78..237756fb 100644
--- a/src/views/main_web/workspace/workspace.new.vue
+++ b/src/views/main_web/workspace/workspace.new.vue
@@ -67,7 +67,7 @@
:selectSystemFolders="selectSystemFolders"
/>
-
+
file.path);
- itemPaths.forEach(async fullPath => {
- const maybeTasks = await system.analyzeSystemPath(fullPath);
- const tasks = maybeTasks || [];
- tasks.forEach(uploadTask => this.clientUpload(uploadTask));
- });
+ this.clientUpload(itemPaths);
+ // itemPaths.forEach(async fullPath => {
+ // const maybeTasks = await system.analyzeSystemPath(fullPath);
+ // const tasks = maybeTasks || [];
+ // tasks.forEach(uploadTask => this.clientUpload(uploadTask));
+ // });
},
stopPropagation(e) {
e.stopPropagation();
@@ -739,11 +740,12 @@ export default {
if(!this.isClient) return;
const filePaths = await system.chooseFiles();
if(!filePaths) return;
- filePaths.forEach(async fullPath => {
- const maybeTasks = await system.analyzeSystemPath(fullPath);
- const tasks = maybeTasks || [];
- tasks.forEach(uploadTask => this.clientUpload(uploadTask));
- });
+ this.clientUpload(filePaths);
+ // filePaths.forEach(async fullPath => {
+ // const maybeTasks = await system.analyzeSystemPath(fullPath);
+ // const tasks = maybeTasks || [];
+ // tasks.forEach(uploadTask => this.clientUpload(uploadTask));
+ // });
},
/**
* 客户端选择文件夹列表并上传
@@ -752,11 +754,12 @@ export default {
if(!this.isClient) return;
const folderPaths = await system.chooseFolders();
if(!folderPaths) return;
- folderPaths.forEach(async fullPath => {
- const maybeTasks = await system.analyzeSystemPath(fullPath);
- const tasks = maybeTasks || [];
- tasks.forEach(uploadTask => this.clientUpload(uploadTask));
- });
+ this.clientUpload(folderPaths);
+ // folderPaths.forEach(async fullPath => {
+ // const maybeTasks = await system.analyzeSystemPath(fullPath);
+ // const tasks = maybeTasks || [];
+ // tasks.forEach(uploadTask => this.clientUpload(uploadTask));
+ // });
},
/**
* 客户端上传文件
@@ -767,47 +770,70 @@ export default {
* relativePath: 相对路径
* }
*/
- clientUpload(uploadTask) {
+ async clientUpload(filePaths) { // uploadTask
+
+ const tasksGroup = await Promise.all(filePaths.map(path => system.analyzeSystemPath(path)));
+ const uploadTasks = flatten(tasksGroup);
const { folderName, levelId, id: folderId } = this.currentNodeFolder;
const { folderPath = '' } = this.currentFolder;
- const { fullPath: sourceFilePath, fileName, extension: fileExtension, relativePath } = uploadTask;
- const params = {
- projectId: this.projectId,
- projectName: this.projectName,
- folderId, folderName, folderLevelId: levelId, distFileRelativePath: `${folderPath ? `${folderPath}\\`:''}${relativePath?`${relativePath}`:''}`.replace(/(\\)+/g, '/'),
- fileName, fileExtension, sourceFilePath,
- fileList: this.workFileList,
- onSuccess: (file) => { // onSuccess
- const {ArchName, IpfsCid, Extension, RelativePath} = file;
- // 注入到文件下载检测表中
- const key = `${folderName}\\${RelativePath ? `${RelativePath.replace(/\//g, '\\')}\\`: ''}${ArchName}${Extension ? `.${Extension}`: ''}`;
- this.addLocalFileRecord(key, IpfsCid);
- this.removeFileLoadingState(file.Id);
- this.fetchFolderFiles();
- },
- onProgress: (progressData, upperUploadFile) => { // onLoading
- const { process, hash, size, currentSize, currentUnit, unit } = progressData;
- const uploadFile = firstCharToLowerCase(upperUploadFile);
- // 避免使用最后一次progreessData中size被修正为Kb的数据
- if(!hash) {
- this.updateFileLoadState(uploadFile.id, UPLOADING, process, currentSize, currentUnit, size, unit);
- }
- // 覆盖已有的同名文件
- if(uploadFile.id.indexOf('upload:') === -1) {
- return;
- }
- // 插入上传队列
- if(!this.uploadFileList.find(f => f.id === uploadFile.id)) {
- this.uploadFileList.push(uploadFile);
- }
- },
- onError: (e, upperFile) => {
- this.removeFileLoadingState(upperFile.Id);
- this.uploadFileList = this.uploadFileList.filter(iFile => iFile.id !== upperFile.Id);
- },
+ const workFileList = this.workFileList;
+ // 检查是否存在文件重名,有则提示
+ const ifHaveRepeatFile = uploadTasks.some(uploadTask => {
+ const { fileName, extension: fileExtension, relativePath } = uploadTask;
+ const extensionedFileName = fileExtension ? `${fileName}.${fileExtension}`: fileName;
+ const distFileRelativePath = `${folderPath ? `${folderPath}\\`:''}${relativePath ? `${relativePath}`:''}`.replace(/(\\)+/g, '/');
+ debugger;
+ // todo
+ return workFileList.some(iFile => distFileRelativePath === iFile.relativePath && `${iFile.archName}${iFile.extension ? `.${iFile.extension}` : ''}` === extensionedFileName)
+ });
+ if(ifHaveRepeatFile) {
+ let confirmRes = false;
+ try {
+ await Vue.prototype.$confirm('监测到文件夹存在同名文件,是否继续上传并覆盖同名文件?');
+ confirmRes = true;
+ } catch(e) { console.log('user canceled'); }
+ if(!confirmRes) return;
}
- // console.log(folderName, levelId, folderId);
- system.uploadFile(params);
+ uploadTasks.forEach(uploadTask => {
+ const { fullPath: sourceFilePath, fileName, extension: fileExtension, relativePath } = uploadTask;
+ const params = {
+ projectId: this.projectId,
+ projectName: this.projectName,
+ folderId, folderName, folderLevelId: levelId, distFileRelativePath: `${folderPath ? `${folderPath}\\`:''}${relativePath?`${relativePath}`:''}`.replace(/(\\)+/g, '/'),
+ fileName, fileExtension, sourceFilePath,
+ fileList: workFileList,
+ onSuccess: (file) => { // onSuccess
+ const {ArchName, IpfsCid, Extension, RelativePath} = file;
+ // 注入到文件下载检测表中
+ const key = `${folderName}\\${RelativePath ? `${RelativePath.replace(/\//g, '\\')}\\`: ''}${ArchName}${Extension ? `.${Extension}`: ''}`;
+ this.addLocalFileRecord(key, IpfsCid);
+ this.removeFileLoadingState(file.Id);
+ this.fetchFolderFiles();
+ },
+ onProgress: (progressData, upperUploadFile) => { // onLoading
+ const { process, hash, size, currentSize, currentUnit, unit } = progressData;
+ const uploadFile = firstCharToLowerCase(upperUploadFile);
+ // 避免使用最后一次progreessData中size被修正为Kb的数据
+ if(!hash) {
+ this.updateFileLoadState(uploadFile.id, UPLOADING, process, currentSize, currentUnit, size, unit);
+ }
+ // 覆盖已有的同名文件
+ if(uploadFile.id.indexOf('upload:') === -1) {
+ return;
+ }
+ // 插入上传队列
+ if(!this.uploadFileList.find(f => f.id === uploadFile.id)) {
+ this.uploadFileList.push(uploadFile);
+ }
+ },
+ onError: (e, upperFile) => {
+ this.removeFileLoadingState(upperFile.Id);
+ this.uploadFileList = this.uploadFileList.filter(iFile => iFile.id !== upperFile.Id);
+ },
+ }
+ // console.log(folderName, levelId, folderId);
+ system.uploadFile(params);
+ })
},
/**
* 客户端下载方法