import Vue from 'vue';
import Vuex from 'vuex';
import {
	getUserInfo
} from '../api';

Vue.use(Vuex);
const store = new Vuex.Store({
	state: {
		userInfo: uni.getStorageSync('userInfo'),
		userId: uni.getStorageSync('userId'),
		isLogin: uni.getStorageSync('isLogin'),
		websitData: uni.getStorageSync('websitData'),
	},
	mutations: {
		changeWebsitObj(state, value) {
			state.websitData = value;
		},
		changeIsLogin(state, bol) {
			state.isLogin = bol;
		},
		changeUserInfo(state, value) {
			state.userInfo = value;
		},
		changeUserId(state, value) {
			state.userId = value;
		},
	},
	actions: {
		resetUserInfo({
			commit
		}) {
			return getUserInfo().then((res) => {
				const {user} = res.data;
				commit('changeUserInfo', user);
				return Promise.resolve(user);
			})
		},
	}
})

export default store;
