doum
2026-04-30 7a0b33a5f2e0ba589bf35a1b8d896700a21f94a4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Vue from 'vue'
import Vuex from 'vuex'
 
Vue.use(Vuex)
const userInfo = uni.getStorageSync('userInfo');
const token = uni.getStorageSync('token');
 
const store = new Vuex.Store({
    
    state: {
        userInfo: userInfo || null,    
        token: token || null      // token
    },
    mutations: {
        setUserInfo(state, val) {
            state.userInfo = val
            uni.setStorageSync('userInfo', val);
        },
        setToken(state, val) {
            state.token = val
            uni.setStorageSync('token', val);
        },
        clearAll(state) {
            state.userInfo = null
            state.token = null
            uni.clearStorageSync()
        }
    },
    
    actions: {
        // 获取状态高度
        // getHeight(context) {
        //     let res = uni.getMenuButtonBoundingClientRect()
        //     let status = uni.getSystemInfoSync()
        //     var height = res.height
        //     let statusbarHeight = status.statusBarHeight
        //     let navHeight = res.height + (res.top - statusbarHeight) * 2;
        //     context.commit('setHeight', { statusbarHeight, navHeight, height })
        // }
    }
    
})
 
export default store;