/*
 * @Author: Zp 管理登录令牌、cookie
 * @Date: 2020-03-12 11:42:19
 * @Last Modified by: Zp
 * @Last Modified time: 2020-03-30 09:40:49
 */

import Cookie from 'js-cookie'

// 设置存储 cookie 的键值
const TokenKey = 'Authorization'

// Token
export function getToken() {
  return Cookie.get(TokenKey)
}

export function setToken(token) {
  return Cookie.set(TokenKey, token)
}

export function removeToken() {
  return Cookie.remove(TokenKey)
}

// 用户名
export function getUserName() {
  return Cookie.get('userName')
}

export function setUserName(userName) {
  return Cookie.set('userName', userName)
}

// 权限列表
export function getRoleList() {
  return Cookie.get('roleList')
}

export function setRoleList(roleList) {
  return Cookie.set('roleList', roleList)
}

const AdminsKey = 'admin_key'

export function setAdmin (data) {
  return Cookie.set(AdminsKey, JSON.stringify(data))
}

export function getAdmin () {
  const admin = Cookie.get(AdminsKey)
  return admin ? JSON.parse(admin) : ''
}