123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- 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
- // }
- // }
|