|
|
@ -1,12 +1,17 @@ |
|
|
|
const state = { |
|
|
|
recentPages: [], |
|
|
|
isRecentOpen:false, |
|
|
|
isRecentOpen:"", |
|
|
|
} |
|
|
|
|
|
|
|
const mutations = { |
|
|
|
saveRecent(state){ |
|
|
|
localStorage.setItem("recentPages", JSON.stringify(state.recentPages)); |
|
|
|
}, |
|
|
|
|
|
|
|
addRecent(state, item) { |
|
|
|
|
|
|
|
if(state.recentPages.length == 0 ){ |
|
|
|
state.recentPages = JSON.parse(localStorage.getItem("recentPages") || "[]"); |
|
|
|
} |
|
|
|
let temp; |
|
|
|
state.recentPages.forEach((unit,index)=>{ |
|
|
|
if(unit.path == item.path){ |
|
|
@ -21,22 +26,38 @@ const state = { |
|
|
|
state.recentPages.push(item); |
|
|
|
} |
|
|
|
|
|
|
|
mutations.saveRecent(state); |
|
|
|
|
|
|
|
}, |
|
|
|
openRecent(state){ |
|
|
|
state.isRecentOpen = true; |
|
|
|
localStorage.setItem("isRecentOpen", true); |
|
|
|
}, |
|
|
|
closeRecent(state){ |
|
|
|
state.isRecentOpen = false; |
|
|
|
localStorage.setItem("isRecentOpen", false); |
|
|
|
}, |
|
|
|
removeRecent(state, item) { |
|
|
|
let i = state.recentPages.findIndex(unit => unit.path == item.path); |
|
|
|
state.recentPages.splice(i, 1); |
|
|
|
mutations.saveRecent(state); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const getters = { |
|
|
|
isRecentOpen(state){ |
|
|
|
if (state.isRecentOpen === ""){ |
|
|
|
state.isRecentOpen = localStorage.getItem("isRecentOpen") || false; |
|
|
|
} |
|
|
|
console.log(state.isRecentOpen); |
|
|
|
return state.isRecentOpen; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export default { |
|
|
|
namespaced: true, |
|
|
|
state, |
|
|
|
getters, |
|
|
|
mutations, |
|
|
|
} |