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

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		token:'',
		userInfo: {},
	},
	mutations: {
		setLogin(state, userInfo) {
			// console.log('userInfo',userInfo);
			// state.userInfo = userInfo.wechatUserInfo || {}
			state.token = userInfo.access_token
			state.hasLogin = Boolean(state.token)
			console.log(state)
			// uni.setStorage({
			// 	key: "userInfo",
			// 	data: userInfo.wechatUserInfo
			// })
			uni.setStorage({
				key: "hasLogin",
				data: true
			})
			uni.setStorage({
				key: "token",
				data: userInfo.access_token
			})
		},
		logout(state) {
			userInfo = {}
			hasLogin: false,
			uni.removeStorage({
				key: "userInfo"
			})
			uni.removeStorage({
				key: "token"
			})
		}
	},
	actions: {

	}
})

export default store
