import CryptoJS from 'crypto-js'; // import { TextEncoder } from 'text-decoding' // const TextEncoder = new TextEncoder(); var aqEnnable = true;//是否开启安全验证 const key = 'zhst@bonus@zhst@bonus@1234567890';//AES加密cbc 256 // const key = '1234567812345678';//AES加密cbc const iv = '1234567812345678'; function getKey() { // 真正的key return CryptoJS.enc.Utf8.parse(key); } function getIv() { // 真正的iv return CryptoJS.enc.Utf8.parse(iv); } export default { encrypt(word) { if(!aqEnnable){ return word; } if(word==null){ var ciphertext = CryptoJS.AES.encrypt(word, getKey(), { iv: getIv(), mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }); return ciphertext.toString(); }else{ var ciphertext = CryptoJS.AES.encrypt(word.toString(), getKey(), { iv: getIv(), mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }); return ciphertext.toString(); } }, decrypt(word) { if(!aqEnnable){ return word; } if(word==null){ return ""; } var bytes = CryptoJS.AES.decrypt(word.toString(), getKey(), { iv: getIv(), mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }); return bytes.toString(CryptoJS.enc.Utf8); }, // DateFormat(date, fmt) { if (date && fmt) { let _date = new Date(date); var o = { 'Y+': _date.getFullYear() , //年 'M+': _date.getMonth() + 1, //月份 'd+': _date.getDate(), //日 'h+': _date.getHours(), //小时 'm+': _date.getMinutes(), //分 's+': _date.getSeconds(), //秒 'q+': Math.floor((_date.getMonth() + 3) / 3), //季度 S: _date.getMilliseconds(), //毫秒 }; if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (_date.getFullYear() + '').substr(4 - RegExp.$1.length)); } for (var k in o) { if (new RegExp('(' + k + ')').test(fmt)) { fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? (o)[k] : ('00' + (o)[k]).substr(('' + (o)[k]).length)); } } return fmt; } else { return ''; } } }