history.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import router from "@/router";
  2. export default {
  3. state: {
  4. history:[],
  5. historyPath:[],
  6. currentPath:null,
  7. },
  8. mutations: {
  9. addHistoryPath(state,path){
  10. let paths=state.historyPath.filter(item=>{
  11. return item!==path;
  12. })
  13. paths.push(path);
  14. state.historyPath=paths;
  15. state.currentPath=path;
  16. },
  17. addHistory(state,history){
  18. if(!history.name){
  19. return
  20. }
  21. let index=-1;
  22. state.history.forEach((item,i)=>{
  23. if(item.path===history.path)
  24. index=i;
  25. })
  26. if(index!==-1){
  27. state.history[index] = history
  28. return;
  29. }
  30. state.history.push(history)
  31. },
  32. removeHistory(state,path){
  33. state.history=state.history.filter(item=>{
  34. return item.path!=path;
  35. })
  36. if(state.history.length == 0){
  37. router.push(
  38. {
  39. path:'/administrator/home',
  40. }
  41. )
  42. }
  43. },
  44. removeHistoryPath(state,path){
  45. state.historyPath=state.historyPath.filter(item=>{
  46. return item!=path;
  47. })
  48. if(state.historyPath.length>0)
  49. state.currentPath=state.historyPath[state.historyPath.length-1];
  50. else
  51. state.currentPath=null;
  52. }
  53. },
  54. actions: {
  55. }
  56. }