Browse Source

workspace 文件解除工作中状态时更新文件

master
unknown 4 years ago
parent
commit
417e0b8b1c
2 changed files with 107 additions and 26 deletions
  1. +34
    -1
      src/services/system.js
  2. +73
    -25
      src/views/main_web/workspace/workspace.vue

+ 34
- 1
src/services/system.js View File

@@ -4,6 +4,7 @@
*/ */
import { fetchApi, wrapErrorHint } from '@/utils/request'; import { fetchApi, wrapErrorHint } from '@/utils/request';
import { notify, firstCharToUpperCase } from '@/utils/tool'; import { notify, firstCharToUpperCase } from '@/utils/tool';
import { identity } from 'lodash';


export const isClient = !!global.electron; // process.env.IS_CLIENT; export const isClient = !!global.electron; // process.env.IS_CLIENT;


@@ -100,7 +101,7 @@ const system = {
* + 文件上传至本地ipfs节点 * + 文件上传至本地ipfs节点
* + 将文件的ipfsCid连同文件信息发送到远端服务器 * + 将文件的ipfsCid连同文件信息发送到远端服务器
*/ */
uploadFile: safeCall(async (projectId, projectName, folderId, folderName, levelId, fileList, onSuccessHandler) => {
uploadFile: safeCall(async (projectId, projectName, folderId, folderName, levelId, fileList, onSuccessHandler, onProgressHandler = identity) => {
const { ipcRenderer } = global.electron; const { ipcRenderer } = global.electron;
const res = await ipcRenderer.invoke('project-upload-file'); const res = await ipcRenderer.invoke('project-upload-file');
console.log('ipcRenderer project-selected-upload-file: ', res); console.log('ipcRenderer project-selected-upload-file: ', res);
@@ -119,6 +120,7 @@ const system = {
console.log('receive download file message:', e); console.log('receive download file message:', e);
try { try {
const { size, process, hash } = JSON.parse(e.data); const { size, process, hash } = JSON.parse(e.data);
onProgressHandler(e);
if(process !== 100 || !hash) return; if(process !== 100 || !hash) return;
socket.close(); socket.close();
// {"size":"88.69","currentSize":"88.69","unit":"KiB","process":100,"hash":""} // {"size":"88.69","currentSize":"88.69","unit":"KiB","process":100,"hash":""}
@@ -176,6 +178,37 @@ const system = {
} }
}); });
}), }),
/**
* 更新本地文件
*/
updateFile: safeCall((file, localFilePathPrefix, projectName, folderName, onSuccessHandler, onProgressHandler = identity) => {
const socket = io('upload');
const { archName, extension, id: fileId } = file;
const extensionedFileName = `${archName}${extension ? `.${extension}` : ''}`;
const filePath = `${localFilePathPrefix}\\${folderName}\\${extensionedFileName}`;
socket.on('open', () => {
const data = [filePath, extensionedFileName, projectName, folderName].join('|');
socket.send(data);
});
socket.on('message', async (e) => {
try {
const progressData = JSON.parse(e.data);
const { size, process, hash } = progressData;
onProgressHandler(progressData);
if(process !== 100 || !hash) return;
socket.close();
const copyFile = firstCharToUpperCase({ ...file, ipfsCid: hash, ModifyUserId: sessionStorage.userId });

const res = await fetchApi('file/updateFile', copyFile);
wrapErrorHint(res);
if(res.Code === 0) { notify.success(`${archName} 更新成功`); }
onSuccessHandler(copyFile);
return;
} catch(err) {
console.error('socket-update-file parse data have error:', e);
}
});
}),
/** /**
* 系统打开文件 * 系统打开文件
*/ */


+ 73
- 25
src/views/main_web/workspace/workspace.vue View File

@@ -563,6 +563,20 @@
<div class="minifont">下载中 {{file.loadProgress}}</div> <div class="minifont">下载中 {{file.loadProgress}}</div>
</span> </span>
</div> </div>
<div
@contextmenu.prevent.stop="
rightShowMenu($event, file, 1)
"
class="downloadIcon"
v-if="
isClient && file.downloadStatus === 3
"
>
<span class="spanjuzhong">
<i class="el-icon-loading largeicon"></i>
<div class="minifont">上传中 {{file.loadProgress}}</div>
</span>
</div>
<div <div
v-if="file.status == 1" v-if="file.status == 1"
class="yijianxietong isonselect_defual" class="yijianxietong isonselect_defual"
@@ -2616,9 +2630,20 @@ const DownloadStatus = {
*/ */
DOWNLOADING: 1, DOWNLOADING: 1,
/** /**
* 已下载
* 已下载/已上传
*/ */
DOWNLOADED: 2
DOWNLOADED: 2,
/**
* 上传中
*/
UPLOADING: 3,
}
/**
* 文件工作状态
*/
const FileWorkStatus = {
NOT_WORKING: 1,
WORKING: 2,
} }


const fileIsDownloaded = file => file.downloadStatus === DownloadStatus.DOWNLOADED; const fileIsDownloaded = file => file.downloadStatus === DownloadStatus.DOWNLOADED;
@@ -2862,7 +2887,7 @@ export default {
localWorkspacePrefix: '', // 本地工作目录前缀 localWorkspacePrefix: '', // 本地工作目录前缀
socketIns: null, // 监听文件变化的socket实例 socketIns: null, // 监听文件变化的socket实例
projectName: sessionStorage.projName, projectName: sessionStorage.projName,
fileDownloadStatusHash: {},
fileDownloadStatusHash: {}, // 文件上传/下载状态存储
folderMap: {}, // 文件夹id哈希: { [folderId]: folder } folderMap: {}, // 文件夹id哈希: { [folderId]: folder }
fileLocalStateMap: {}, // 本地网关文件通信数据缓存: { [fileId]: { } } fileLocalStateMap: {}, // 本地网关文件通信数据缓存: { [fileId]: { } }
}; };
@@ -2969,7 +2994,7 @@ export default {
file.downloadStatus = DownloadStatus.DOWNLOADED; file.downloadStatus = DownloadStatus.DOWNLOADED;
ifModify = true; ifModify = true;
} }
if(stateMap[file.id] && file.downloadStatus !== DownloadStatus.DOWNLOADED) {
if(stateMap[file.id]) {
Object.assign(file, stateMap[file.id]); Object.assign(file, stateMap[file.id]);
ifModify = true; ifModify = true;
} }
@@ -3303,27 +3328,50 @@ export default {
// console.log(error); // console.log(error);
// }); // });
// }, // },
async updateFileWorkStatus(file, workStatus, message) {
// const params = {
// FolderId: file.folderId,
// FileId: file.id,
// UserId: this.userId,
// FileStatus: file.status
// }
// file.loadingProgress = 0;
const [resFlag] = await Promise.all([
services.changeFileWorkStatus(file.id, workStatus),
// services.fileCoordinationChange(params)
]);
if(resFlag.Code !== 0) return;
notify.success(message);
file.workStatus = workStatus;
this.$forceUpdate();
async updateFileWorkStatus(file, nextWorkStatus, message) {
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);
this.$forceUpdate();
return;
}
// 仅当文件从工作中变成非工作状态时执行下面的代码
// todo 获取文件最新的hash并更新文件 // todo 获取文件最新的hash并更新文件
// if(workStatus === 1 && file.workStatus === 2) {
// }
const { folderName, levelId, id: folderId } = this.nowFolder;
const { archName, extension, id: fileId } = file;
const stateMap = this.fileLocalStateMap;
const updateState = {
loadProgress: 0,
downloadStatus: DownloadStatus.UPLOADING,
isDownload: true,
};
stateMap[fileId] = updateState;
this.refreshFileStatus();
// const fileList = this.currentPageType === 0 ? this.folderFileList.listMyFiles : this.folderFileList.listOtherFiles;
const fileKey = `${folderName}\\${archName}${extension ? `.${extension}`:''}`;
system.updateFile(
file, this.localWorkspacePrefix,
this.projectName, folderName,
async (fileNewState) => {
const [resFlag] = await services.changeFileWorkStatus(file.id, nextWorkStatus);
notify.success(message);
const {IpfsCid} = fileNewState;
// 注入到文件下载检测表中
this.fileDownloadStatusHash[fileKey] = IpfsCid;
this.refreshFileStatus();
},
(progressData) => {
const { process, hash } = progressData;
const updateState = {
loadProgress: process,
downloadStatus: process === 100 ? DownloadStatus.DOWNLOADED : DownloadStatus.UPLOADING,
isDownload: true,
};
stateMap[fileId] = updateState;
this.refreshFileStatus();
},
);
}, },
/** /**
* 更改文件状态 * 更改文件状态
@@ -4755,7 +4803,7 @@ export default {
const { folderName, levelId, id: folderId } = nowFolder; const { folderName, levelId, id: folderId } = nowFolder;
// console.log(folderName, levelId, folderId); // console.log(folderName, levelId, folderId);
system.uploadFile( system.uploadFile(
sessionStorage.projId,sessionStorage.projName, folderId, folderName, levelId, this.myFilesList,
sessionStorage.projId, sessionStorage.projName, folderId, folderName, levelId, this.myFilesList,
(file) => { (file) => {
const {ArchName, IpfsCid} = file; const {ArchName, IpfsCid} = file;
// 注入到文件下载检测表中 // 注入到文件下载检测表中


Loading…
Cancel
Save