import Vue from 'vue'
import Vuex from 'vuex'
import sdk from "../sdk/index"

Vue.use(Vuex)

export default new Vuex.Store({
	strict: true,
	state: {
		token: localStorage.getItem("token"),
		publicConfig: localStorage.getItem("publicConfig")? localStorage.getItem("publicConfig"):[],
		loginIp:localStorage.getItem("loginIp"),
	},
	getters: {
		token: state => state.token,
		publicConfig:state => state.publicConfig,
		loginIp: state=>state.loginIp
	},
	mutations: {
		setToken(state, token) {
			state.token = token
		},
		// 保存公共配置
		savaPublicConfig(state, parmas) {
			console.log(parmas)
			state.publicConfig = parmas
		},
		setLoginIp(state,param) {
			state.loginIp = param
		}
	},
	actions: {
		login({ commit }, token) {
			commit('setToken', token)
			// commit('route/ROUTE_CHANGED',{to: {path: '/'}})
		},
		fetch({ state }, params) {
			sdk.fetch(params, state.token)
		},
		upload({ state }, params) {
			return sdk.uploadCustom(params, state.token)
		}
		
	}
})
