// 用户数据模块
import http from '@/common/request/index'
import store from '@/common/store'
import tools from '@/common/utils/tools'
import wechat from '@/common/wechat/wechat'
import share from '@/common/share'

const state = {
	token: uni.getStorageSync("token") || "",
	hasLogin: uni.getStorageSync("hasLogin") || false, // 是否登陆
	userInfo: uni.getStorageSync("userInfo") || {}, // 用户信息
	userData: {}, //用户其他相关数据
	subscribeMessageIdsMap: [], //小程序订阅消息模板ids
	authType: '', // smsLogin:手机号登录注册, accountLogin:密码登录, forgotPwd:忘记密码, changePwd:修改密码, bindMobile:绑定手机号
	tabbarList: []
}

const getters = {
	token: state => state.token,
	hasLogin: state => state.hasLogin,
	tabbarList: state => state.tabbarList,

}

const actions = {
	// 获取用户信息
	login({
		commit,
		dispatch,
		getters,
		state
	}, token = '') {
		token && uni.setStorageSync('token', token);
		commit('hasLogin', true);
		console.log(token);
	},

	// 退出登录
	logout({
		commit,
		dispatch
	}) {
		commit('token', "");
		commit('hasLogin', false);
	},
}

const mutations = {
	token(state, payload) {
		state.token = payload;
		uni.setStorageSync("token", payload);
	},
	// 登录态
	hasLogin(state, data) {
		state.hasLogin = data;
		uni.setStorageSync('hasLogin', data);
	},
}



export default {
	state,
	mutations,
	actions,
	getters
}