diff --git a/z_ele/src/config/setting.ts b/z_ele/src/config/setting.ts index 64bb5d0..799f78f 100644 --- a/z_ele/src/config/setting.ts +++ b/z_ele/src/config/setting.ts @@ -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'; diff --git a/z_ele/src/utils/common.ts b/z_ele/src/utils/common.ts index 1087900..c834754 100644 --- a/z_ele/src/utils/common.ts +++ b/z_ele/src/utils/common.ts @@ -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 是否使用路由跳转 diff --git a/z_ele/src/utils/request.ts b/z_ele/src/utils/request.ts index bf3eef9..fbcd20c 100644 --- a/z_ele/src/utils/request.ts +++ b/z_ele/src/utils/request.ts @@ -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) { 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; + } } /** diff --git a/z_ele/src/utils/token-util.ts b/z_ele/src/utils/token-util.ts index 7477550..1aa8894 100644 --- a/z_ele/src/utils/token-util.ts +++ b/z_ele/src/utils/token-util.ts @@ -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