/**
 * 设置token
 * */
import { isJSON } from '@/webPublic/one_stop_public/copy';
import { getOneStopMyInfo } from '@/webPublic/one_stop_public/utils/utils';

export function setToken(value, time){
  if(getToken() !== value){
    localStorage.setItem('antd-pro-token-onestop', value);
    localStorage.setItem('antd-pro-token', value);
    localStorage.setItem('wisdom-school-token', value);
    getOneStopMyInfo();
  }
}

/**
 * 获取token
 * */
export function getToken(){
  const x = localStorage.getItem('antd-pro-token-onestop');
  if (x && x.length > 11) {
    return x;
  }
  const y = localStorage.getItem('antd-pro-token');
  if (y && y.length > 11) {
    return y;
  }

  return null;
}

/**
 * 删除token
 * */
export const delToken = () => {
  localStorage.removeItem('antd-pro-token-onestop');
  localStorage.removeItem('antd-pro-token');
  localStorage.removeItem('wisdom-school-token');
};

export const getUserInfo = () => {
  let x = localStorage.getItem('user');
  if(isJSON(x)){
    x = JSON.parse(x);
    if(!x.groupsId){
      x.groupsId = 'pub';
    }
    return x;
  }else{
    return {
      groupsId: 'pub',
    };
  }
};
