import { getState, setState } from '@/store/modules/vuexStorange'

/** 基本用户信息 */
const state = {
	basicUser: null,
	user: null
}

const getters = {
	// 基本用户信息
	getBasicUser: (state) => {
	 getState(state, 'basicUser', 'basicUser')
		return state.basicUser
	},
	// 后台管理用户信息
	getUser: (state) => {
		getState(state, 'user', 'userInfo')
		return state.user
	}
}

const actions = {
	// 基本用户信息
	setBasicUser({
		commit,
		dispatch,
		getters,
		rootGetters,
		rootState,
		state
	}, userInfo) {
		commit('SET_BASIC_USER', userInfo)
	},
	delBasicUser({
		commit,
		dispatch,
		getters,
		rootGetters,
		rootState,
		state
	}) {
		commit('DEL_BASIC_USER')
	},
	// 后台管理用户信息
	setUser({
		commit,
		dispatch,
		getters,
		rootGetters,
		rootState,
		state
	}, userInfo) {
		commit('SET_USER', userInfo)
	},
	delUser({
		commit,
		dispatch,
		getters,
		rootGetters,
		rootState,
		state
	}) {
		commit('DEL_USER')
	}
}

const mutations = {
	// 基本用户信息
	SET_BASIC_USER(state, userInfo = {}) {
		setState(state, userInfo, 'basicUser', 'basicUser')
	},
	DEL_BASIC_USER(state) {
		state.basicUser = ''
	},
	// 后台管理用户信息
	SET_USER(state, userInfo = {}) {
		setState(state, userInfo, 'user', 'userInfo')
	},
	DEL_USER(state) {
		state.user = ''
	}
}

export default {
	state,
	getters,
	actions,
	mutations
}
