import Vue from "vue"
import Vuex from "vuex"
import getters from './getters'
Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		Token: uni.getStorageSync('xj-storage_token'),
		users:uni.getStorageSync('xj-storage_users'),
		auths:uni.getStorageSync('xj-storage_auth') || [],
		dataArray:[],
		doneBack:false
	},
	actions: {
		setToken({
			commit,
			state
		}, token) {
			commit("SETTOKEN", token)
		},
		setUsers({
			commit,
			state
		}, users) {
			commit("SETUSERS", users)
		},
		setAuths({
			commit,
			state
		}, auths) {
			commit("SETAUTHS", auths)
		},
		setObj({
			commit,
			state
		}, dataArray) {
			commit("SETOBJ", dataArray)
		},
		setDoneBack({
			commit,
			state
		}, doneBack) {
			commit("SETBACK", doneBack)
		},
	},
	mutations: {
		SETBACK: (state, doneBack) => {
			state.doneBack = doneBack
		},
		SETOBJ: (state, dataArray) => {
			state.dataArray = dataArray
		},
		SETTOKEN: (state, token) => {
			state.Token = token
			uni.setStorageSync("xj-storage_token", token)
		},
		SETUSERS:(state,users) =>{
			state.users = users
			uni.setStorageSync("xj-storage_users", users)
		},
		SETAUTHS:(state,auths) =>{
			state.auths = auths
			uni.setStorageSync("xj-storage_auth", auths)
		}
	},
	getters
})

export default store
