user.js 759 字节
Newer Older
芊里 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
// 上次启动时的用户信息
let userHistory = uni.getStorageSync('userInfo') || null;

let state = {
		/**
		 * 是否需要强制登录
		 */
		forcedLogin: false,
		hasLogin: Boolean(userHistory),
		info: userHistory
	},
	getters = {
		info(state) {
			return state.info;
		},
		hasLogin(state){
			return state.hasLogin;
		}
	},
	mutations = {
		login(state, info) {
芊里 已提交
22 23
			let _info = state.info;
			state.info = Object.assign({}, _info, info);
芊里 已提交
24 25 26 27 28 29 30
			state.hasLogin = true;
			uni.setStorageSync('userInfo', info);
		},
		logout(state) {
			state.info = null;
			state.hasLogin = false;
			uni.setStorageSync('userInfo', null);
L
23  
linju 已提交
31
			uni.setStorageSync('uni_id_token', '');
芊里 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44
		}
	},
	actions = {

	}


export default {
	state,
	getters,
	mutations,
	actions
}