up. 双向数据加密
This commit is contained in:
parent
12b16e56d7
commit
8514062951
@ -34,5 +34,8 @@ export const MAP_KEY = '006d995d433058322319fa797f2876f5';
|
||||
/** EleAdminPlus授权码 */
|
||||
export const LICENSE_CODE = import.meta.env.VITE_LICENSE;
|
||||
|
||||
|
||||
/** 数据加密key */
|
||||
export const DATA_SECRET_KEY = "mySecretKey123!"
|
||||
|
||||
/** 请求加密开关 */
|
||||
export const REQUEST_ENCRYPTION = import.meta.env.REQUEST_ENCRYPTION;
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
import axios from 'axios';
|
||||
import type { AxiosResponse, InternalAxiosRequestConfig, Method } from 'axios';
|
||||
import { unref } from 'vue';
|
||||
import { API_BASE_URL, LAYOUT_PATH, DATA_SECRET_KEY } from '@/config/setting';
|
||||
import { API_BASE_URL, LAYOUT_PATH, DATA_SECRET_KEY, REQUEST_ENCRYPTION } from '@/config/setting';
|
||||
import type { ApiResult } from '@/api';
|
||||
import router from '@/router';
|
||||
import { isWhiteList } from '@/router/routes';
|
||||
@ -44,11 +44,7 @@ export function decryptData(ciphertext: string): any {
|
||||
*/
|
||||
export function requestInterceptor(config: SecureRequestConfig) {
|
||||
const method = config.method?.toLowerCase() as Method;
|
||||
// 是否加密
|
||||
const shouldEncrypt = (
|
||||
!config.skipEncryption &&
|
||||
config.data &&
|
||||
['post', 'put', 'delete', 'patch'].includes(method));
|
||||
|
||||
|
||||
// 添加客户端信息到header
|
||||
const client = useClientStore();
|
||||
@ -64,10 +60,16 @@ export function requestInterceptor(config: SecureRequestConfig) {
|
||||
config.headers['Authorization'] = token;
|
||||
}
|
||||
// get请求处理数组和对象类型参数
|
||||
if (config.method === 'get' && config.params) {
|
||||
if (method === 'get' && config.params) {
|
||||
config.url = toURLSearch(config.params, config.url);
|
||||
config.params = {};
|
||||
}
|
||||
if (REQUEST_ENCRYPTION) {
|
||||
// 是否加密
|
||||
const shouldEncrypt = (
|
||||
!config.skipEncryption &&
|
||||
config.data &&
|
||||
['post', 'put', 'delete', 'patch'].includes(method));
|
||||
if (shouldEncrypt && !config.headers?.['X-Encrypted']) {
|
||||
config.data = {
|
||||
encryptedData: encryptData(config.data)
|
||||
@ -75,6 +77,7 @@ export function requestInterceptor(config: SecureRequestConfig) {
|
||||
config.headers['X-Encrypted'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 响应拦截处理
|
||||
|
||||
Loading…
Reference in New Issue
Block a user