import request from '@/utils/request'; import config from '@/config' const TokenKey = 'App-Token' export const isLoginSso = config.VITE_SSO_LOGIN export function getToken() { return uni.getStorageSync(TokenKey) } export function setToken(token) { return uni.setStorageSync(TokenKey, token) } export function removeToken() { return uni.removeStorageSync(TokenKey) } const SYS_CODE = 'XXLSSO'; // 单点登录Token const SsoTokenKey = 'Sso-Admin-Token'; // 获取单点登录Token export function getSsoAdminToken() { return uni.getStorageSync(SsoTokenKey); }; // 设置单点登录Token export function setSsoAdminToken(token) { return uni.setStorageSync(SsoTokenKey, token); }; // 删除单点登录Token export function removeSsoAdminToken() { return uni.removeStorageSync(SsoTokenKey); }; // 当前环境 // const VITE_APP_ENV = import.meta.env.VITE_APP_ENV; const VITE_APP_ENV = 'beta' function getEnv() { // let jumpEnv = 'http://localhost:88'; // let curEnv = 'http://localhost:81/pages'; // let suffix = 'localhost'; // if (VITE_APP_ENV == 'production') { // // 生产环境 let jumpEnv = 'https://sso.huaxiazhizao.com'; let curEnv = 'https://tools-m.huaxiazhizao.com/pages'; let suffix = '.huaxiazhizao.com'; // } else if (VITE_APP_ENV == 'beta') { // // 测试环境 // jumpEnv = 'https://sso.huabaosmart.cn'; // curEnv = 'https://sundry.huabaosmart.cn'; // suffix = '.huabaosmart.cn'; // }; return { jumpEnv, curEnv, suffix }; }; /** * 获取当前用户 Token * @param {*} SSO_CODE * @param {*} noMessage * @returns */ export function getOpenToken() { return request({ url: '/open/ex_login', method: 'get', params: { sysCode: SYS_CODE, token: getSsoAdminToken() }, noMessage: false }); }; export function ssoLogout() { removeEnv(); document.cookie = "ssoLogout=true;path=/;domain=" + getEnv().suffix; }; // 打开单点登录页面 export function openWindowSso() { // 清除单点登录Token removeSsoAdminToken(); // 清除Token removeToken(); setEnv(); // 登录失效跳转到单点登录页面 window.open(getEnv().jumpEnv, '_self'); }; // 系统退出 export function toolsLogout() { Cookies.set('tools-logout', true); }; // 设置跳转 url export function setEnv() { document.cookie = "ssoLogin=" + getEnv().curEnv + ";path=/;domain=" + getEnv().suffix; }; // 删除定点跳转cookie export function removeEnv() { var date = new Date(); date.setTime(date.getTime() - 500000); document.cookie = "ssoLogin=' ';expires=" + date.toUTCString() + "path=/;domain=" + getEnv().suffix; }; // 请求头 // let search = window.location.search; // if (search && search.length > 1) { // let arr = search.split('=') // if (arr[0] === '?token') { // let token = arr[1]; // Cookies.set('TokenKey', token); // // setToken(token) // 将token值按照子系统的方式保存下来,cookie或者localStorage均可 // window.location.href = window.location.origin // } // }