//将TOKEN和用户信息保存到本地

import Cookies from 'js-cookie'

const TokenKey = 'ipsomc8000_token'
const UserInfoKey = "ipsomc8000_user_info"


//设置token
export function setToken(token) {
    return Cookies.set(TokenKey, token)
}

//查询token
export function getToken() {
    return Cookies.get(TokenKey)
}

//删除token
export function removeToken() {
    return Cookies.remove(TokenKey)
}

//设置用户信息
export function setUserInfo(data) {
    //将json对象转成字符串保存到本地
    return Cookies.set(UserInfoKey, JSON.stringify(data))
}

//查询用户信息
export function getUserInfo() {
    let userInfoStr = Cookies.get(UserInfoKey)
    let userInfoJson = {}

    //将本地的字符串转成json对象
    if (userInfoStr && userInfoStr.length > 0 && userInfoStr != "undefined") {
        userInfoJson = JSON.parse(userInfoStr)
    }

    return userInfoJson
}

//删除用户信息
export function removeUserInfo() {
    return Cookies.remove(UserInfoKey)
}
