|
|
@@ -451,16 +451,20 @@ export default { |
|
|
|
this.workFileList = injectionFileLocalStatus(this.workFileList, fileStatusHash, stateMap, folderMap); |
|
|
|
this.cooperationFileList = injectionFileLocalStatus(this.cooperationFileList, fileStatusHash, stateMap, folderMap); |
|
|
|
}, |
|
|
|
updateFileLoadState(file, progress){ |
|
|
|
updateFileLoadState(file, progress, type){ |
|
|
|
const stateMap = this.fileLocalStateMap; |
|
|
|
const updateState = { |
|
|
|
loadProgress: progress, |
|
|
|
downloadStatus: DownloadStatus.DOWNLOADING, |
|
|
|
downloadStatus: type === 'download' ? DownloadStatus.DOWNLOADING : DownloadStatus.UPLOADING, |
|
|
|
}; |
|
|
|
stateMap[file.id] = updateState; |
|
|
|
this.fileLocalStateMap = { ...stateMap, [file.id]: updateState }; |
|
|
|
this.refreshFileStatus(); |
|
|
|
}, |
|
|
|
removeFileLoadingState(fileId) { |
|
|
|
delete this.fileLocalStateMap[fileId]; |
|
|
|
this.fileLocalStateMap = {...this.fileLocalStateMap}; |
|
|
|
this.refreshFileStatus(); |
|
|
|
}, |
|
|
|
|
|
|
|
/* 工作链API */ |
|
|
|
/** |
|
|
|
* 工作链页面点击 |
|
|
@@ -586,6 +590,7 @@ export default { |
|
|
|
this.fileLocalStateMap, |
|
|
|
this.folderMap, |
|
|
|
); |
|
|
|
this.resolveUploadFileList(this.cooperationFileList); |
|
|
|
}, |
|
|
|
/** |
|
|
|
* 点击确定 保存文件夹组 |
|
|
@@ -706,9 +711,10 @@ export default { |
|
|
|
clientDownLoad: function (file, type) { |
|
|
|
if(!this.isClient) return; |
|
|
|
console.log('下载的文件对象', file); |
|
|
|
const { ipfsCid, archName: fileName, extension, folderId } = file; |
|
|
|
const { ipfsCid, archName: fileName, extension, folderId, nodeName } = file; |
|
|
|
const folderMap = this.folderMap; |
|
|
|
const { folderName, levelId } = folderMap[folderId] || {}; |
|
|
|
// const { levelId } = folderMap[folderId] || {}; |
|
|
|
const nodeFolderName = nodeName || this.currentNodeFolder.folderName; |
|
|
|
const extensionedFileName = `${fileName}${extension ? `.${extension}`:''}`; |
|
|
|
const copyFile = { ...file }; |
|
|
|
const errorHandler = () => { |
|
|
@@ -717,19 +723,19 @@ export default { |
|
|
|
delete this.fileLocalStateMap[file.id]; |
|
|
|
this.refreshFileStatus(); |
|
|
|
} |
|
|
|
this.updateFileLoadState(file, 0); |
|
|
|
system.downloadFile(ipfsCid, sessionStorage.projName, extensionedFileName, folderName, (resMessage, socketIns) => { |
|
|
|
this.updateFileLoadState(file, 0, 'download'); |
|
|
|
system.downloadFile(ipfsCid, sessionStorage.projName, extensionedFileName, nodeFolderName, (resMessage, socketIns) => { |
|
|
|
console.log('receive download file message:', resMessage, socketIns); |
|
|
|
// {"size":"11","currentSize":"11","unit":"B","process":100,"hash":""} |
|
|
|
try { |
|
|
|
const { process } = JSON.parse(resMessage.data); |
|
|
|
this.updateFileLoadState(file, process); |
|
|
|
if(resMessage.data === '-1') { throw 'download failed'; } |
|
|
|
this.updateFileLoadState(file, process, 'download'); |
|
|
|
if(process !== 100) return; |
|
|
|
socketIns.close(); |
|
|
|
// file.downloadStatus = 2; |
|
|
|
// file.isDownload = true; |
|
|
|
// 注入到文件下载检测表中 |
|
|
|
const key = `${folderName}\\${extensionedFileName}`; |
|
|
|
const key = `${nodeFolderName}\\${extensionedFileName}`; |
|
|
|
this.fileDownloadStatusHash[key] = ipfsCid; |
|
|
|
this.refreshFileStatus(); |
|
|
|
notify.success(`文件:${fileName} 下载完成`); |
|
|
@@ -737,6 +743,8 @@ export default { |
|
|
|
} catch (e) { |
|
|
|
console.error('socket-download-file parse data have error:', e); |
|
|
|
errorHandler(); |
|
|
|
} finally { |
|
|
|
socketIns.close(); |
|
|
|
} |
|
|
|
}, errorHandler); |
|
|
|
}, |
|
|
@@ -777,7 +785,7 @@ export default { |
|
|
|
* 更新文件 |
|
|
|
*/ |
|
|
|
async updateFileWorkStatus(file, nextWorkStatus, message) { |
|
|
|
if(!this.isClient || nextWorkStatus === FileWorkStatus.WORKING && file.workStatus === FileWorkStatus.NOT_WORKING) { |
|
|
|
if(!this.isClient || (nextWorkStatus === FileWorkStatus.WORKING && file.workStatus === FileWorkStatus.NOT_WORKING)) { |
|
|
|
const resFlag = await services.changeFileWorkStatus(file.id, nextWorkStatus); |
|
|
|
if(resFlag.Code !== 0) return; |
|
|
|
notify.success(message); |
|
|
@@ -788,16 +796,11 @@ export default { |
|
|
|
// todo 获取文件最新的hash并更新文件 |
|
|
|
const { folderName, levelId, id: folderId } = this.currentNodeFolder; |
|
|
|
const { archName, extension, id: fileId } = file; |
|
|
|
const stateMap = this.fileLocalStateMap; |
|
|
|
const updateState = { |
|
|
|
loadProgress: 0, |
|
|
|
downloadStatus: DownloadStatus.UPLOADING, |
|
|
|
isDownload: true, |
|
|
|
}; |
|
|
|
stateMap[fileId] = updateState; |
|
|
|
this.refreshFileStatus(); |
|
|
|
this.updateFileLoadState(file, 0, 'upload'); |
|
|
|
// const fileList = this.currentPageType === 0 ? this.folderFileList.listMyFiles : this.folderFileList.listOtherFiles; |
|
|
|
const fileKey = `${folderName}\\${archName}${extension ? `.${extension}`:''}`; |
|
|
|
this.fileDownloadStatusHash[fileId] = `${file.localIpfsCid}--upload`; |
|
|
|
this.refreshFileStatus(); |
|
|
|
system.updateFile( |
|
|
|
file, this.localWorkspacePrefix, |
|
|
|
this.projectName, folderName, |
|
|
@@ -808,17 +811,11 @@ export default { |
|
|
|
const {IpfsCid} = fileNewState; |
|
|
|
// 注入到文件下载检测表中 |
|
|
|
this.fileDownloadStatusHash[fileKey] = IpfsCid; |
|
|
|
this.refreshFileStatus(); |
|
|
|
this.removeFileLoadingState(fileId); |
|
|
|
}, |
|
|
|
(progressData) => { |
|
|
|
const { process, hash } = progressData; |
|
|
|
const updateState = { |
|
|
|
loadProgress: process, |
|
|
|
downloadStatus: process === 100 ? DownloadStatus.DOWNLOADED : DownloadStatus.UPLOADING, |
|
|
|
isDownload: true, |
|
|
|
}; |
|
|
|
stateMap[fileId] = updateState; |
|
|
|
this.refreshFileStatus(); |
|
|
|
this.updateFileLoadState(file, process, 'upload'); |
|
|
|
}, |
|
|
|
); |
|
|
|
}, |
|
|
@@ -832,14 +829,14 @@ export default { |
|
|
|
const folderName = nodeName || this.currentFolder.folderName; |
|
|
|
const localWorkspacePrefix = this.localWorkspacePrefix; |
|
|
|
const filePath = `${localWorkspacePrefix}\\${folderName}\\${archName}${extension ? `.${extension}` : ''}`; |
|
|
|
|
|
|
|
if(file.workStatus === 2 && sessionStorage.userId !== file.modifyUserId) { |
|
|
|
const isCooperationFile = !!nodeName; |
|
|
|
if(!isCooperationFile && (file.workStatus === 2 && sessionStorage.userId !== file.modifyUserId)) { |
|
|
|
notify.warning('文件正在工作编辑中,请耐心等待'); |
|
|
|
return; |
|
|
|
} |
|
|
|
system.openFile(filePath); |
|
|
|
// 若文件在协作文件中,则不更改状态 |
|
|
|
if(nodeName) { return; } |
|
|
|
if(isCooperationFile) { return; } |
|
|
|
// 将文件状态设置为编辑中 |
|
|
|
const flagRes = await services.changeFileWorkStatus(fileId, 2); |
|
|
|
if(flagRes.Code !== 0) return; |
|
|
|