This commit is contained in:
u2nyakim 2025-08-28 13:49:59 +08:00
parent a5588c7612
commit 644e1ca050
4 changed files with 33 additions and 8 deletions

View File

@ -17,7 +17,10 @@ export const LAYOUT_PATH = '/';
export const REDIRECT_PATH = '/redirect'; export const REDIRECT_PATH = '/redirect';
/** token本地缓存的名称 */ /** 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'; export const THEME_CACHE_NAME = 'theme';

View File

@ -2,8 +2,12 @@ import type { Router } from 'vue-router';
import type { Action } from 'element-plus'; import type { Action } from 'element-plus';
import { ElMessageBox } from 'element-plus'; import { ElMessageBox } from 'element-plus';
import { removeToken } from '@/utils/token-util'; 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 使 * @param route 使

View File

@ -8,7 +8,7 @@ import { API_BASE_URL, LAYOUT_PATH } from '@/config/setting';
import type { ApiResult } from '@/api'; import type { ApiResult } from '@/api';
import router from '@/router'; import router from '@/router';
import { isWhiteList } from '@/router/routes'; import { isWhiteList } from '@/router/routes';
import { getToken, setToken } from './token-util'; import {getClientInfo, getToken, setToken} from './token-util';
import {logout, showLogoutConfirm, toURLSearch} from './common'; import {logout, showLogoutConfirm, toURLSearch} from './common';
/** /**
@ -25,9 +25,13 @@ export function requestInterceptor(config: InternalAxiosRequestConfig<any>) {
config.url = toURLSearch(config.params, config.url); config.url = toURLSearch(config.params, config.url);
config.params = {}; config.params = {};
} }
config.headers['Client'] = "PAdmin"; // 客户端信息
config.headers['Client-Id'] = 1; let clientInfo = getClientInfo();
config.headers['Client-Version'] = "1.0.0"; if(clientInfo) {
config.headers['Client'] = clientInfo.name;
config.headers['Client-Id'] = clientInfo.id;
config.headers['Client-Version'] = clientInfo.version;
}
} }
/** /**

View File

@ -1,7 +1,21 @@
/** /**
* token操作封装 * 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 * token