import { setLocal, getLocal, jump, getQueryString } from './utils' class Loginfos { // 获取user或者user属性 getLoginfo() { return getLocal('USER'); }; // 设置user setLoginfo(user: any) { return setLocal('USER', user); }; //移除 removeLoginfo() { localStorage.removeItem('USER'); } // 设置token setToken(token: string) { localStorage.setItem('SP_TOKEN', token); }; //获取token getToken() { return getLocal('USER', 'SP_TOKEN') } //移除 removeToken() { localStorage.removeItem('SP_TOKEN'); } // 设置companyId setCompanyId(id: string) { return setLocal('USER', { 'SP_COM_ID': id }); }; //获取companyId getCompanyId() { return getLocal('USER', 'SP_COM_ID'); }; // 设置mobile setMobileNo(mobile: string) { return setLocal('USER', { 'SP_PHONE_NUMBER': mobile }); }; //获取手机号 getMobileNo() { return getLocal('USER', 'SP_PHONE_NUMBER'); }; // 获取user或者user属性 getUserId() { return getLocal('USER', 'SP_USER_ID'); }; // 校验token checkToken(params?: { callback?: Function, redictUrl?: string }) { const token = getLocal('USER', 'SP_TOKEN'); if (token) { const callback = params && params.callback || null; typeof callback === 'function' && callback(); return true; } else { //没有token的情况 const redictUrl = params && params.redictUrl || ''; let isInsH = getQueryString('isInsH') || ''; let pathname = ''; if (isInsH || 'jkb.ytbxjj.com' === location.host) { pathname = '/spcare-public/health-enterprise-login/'; } else { pathname = '/spcare-public/enterprise-login/login'; } jump(pathname, redictUrl); } }; // 先校验token后校验companyId checkComId(params?: { callback?: any, redictUrl?: string }) { let token = this.checkToken(); if (token) { const companyId = getLocal('USER', 'SP_COM_ID'); if (companyId) { const callback = params && params.callback || null; typeof callback === 'function' && callback(); return true; } //没有comid的情况 const redictUrl = params && params.redictUrl || ''; let isInsH = getQueryString('isInsH') || ''; let pathname = ''; if (isInsH || 'jkb.ytbxjj.com' === location.host) { pathname = '/spcare-public/health-enterprise-login/enterpriseInfo'; } else { pathname = '/spcare-public/enterprise-login/'; } jump(pathname, redictUrl); } } } const Loginfo = new Loginfos(); export default Loginfo;