perf:新增GlobalConfig,发布版本1.0.4

This commit is contained in:
曾文豪
2023-03-17 12:43:47 +08:00
parent 580d7c5d62
commit 561be80efb
3 changed files with 34 additions and 33 deletions

View File

@@ -1,17 +1,17 @@
const base64js = require("base64-js");
const SM4 = require("./SM4");
const GlobalConfig = require("../utils/GlobalConfig");
class Crypto {
constructor() {
this.sm4 = new SM4({
keyBuffer: base64js.toByteArray(window.httpConfig.base64Key),
keyBuffer: base64js.toByteArray(GlobalConfig.getConfig().base64Key),
mode: "ecb",
cipherType: 'base64'
})
}
/**
* 加密数据
* @param content

28
src/utils/GlobalConfig.js Normal file
View File

@@ -0,0 +1,28 @@
/**
* 默认配置
* @type {{prefix: string, encryptBody: boolean}}
*/
const defaultConfig = {
encryptBody: true,
base64Key: "WmdUzPJXbngVNiaSsQrihg==",
prefix: "",
}
/**
* 获取网络请求配置
*/
const getConfig = () => {
return window.httpConfig || defaultConfig;
}
/**
* 网络请求配置
* @param obj
*/
function setConfig(obj = defaultConfig) {
window.httpConfig = {...getConfig(), ...obj};
}
module.exports = {
setConfig, getConfig
}