Browse Source

feat: 优化前端

xiansin 2 năm trước cách đây
mục cha
commit
59ac9a61c8
3 tập tin đã thay đổi với 34 bổ sung0 xóa
  1. 1 0
      mini/store/getters.js
  2. 2 0
      mini/store/index.js
  3. 31 0
      mini/store/modules/tab.js

+ 1 - 0
mini/store/getters.js

xqd
@@ -2,6 +2,7 @@
 const getters = {
   token: state => state.user.token,
   userInfo: state => state.user.info,
+  tabIndex: state => state.tab.index
 }
 export default getters
 

+ 2 - 0
mini/store/index.js

xqd
@@ -2,12 +2,14 @@ import Vue from 'vue'
 import Vuex from 'vuex'
 import getters from './getters'
 import user from './modules/user'
+import tab from './modules/tab'
 
 Vue.use(Vuex)
 
 const store = new Vuex.Store({
   modules: {
     user,
+    tab
   },
   getters
 })

+ 31 - 0
mini/store/modules/tab.js

xqd
@@ -0,0 +1,31 @@
+import Cache from '@/utils/cache'
+import Constant from '@/utils/constant'
+const val = Cache.get(Constant.CACHE_TAB_SELECTED)
+const getDefaultState = () => {
+  return {
+    index: val === undefined ? 1 : val
+  }
+}
+
+const state = getDefaultState()
+
+const mutations = {
+  SET_INDEX: (state, index) => {
+    Cache.set(Constant.CACHE_TAB_SELECTED, index)
+    state.index = index
+  }
+}
+
+const actions = {
+  index({ commit }, index) {
+    commit('SET_INDEX', index)
+  }
+}
+
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions
+}
+