user.js 748 字节
Newer Older
芊里 已提交
1
// 上次启动时的用户信息
2
let userHistory = uni.getStorageSync('userInfo') || {};
芊里 已提交
3 4

let state = {
5
		/* 是否需要强制登录 */
芊里 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19
		forcedLogin: false,
		hasLogin: Boolean(userHistory),
		info: userHistory
	},
	getters = {
		info(state) {
			return state.info;
		},
		hasLogin(state){
			return state.hasLogin;
		}
	},
	mutations = {
		login(state, info) {
芊里 已提交
20 21
			let _info = state.info;
			state.info = Object.assign({}, _info, info);
芊里 已提交
22
			state.hasLogin = true;
23
			uni.setStorageSync('userInfo', state.info);
芊里 已提交
24 25
		},
		logout(state) {
26
			state.info = {};
芊里 已提交
27
			state.hasLogin = false;
28
			uni.setStorageSync('userInfo', {});
L
23  
linju 已提交
29
			uni.setStorageSync('uni_id_token', '');
芊里 已提交
30 31 32 33 34 35 36 37 38 39 40
		}
	},
	actions = {

	}
export default {
	state,
	getters,
	mutations,
	actions
}