Pārlūkot izejas kodu

GET请求增加参数加密配置

cfort 1 gadu atpakaļ
vecāks
revīzija
bef2ce5880
3 mainītis faili ar 19 papildinājumiem un 9 dzēšanām
  1. 2 1
      public/config.js
  2. 2 0
      src/constant.js
  3. 15 8
      src/utils/request.js

+ 2 - 1
public/config.js

@@ -56,7 +56,8 @@
     //国际化配置
     I18N_LOCALE:'zh-CN',
     I18N_FALLBACK_LOCALE:'zh-CN',
-
+    // 加密 GET 请求参数
+    ENCRYPT_GET_PARAMS: true
   }
 
 })(window)

+ 2 - 0
src/constant.js

@@ -61,4 +61,6 @@
  
  export const REPORT_PATH = __IBPS_CONFIG__.REPORT_PATH || '金通医学实验室管理系统'
  export const SYSTEM_NAME = __IBPS_CONFIG__.SYSTEM_NAME || '金通医学实验室标准化数智化管理平台'
+
+ export const ENCRYPT_GET_PARAMS = __IBPS_CONFIG__.ENCRYPT_GET_PARAMS || false
  

+ 15 - 8
src/utils/request.js

@@ -22,7 +22,7 @@ import { showFullScreenLoading, tryHideFullScreenLoading } from './loading'
 
 import requestState from '@/constants/state'
 import { BASE_API, BASE_GATEWAY_API } from '@/api/baseUrl'
-import { HEADER_TOKEN_KEY, HEADER_SYSTEM_ID, HEADER_TENANT_ID, MULTIPLE_DOMAIN, API_DOMAIN_NAMES } from '@/constant'
+import { HEADER_TOKEN_KEY, HEADER_SYSTEM_ID, HEADER_TENANT_ID, MULTIPLE_DOMAIN, API_DOMAIN_NAMES, ENCRYPT_GET_PARAMS } from '@/constant'
 
 const TIMEOUT = 3000 * 100 // 请求超时(timeout)时间
 /**
@@ -88,13 +88,20 @@ service.interceptors.request.use(async config => {
   if (config.isLoading) {
     showFullScreenLoading(config.loading)
   }
-  // 防止缓存
-  // if (config.method.toUpperCase() === 'GET') {
-  //   config.params = {
-  //     ...config.params,
-  //     _t: Date.parse(new Date()) / 1000
-  //   }
-  // }
+  // 防止缓存,参数加密
+  if (config.method.toUpperCase() === 'GET') {
+    if (ENCRYPT_GET_PARAMS) {
+      config.params = {
+        _p: Utils.isNotEmpty(config.params) ? encryptByAes(JSON.stringify(config.params)) : undefined,
+        _t: Date.parse(new Date()) / 1000
+      }
+    } else {
+      config.params = {
+        ...config.params,
+        _t: Date.parse(new Date()) / 1000
+      }
+    }
+  }
 
   // 判断是否需要token
   if (whiteList.indexOf(config.url) !== -1) {