import {TOKEN_KEY, TENANT_KEY} from "@/lib/config"



export function getConfig(key:string) {
  try {
	  let val = uni.getStorageSync(key);
      if(val==null || typeof(val)==='undefined' ||val==""){
		  return null
	  }
	  return val;
  } catch (e) {
	console.log("获取"+key+"出错",e);
	return null;
  }
}

export function setConfig(key:string, val: string) {
  try {
	  if(val == null || val ==""){
		  uni.setStorageSync(key, val);
		  uni.removeStorageSync(key)
		  return;
	  }
      uni.setStorageSync(key, val);
	  return;
  } catch (e) {
  	console.log("设置"+key+"出错",e);
  	return null;
  }
}



export function getToken() {
	return getConfig(TOKEN_KEY)
}

export function setToken(token: string) {
	return setConfig(TOKEN_KEY, token)
}


export function getTenant() {
	return getConfig(TENANT_KEY)
}

export function setTenant(val: string) {
	return setConfig(TENANT_KEY, val)
}

export default {
	getToken,
	setToken,
	getTenant,
	setTenant
}