keepAlive.js 728 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * @Author: Badguy
  3. * @Date: 2022-03-08 17:31:03
  4. * @LastEditTime: 2022-05-17 20:14:20
  5. * @LastEditors: your name
  6. * @Description: 页面缓存
  7. * have a nice day!
  8. */
  9. const state = {
  10. clickedCells: JSON.parse(sessionStorage.getItem('clickedCells')) || []
  11. }
  12. const mutations = {
  13. ADD_CLICKED_CELL(state, cell) {
  14. state.clickedCells.some(item =>
  15. Object.keys(item).every(key => {
  16. item[key] === cell[key]
  17. })
  18. ) || (state.clickedCells.push(cell), sessionStorage.setItem('clickedCells', JSON.stringify(state.clickedCells)))
  19. }
  20. }
  21. const actions = {
  22. addClickedCell({ commit }, cell) {
  23. commit('ADD_CLICKED_CELL', cell)
  24. }
  25. }
  26. export default {
  27. namespaced: true,
  28. state,
  29. mutations,
  30. actions
  31. }