import Cookies from 'js-cookie'

export const TokenKey = 'Admin-Token'
export const RefreashToken = 'Refreash-Token'

export function getToken() {
  // return Cookies.get(TokenKey)
  return sessionStorage.getItem(TokenKey)
}

export function setToken(token) {
  // return Cookies.set(TokenKey, token)
  return sessionStorage.setItem(TokenKey, token)
}

export function removeToken() {
  // return Cookies.remove(TokenKey)
  return sessionStorage.removeItem(TokenKey)
}

export function getRefreashToken() {
  // return Cookies.get(RefreashToken)
  return sessionStorage.getItem(RefreashToken)
}

export function setRefreashToken(refreashToken) {
  // return Cookies.set(RefreashToken, refreashToken)
  return sessionStorage.setItem(RefreashToken, refreashToken)
}

export function removeRefreashToken() {
  // return Cookies.remove(RefreashToken)
  return sessionStorage.removeItem(RefreashToken)
}

export function removeSessionStorage() {
  removeRefreashToken();
  removeToken();
  sessionStorage.removeItem("role");
  sessionStorage.removeItem("sysDate");
  sessionStorage.removeItem("pass");
  sessionStorage.removeItem("roleDepartment");
  sessionStorage.removeItem("user");
  sessionStorage.removeItem("depart");
}


//获取系统当前登录用户号
export function getUserNo() {
  const userNoInfo = JSON.parse(sessionStorage.getItem("user"));
  return userNoInfo.no;
}

//获取系统日期
export function getSysDate() {
  const sysDate = JSON.parse(sessionStorage.getItem("sysDate"));
  return sysDate;
}

/**
 * 获取用户编号 
 * @returns 
 */
export function getUserName() {
  const userNoInfo = JSON.parse(sessionStorage.getItem("user"));
  return userNoInfo.userName
}

/**
 * 获取用户编号
 * @returns 
 */
export function getUserKey(){
  const userNoInfo = JSON.parse(sessionStorage.getItem("user"));
  return userNoInfo.userKey
}

export function getDepartNo(){
  const departInfo = JSON.parse(sessionStorage.getItem('depart'))
  return departInfo.no;
}

export function getUpbrNo(){
  const departInfo = JSON.parse(sessionStorage.getItem('depart'))
  return departInfo.upBrNo
}
