const ACCESS_TOKEN = 'yuncheng__Access-Token';
const TokenStorageUtil = {
  get() {
    // 从本地存储中获取token
    // 如果没有，再尝试从cookie中获取
    function getCookieValue(key) {
      const regex = new RegExp(`${key}=([^;]+)`);
      const match = document.cookie.match(regex);
      return match && match[1];
    }
    let token = getCookieValue('token')
    if (localStorage.getItem(ACCESS_TOKEN)){
      token = JSON.parse(localStorage.getItem(ACCESS_TOKEN)) && JSON.parse(localStorage.getItem(ACCESS_TOKEN)).value
    }
    return token
  },
  set(token) {
    localStorage.setItem(ACCESS_TOKEN, token)
  },
  remove() {
    localStorage.removeItem(ACCESS_TOKEN)
  }
}
export default TokenStorageUtil;
