no message

This commit is contained in:
小陌 2023-07-07 08:33:06 +08:00
parent 01eeb6db39
commit 7db9708231
4 changed files with 220 additions and 171 deletions

View File

@ -0,0 +1,22 @@
export default {
state: {
cacheList: {}
},
mutations: {
setCache(state, { name, value }) {
state.cacheList[name] = value;
},
getCache(state, name) {
if (!Object.prototype.hasOwnProperty.call(state.cacheList, name)) {
state.cacheList[name] = null;
}
return state.cacheList[name];
},
removeCache(state, name) {
delete state.cacheList[name];
},
clearCache(state) {
state.cacheList = {};
}
}
}

View File

@ -6,6 +6,8 @@ import {
import sysConfig from "@/config"; import sysConfig from "@/config";
import tool from '@/utils/tool'; import tool from '@/utils/tool';
import router from '@/router'; import router from '@/router';
axios.defaults.baseURL = sysConfig.API_URL axios.defaults.baseURL = sysConfig.API_URL
axios.defaults.timeout = sysConfig.TIMEOUT axios.defaults.timeout = sysConfig.TIMEOUT
// HTTP request 拦截器 // HTTP request 拦截器
@ -91,6 +93,10 @@ var http = {
var cacheKey = ''; var cacheKey = '';
if (typeof config.cache !== 'undefined' && !isNaN(config.cache) && config.cache > 0) { if (typeof config.cache !== 'undefined' && !isNaN(config.cache) && config.cache > 0) {
cacheKey = tool.crypto.MD5(url + (new URLSearchParams(params)).toString()); cacheKey = tool.crypto.MD5(url + (new URLSearchParams(params)).toString());
const cachedData = tool.data.get(cacheKey); const cachedData = tool.data.get(cacheKey);
if (cachedData) { if (cachedData) {
return resolve(cachedData); return resolve(cachedData);

View File

@ -4,17 +4,37 @@
* @LastEditors: sakuya * @LastEditors: sakuya
* @LastEditTime: 2022年5月24日00:28:56 * @LastEditTime: 2022年5月24日00:28:56
*/ */
import CryptoJS from 'crypto-js'; import CryptoJS from 'crypto-js';
import sysConfig from "@/config"; import sysConfig from "@/config";
import store from '@/store'
const tool = {} const tool = {}
/* store */
tool.store = {
set(key, data) {
return store.commit('setCache', key, data);
},
get(key) {
try {
return store.commit('getCache', key);
} catch (err) {
return null
}
},
remove(key) {
return store.commit('removeCache', key);
},
clear() {
return store.commit('clearCache');
}
}
/* localStorage */ /* localStorage */
tool.data = { tool.data = {
set(key, data, datetime = 0) { set(key, data, datetime = 0) {
//加密 //加密
if(sysConfig.LS_ENCRYPTION == "AES"){ if (sysConfig.LS_ENCRYPTION == "AES") {
data = tool.crypto.AES.encrypt(JSON.stringify(data), sysConfig.LS_ENCRYPTION_key) data = tool.crypto.AES.encrypt(JSON.stringify(data), sysConfig.LS_ENCRYPTION_key)
} }
let cacheValue = { let cacheValue = {
@ -33,7 +53,7 @@ tool.data = {
return null; return null;
} }
//解密 //解密
if(sysConfig.LS_ENCRYPTION == "AES"){ if (sysConfig.LS_ENCRYPTION == "AES") {
value.content = JSON.parse(tool.crypto.AES.decrypt(value.content, sysConfig.LS_ENCRYPTION_key)) value.content = JSON.parse(tool.crypto.AES.decrypt(value.content, sysConfig.LS_ENCRYPTION_key))
} }
return value.content return value.content
@ -50,7 +70,6 @@ tool.data = {
return localStorage.clear() return localStorage.clear()
} }
} }
/*sessionStorage*/ /*sessionStorage*/
tool.session = { tool.session = {
set(table, settings) { set(table, settings) {
@ -73,10 +92,9 @@ tool.session = {
return sessionStorage.clear(); return sessionStorage.clear();
} }
} }
/*cookie*/ /*cookie*/
tool.cookie = { tool.cookie = {
set(name, value, config={}) { set(name, value, config = {}) {
var cfg = { var cfg = {
expires: null, expires: null,
path: null, path: null,
@ -86,118 +104,113 @@ tool.cookie = {
...config ...config
} }
var cookieStr = `${name}=${escape(value)}` var cookieStr = `${name}=${escape(value)}`
if(cfg.expires){ if (cfg.expires) {
var exp = new Date() var exp = new Date()
exp.setTime(exp.getTime() + parseInt(cfg.expires) * 1000) exp.setTime(exp.getTime() + parseInt(cfg.expires) * 1000)
cookieStr += `;expires=${exp.toGMTString()}` cookieStr += `;expires=${exp.toGMTString()}`
} }
if(cfg.path){ if (cfg.path) {
cookieStr += `;path=${cfg.path}` cookieStr += `;path=${cfg.path}`
} }
if(cfg.domain){ if (cfg.domain) {
cookieStr += `;domain=${cfg.domain}` cookieStr += `;domain=${cfg.domain}`
} }
document.cookie = cookieStr document.cookie = cookieStr
}, },
get(name){ get(name) {
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)")) var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"))
if(arr != null){ if (arr != null) {
return unescape(arr[2]) return unescape(arr[2])
}else{ } else {
return null return null
} }
}, },
remove(name){ remove(name) {
var exp = new Date() var exp = new Date()
exp.setTime(exp.getTime() - 1) exp.setTime(exp.getTime() - 1)
document.cookie = `${name}=;expires=${exp.toGMTString()}` document.cookie = `${name}=;expires=${exp.toGMTString()}`
} }
} }
/* Fullscreen */ /* Fullscreen */
tool.screen = function (element) { tool.screen = function(element) {
var isFull = !!(document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement || document.fullscreenElement); var isFull = !!(document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement || document.fullscreenElement);
if(isFull){ if (isFull) {
if(document.exitFullscreen) { if (document.exitFullscreen) {
document.exitFullscreen(); document.exitFullscreen();
}else if (document.msExitFullscreen) { } else if (document.msExitFullscreen) {
document.msExitFullscreen(); document.msExitFullscreen();
}else if (document.mozCancelFullScreen) { } else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen(); document.mozCancelFullScreen();
}else if (document.webkitExitFullscreen) { } else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen(); document.webkitExitFullscreen();
} }
}else{ } else {
if(element.requestFullscreen) { if (element.requestFullscreen) {
element.requestFullscreen(); element.requestFullscreen();
}else if(element.msRequestFullscreen) { } else if (element.msRequestFullscreen) {
element.msRequestFullscreen(); element.msRequestFullscreen();
}else if(element.mozRequestFullScreen) { } else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen(); element.mozRequestFullScreen();
}else if(element.webkitRequestFullscreen) { } else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen(); element.webkitRequestFullscreen();
} }
} }
} }
/* 复制对象 */ /* 复制对象 */
tool.objCopy = function (obj) { tool.objCopy = function(obj) {
return JSON.parse(JSON.stringify(obj)); return JSON.parse(JSON.stringify(obj));
} }
/* 日期格式化 */ /* 日期格式化 */
tool.dateFormat = function (date, fmt='yyyy-MM-dd hh:mm:ss') { tool.dateFormat = function(date, fmt = 'yyyy-MM-dd hh:mm:ss') {
date = new Date(date) date = new Date(date)
var o = { var o = {
"M+" : date.getMonth()+1, //月份 "M+": date.getMonth() + 1, //月份
"d+" : date.getDate(), //日 "d+": date.getDate(), //日
"h+" : date.getHours(), //小时 "h+": date.getHours(), //小时
"m+" : date.getMinutes(), //分 "m+": date.getMinutes(), //分
"s+" : date.getSeconds(), //秒 "s+": date.getSeconds(), //秒
"q+" : Math.floor((date.getMonth()+3)/3), //季度 "q+": Math.floor((date.getMonth() + 3) / 3), //季度
"S" : date.getMilliseconds() //毫秒 "S": date.getMilliseconds() //毫秒
}; };
if(/(y+)/.test(fmt)) { if (/(y+)/.test(fmt)) {
fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length)); fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
} }
for(var k in o) { for (var k in o) {
if(new RegExp("("+ k +")").test(fmt)){ if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
} }
} }
return fmt; return fmt;
} }
/* 千分符 */ /* 千分符 */
tool.groupSeparator = function (num) { tool.groupSeparator = function(num) {
num = num + ''; num = num + '';
if(!num.includes('.')){ if (!num.includes('.')) {
num += '.' num += '.'
} }
return num.replace(/(\d)(?=(\d{3})+\.)/g, function ($0, $1) { return num.replace(/(\d)(?=(\d{3})+\.)/g, function($0, $1) {
return $1 + ','; return $1 + ',';
}).replace(/\.$/, ''); }).replace(/\.$/, '');
} }
/* 常用加解密 */ /* 常用加解密 */
tool.crypto = { tool.crypto = {
//MD5加密 //MD5加密
MD5(data){ MD5(data) {
return CryptoJS.MD5(data).toString() return CryptoJS.MD5(data).toString()
}, },
//BASE64加解密 //BASE64加解密
BASE64: { BASE64: {
encrypt(data){ encrypt(data) {
return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(data)) return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(data))
}, },
decrypt(cipher){ decrypt(cipher) {
return CryptoJS.enc.Base64.parse(cipher).toString(CryptoJS.enc.Utf8) return CryptoJS.enc.Base64.parse(cipher).toString(CryptoJS.enc.Utf8)
} }
}, },
//AES加解密 //AES加解密
AES: { AES: {
encrypt(data, secretKey, config={}){ encrypt(data, secretKey, config = {}) {
if(secretKey.length % 8 != 0){ if (secretKey.length % 8 != 0) {
console.warn("[X-PHP ERROR]: 秘钥长度需为8的倍数否则解密将会失败。") console.warn("[X-PHP ERROR]: 秘钥长度需为8的倍数否则解密将会失败。")
} }
const result = CryptoJS.AES.encrypt(data, CryptoJS.enc.Utf8.parse(secretKey), { const result = CryptoJS.AES.encrypt(data, CryptoJS.enc.Utf8.parse(secretKey), {
@ -207,7 +220,7 @@ tool.crypto = {
}) })
return result.toString() return result.toString()
}, },
decrypt(cipher, secretKey, config={}){ decrypt(cipher, secretKey, config = {}) {
const result = CryptoJS.AES.decrypt(cipher, CryptoJS.enc.Utf8.parse(secretKey), { const result = CryptoJS.AES.decrypt(cipher, CryptoJS.enc.Utf8.parse(secretKey), {
iv: CryptoJS.enc.Utf8.parse(config.iv || ""), iv: CryptoJS.enc.Utf8.parse(config.iv || ""),
mode: CryptoJS.mode[config.mode || "ECB"], mode: CryptoJS.mode[config.mode || "ECB"],
@ -217,5 +230,4 @@ tool.crypto = {
} }
} }
} }
export default tool export default tool

View File

@ -106,6 +106,15 @@
} }
}); });
} }
this.$tool.store.set('cacheKey', {uid:1});
console.log(this.$tool.store.get('cacheKey'))
}, },
computed: { computed: {
filterObj(){ filterObj(){