feat:redux使用map有问题改list
This commit is contained in:
parent
3a688af342
commit
3f8477aad6
|
@ -73,8 +73,12 @@ class UploadUtils {
|
||||||
// 文件存在,比较MD5值
|
// 文件存在,比较MD5值
|
||||||
let onlineMd5= data.ETag.replaceAll('"',"")
|
let onlineMd5= data.ETag.replaceAll('"',"")
|
||||||
let fileMd5
|
let fileMd5
|
||||||
if (dirMessage&&dirMessage.data&&dirMessage.data.activeFile) {
|
if (dirMessage&&dirMessage.data) {
|
||||||
fileMd5= dirMessage.data.activeFile.fileMd5;
|
console.log("dirMessage.data",JSON.parse(dirMessage.data,[]))
|
||||||
|
let find = JSON.parse(dirMessage.data,[]).find(file=>file.fileId===activeFile||file.filePath===activeFile);
|
||||||
|
if (find){
|
||||||
|
fileMd5= find.fileMd5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!fileMd5){
|
if (!fileMd5){
|
||||||
fileMd5=md5(readFileSync(activeFile).toString())
|
fileMd5=md5(readFileSync(activeFile).toString())
|
||||||
|
|
|
@ -26,7 +26,7 @@ export const dirMessageSlice = createSlice({
|
||||||
name: 'dirMessage',
|
name: 'dirMessage',
|
||||||
initialState: {
|
initialState: {
|
||||||
// 暂时只存储文件信息,不存贮文件夹信息。
|
// 暂时只存储文件信息,不存贮文件夹信息。
|
||||||
data: new Map([['root','']]),
|
data: [],
|
||||||
dirTree:new FileTree("root","/root",true,[],"root",undefined)
|
dirTree:new FileTree("root","/root",true,[],"root",undefined)
|
||||||
},
|
},
|
||||||
reducers: {
|
reducers: {
|
||||||
|
@ -38,7 +38,7 @@ export const dirMessageSlice = createSlice({
|
||||||
newFileAdd :(state,action)=>{
|
newFileAdd :(state,action)=>{
|
||||||
console.log("dirMessage:newFileAdd", state, action)
|
console.log("dirMessage:newFileAdd", state, action)
|
||||||
insertNode(state.dirTree,action.payload)
|
insertNode(state.dirTree,action.payload)
|
||||||
state.data.set(action.payload.fileId?action.payload.fileId:action.payload.filePath,action.payload)
|
state.data.push(action.payload)
|
||||||
},
|
},
|
||||||
dirRemove:(state,action)=>{
|
dirRemove:(state,action)=>{
|
||||||
console.log("dirMessage:dirRemove", state, action)
|
console.log("dirMessage:dirRemove", state, action)
|
||||||
|
@ -73,16 +73,13 @@ export const dirMessageSlice = createSlice({
|
||||||
updateNode(state.dirTree,
|
updateNode(state.dirTree,
|
||||||
{"filePath":action.payload.filePath},
|
{"filePath":action.payload.filePath},
|
||||||
{"fileMd5":action.payload.fileMd5})
|
{"fileMd5":action.payload.fileMd5})
|
||||||
console.log("state.data",...state.data)
|
|
||||||
let fileId = action.payload.fileId?action.payload.fileId:action.payload.filePath;
|
let fileId = action.payload.fileId?action.payload.fileId:action.payload.filePath;
|
||||||
if (state.data.fileIdKey){
|
let find = state.data.find(file=>file.fileId===fileId||file.filePath===fileId);
|
||||||
state.data.fileIdKey.fileMd5=action.payload.fileMd5
|
if (find){
|
||||||
|
find.fileMd5=action.payload.fileMd5
|
||||||
}else {
|
}else {
|
||||||
let newMap = new Map();
|
|
||||||
state.data.forEach((value, key) => {
|
state.data.push({
|
||||||
newMap.set(key, value);
|
|
||||||
});
|
|
||||||
newMap.set(action.payload.filePath,{
|
|
||||||
fileTitle:getFileNameByPath(action.payload.filePath),
|
fileTitle:getFileNameByPath(action.payload.filePath),
|
||||||
fileName:getFileFullNameByPath(action.payload.filePath),
|
fileName:getFileFullNameByPath(action.payload.filePath),
|
||||||
fileDir:false,
|
fileDir:false,
|
||||||
|
@ -91,17 +88,7 @@ export const dirMessageSlice = createSlice({
|
||||||
fileId:fileId,
|
fileId:fileId,
|
||||||
fileMd5:action.payload.fileMd5
|
fileMd5:action.payload.fileMd5
|
||||||
})
|
})
|
||||||
state.data=newMap
|
|
||||||
}
|
}
|
||||||
state.data.set(action.payload.filePath,{
|
|
||||||
fileTitle:getFileNameByPath(action.payload.filePath),
|
|
||||||
fileName:getFileFullNameByPath(action.payload.filePath),
|
|
||||||
fileDir:false,
|
|
||||||
children:[],
|
|
||||||
filePath:action.payload.filePath,
|
|
||||||
fileId:fileId,
|
|
||||||
fileMd5:action.payload.fileMd5
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
dirFileAdd:(state,action)=>{
|
dirFileAdd:(state,action)=>{
|
||||||
console.log("dirMessage:dirFileAdd", state, action)
|
console.log("dirMessage:dirFileAdd", state, action)
|
||||||
|
@ -112,10 +99,11 @@ export const dirMessageSlice = createSlice({
|
||||||
"fileName": fileName,
|
"fileName": fileName,
|
||||||
"filePath": filePath,
|
"filePath": filePath,
|
||||||
"dirFlag": false,
|
"dirFlag": false,
|
||||||
"children": []
|
"children": [],
|
||||||
|
"fileId":filePath
|
||||||
}
|
}
|
||||||
insertNode(state.dirTree,fileMessage)
|
insertNode(state.dirTree,fileMessage)
|
||||||
state.data.set(action.payload.fileId?action.payload.fileId:action.payload.filePath,fileMessage)
|
state.data.push(fileMessage)
|
||||||
},
|
},
|
||||||
dirDirAdd:(state,action)=>{
|
dirDirAdd:(state,action)=>{
|
||||||
console.log("dirMessage:dirDirAdd", state, action)
|
console.log("dirMessage:dirDirAdd", state, action)
|
||||||
|
|
Loading…
Reference in New Issue