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