import store from '@/store/index.js'
const tokenKey = 'user_access_token'; //键值
// token
const getAccessToken = function() {
	let token = store.state.user_access_token ? store.state.user_access_token : uni.getStorageSync(tokenKey);
	try {
		token = token?token:''
	} catch (e) {}
	return token;
}
const setAccessToken = (access_token) => {
	try {
		uni.setStorageSync(tokenKey, access_token);
		store.commit('USERACCESSTOKEN',access_token);
		return true;
	} catch (e) {
		return false;
	}
}
const clearAccessToken = function() {
	try {
		uni.removeStorageSync(tokenKey);
		store.commit(tokenKey,'');
	} catch (e) {}
}
//用户key
const getUserKey = function() {
	let userKey = store.state.user_key ? store.state.user_key : uni.getStorageSync('user_key');
	try {
		userKey = userKey?userKey:''
	} catch (e) {}
	return userKey;
}
const setUserKey = (user_key) => {
	try {
		uni.setStorageSync('user_key', user_key);
		store.commit('USERKEY',user_key);
		return true;
	} catch (e) {
		return false;
	}
}
const clearUserKey = function() {
	try {
		uni.removeStorageSync('user_key');
		store.commit('USERKEY','');
	} catch (e) {}
}

export default {
	getAccessToken,
	setAccessToken,
	clearAccessToken,
	getUserKey,
	setUserKey,
	clearUserKey
}
