up.
This commit is contained in:
parent
a5588c7612
commit
644e1ca050
@ -17,7 +17,10 @@ export const LAYOUT_PATH = '/';
|
||||
export const REDIRECT_PATH = '/redirect';
|
||||
|
||||
/** token本地缓存的名称 */
|
||||
export const TOKEN_CACHE_NAME = 'token';
|
||||
export const TOKEN_CACHE_NAME = '--token';
|
||||
|
||||
/** clientId本地缓存的名称 */
|
||||
export const CLIENT_ID_CACHE_NAME = '--client-id';
|
||||
|
||||
/** 主题配置本地缓存的名称 */
|
||||
export const THEME_CACHE_NAME = 'theme';
|
||||
|
||||
@ -2,8 +2,12 @@ import type { Router } from 'vue-router';
|
||||
import type { Action } from 'element-plus';
|
||||
import { ElMessageBox } from 'element-plus';
|
||||
import { removeToken } from '@/utils/token-util';
|
||||
import { userLogout } from '@/api/layout';
|
||||
|
||||
export function generateGUID() {
|
||||
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
|
||||
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
||||
);
|
||||
}
|
||||
/**
|
||||
* 退出登录
|
||||
* @param route 是否使用路由跳转
|
||||
|
||||
@ -8,8 +8,8 @@ import { API_BASE_URL, LAYOUT_PATH } from '@/config/setting';
|
||||
import type { ApiResult } from '@/api';
|
||||
import router from '@/router';
|
||||
import { isWhiteList } from '@/router/routes';
|
||||
import { getToken, setToken } from './token-util';
|
||||
import { logout, showLogoutConfirm, toURLSearch } from './common';
|
||||
import {getClientInfo, getToken, setToken} from './token-util';
|
||||
import {logout, showLogoutConfirm, toURLSearch} from './common';
|
||||
|
||||
/**
|
||||
* 请求拦截处理
|
||||
@ -25,9 +25,13 @@ export function requestInterceptor(config: InternalAxiosRequestConfig<any>) {
|
||||
config.url = toURLSearch(config.params, config.url);
|
||||
config.params = {};
|
||||
}
|
||||
config.headers['Client'] = "PAdmin";
|
||||
config.headers['Client-Id'] = 1;
|
||||
config.headers['Client-Version'] = "1.0.0";
|
||||
// 客户端信息
|
||||
let clientInfo = getClientInfo();
|
||||
if(clientInfo) {
|
||||
config.headers['Client'] = clientInfo.name;
|
||||
config.headers['Client-Id'] = clientInfo.id;
|
||||
config.headers['Client-Version'] = clientInfo.version;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,7 +1,21 @@
|
||||
/**
|
||||
* token操作封装
|
||||
*/
|
||||
import { TOKEN_CACHE_NAME } from '@/config/setting';
|
||||
import { TOKEN_CACHE_NAME, CLIENT_ID_CACHE_NAME } from '@/config/setting';
|
||||
import {generateGUID} from "@/utils/common";
|
||||
|
||||
export function getClientInfo() {
|
||||
let clientId = localStorage.getItem(CLIENT_ID_CACHE_NAME);
|
||||
if (!clientId) {
|
||||
clientId = generateGUID();
|
||||
localStorage.setItem(CLIENT_ID_CACHE_NAME, clientId);
|
||||
}
|
||||
return {
|
||||
name: 'PAdmin',
|
||||
id: clientId,
|
||||
version: "1.0.0"
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存的token
|
||||
|
||||
Loading…
Reference in New Issue
Block a user