import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,  //代表用户授权头像等信息
		sessionId:'',
		successlogion: false, // 同意授权手机号 成功登录
		getcode: {}, // code 后获取的token session_key等值
		//showModal: false, //登录授权弹窗
		userInfo: {},
		beginload: false,
	},
	mutations: {
		login(state, provider) {
			state.userInfo = provider;
			uni.setStorage({//缓存用户登陆信息
			    key: 'userInfo',  
			    data: provider  
			}) 
			console.log(state.userInfo);
		},
		beginload(state, provider) {
			state.beginload = provider
			uni.setStorage({//缓存用户登陆信息
			    key: 'beginload',  
			    data: provider  
			}) 
		},
		setcode(state, provider) {
			uni.setStorage({//缓存用户登陆信息
			    key: 'getcode',  
			    data: provider  
			}) 
		},
		setOpenid(state, provider) {
			state.sessionId = provider;
			uni.setStorage({//缓存用户登陆状态
			    key: 'sessionId',  
			    data: provider  
			}) 
			
		},
		showDialog(state, status) {
			state.hasLogin = status;
			uni.setStorage({
			    key: 'hasLogin',  
			    data: status  
			}) 
		},
		islogionsuccess(state,provider) {
			state.successlogion = provider;
			uni.setStorage({
			    key: 'successlogion',  
			    data: provider  
			}) 
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			state.getcode = {};
			state.sessionId = '';
			uni.removeStorage({  
		        key: 'userInfo'  
		    })
			uni.removeStorage({
			    key: 'getcode'  
			})
			uni.removeStorage({
			    key: 'sessionId'  
			})
		}
	},
	
})

export default store

