diff --git a/src/config/index.js b/src/config/index.js index fb63632c..21064adc 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -48,6 +48,12 @@ const DEFAULT_CONFIG = { //主题颜色 COLOR: '', + //是否加密localStorage, 为空不加密,可填写AES(模式ECB,移位Pkcs7)加密 + LS_ENCRYPTION: '', + + //localStorageAES加密秘钥,位数建议填写8的倍数 + LS_ENCRYPTION_key: '2XNN4K8LC0ELVWN4', + //控制台首页默认布局 DEFAULT_GRID: { //默认分栏数量和宽度 例如 [24] [18,6] [8,8,8] [6,12,6] diff --git a/src/utils/tool.js b/src/utils/tool.js index fadb9d67..8c027dbc 100644 --- a/src/utils/tool.js +++ b/src/utils/tool.js @@ -6,12 +6,17 @@ */ import CryptoJS from 'crypto-js'; +import sysConfig from "@/config"; const tool = {} /* localStorage */ tool.data = { set(key, data, datetime = 0) { + //加密 + if(sysConfig.LS_ENCRYPTION == "AES"){ + data = tool.crypto.AES.encrypt(JSON.stringify(data), sysConfig.LS_ENCRYPTION_key) + } let cacheValue = { content: data, datetime: parseInt(datetime) === 0 ? 0 : new Date().getTime() + parseInt(datetime) * 1000 @@ -27,6 +32,10 @@ tool.data = { localStorage.removeItem(key) return null; } + //解密 + if(sysConfig.LS_ENCRYPTION == "AES"){ + value.content = JSON.parse(tool.crypto.AES.decrypt(value.content, sysConfig.LS_ENCRYPTION_key)) + } return value.content } return null