MrShi
17 小时以前 47d56a8b0f22fb15a46b69dfd46fac23560ad2cd
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import Vue from 'vue'
import Vuex from 'vuex'
 
Vue.use(Vuex)
 
const navHeight = uni.getStorageSync('navHeight');
const statusbarHeight = uni.getStorageSync('statusbarHeight');
const userInfo = uni.getStorageSync('userInfo');
const shopInfo = uni.getStorageSync('shopInfo');
const openid = uni.getStorageSync('openid');
const token = uni.getStorageSync('token');
const recuserid = uni.getStorageSync('recuserid');
const recshopid = uni.getStorageSync('recshopid');
const shopToken = uni.getStorageSync('shopToken');
 
 
const store = new Vuex.Store({
    
    state: {
        imgUrl: 'https://mall.dynometacn.com/dmmall_web_api/',      // 服务器资源前缀
        navHeight: navHeight || '',
        statusbarHeight: statusbarHeight || '',
        userInfo: userInfo || '',      // 用户信息
        shopInfo: shopInfo || '',      // 用户信息
        token: token || '',
        shopToken: shopToken || '',
        openid: openid || '',
        position: null,
        recuserid:recuserid||'',
        recshopid:recshopid||'',
    },
    mutations: {
        // 设置导航栏高度
        setHeight(state, val) {
            state.navHeight = val.navHeight
            state.statusbarHeight = val.statusbarHeight
            uni.setStorageSync('navHeight', val.navHeight);
            uni.setStorageSync('statusbarHeight', val.statusbarHeight);
        },
        // 设置token
        setToken(state, val) {
            state.token = val
            uni.setStorageSync('token', val);
        },
        setShopToken(state, val) {
            state.shopToken = val
            uni.setStorageSync('shopToken', val);
        },
        // 设置openid
        setOpenId(state, openid) {
            state.openid = openid
            uni.setStorageSync('openid', openid);
        },
        setRecUserId(state, recuserid) {
            state.recuserid = recuserid
            uni.setStorageSync('recuserid', recuserid);
        },
        setRecShopId(state, recshopid) {
            state.recshopid = recshopid
            uni.setStorageSync('recshopid', recshopid);
        },
        // 设置用户信息
        setUserInfo(state, val) {
            state.userInfo = val
            uni.setStorageSync('userInfo', val);
        },
        setShopInfo(state, val) {
            state.shopInfo = val
            uni.setStorageSync('shopInfo', val);
        },
        // 设置当前位置信息
        setPosition(state, val) {
            state.position = val
        },
        // 退出
        clear(state) {
            state.userInfo = ''
            state.token = ''
            state.openid = ''
            uni.removeStorageSync('userInfo');
            uni.removeStorageSync('token');
            uni.removeStorageSync('openid');
            uni.removeStorageSync('recshopid');
            uni.removeStorageSync('recuserid');
        },
        // 登录过期
        guoqi(state) {
            state.userInfo = ''
            state.token = ''
            state.openid = ''
            state.shopInfo = ''
            state.shopToken = ''
            state.recshopid = ''
            state.recuserid = ''
            
            uni.removeStorageSync('userInfo');
            uni.removeStorageSync('token');
            uni.removeStorageSync('openid');
            uni.removeStorageSync('shopInfo');
            uni.removeStorageSync('shopToken');
            uni.removeStorageSync('recshopid');
            uni.removeStorageSync('recuserid');
        }
    },
    
    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;