app.js 1.0 KB
Newer Older
P
init  
Pan 已提交
1 2 3 4 5 6 7 8
import Cookies from 'js-cookie';

const app = {
  state: {
    sidebar: {
      opened: !+Cookies.get('sidebarStatus')
    },
    theme: 'default',
P
Pan 已提交
9 10
    livenewsChannels: Cookies.get('livenewsChannels') || '[]',
    visitedViews: []
P
init  
Pan 已提交
11 12 13 14 15 16 17 18 19
  },
  mutations: {
    TOGGLE_SIDEBAR: state => {
      if (state.sidebar.opened) {
        Cookies.set('sidebarStatus', 1);
      } else {
        Cookies.set('sidebarStatus', 0);
      }
      state.sidebar.opened = !state.sidebar.opened;
P
Pan 已提交
20 21 22 23 24 25 26 27
    },
    ADD_VISITED_VIEWS: (state, view) => {
      if (state.visitedViews.includes(view)) return
      state.visitedViews.push(view)
    },
    DEL_VISITED_VIEWS: (state, view) => {
      const index = state.visitedViews.indexOf(view)
      state.visitedViews.splice(index, 1)
P
init  
Pan 已提交
28 29 30 31 32
    }
  },
  actions: {
    ToggleSideBar: ({ commit }) => {
      commit('TOGGLE_SIDEBAR')
P
Pan 已提交
33 34 35 36 37 38
    },
    addVisitedViews: ({ commit }, view) => {
      commit('ADD_VISITED_VIEWS', view)
    },
    delVisitedViews: ({ commit }, view) => {
      commit('DEL_VISITED_VIEWS', view)
P
init  
Pan 已提交
39 40 41 42 43
    }
  }
};

export default app;