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

View File

@ -4,11 +4,31 @@
* @LastEditors: sakuya
* @LastEditTime: 2022年5月24日00:28:56
*/
import CryptoJS from 'crypto-js';
import sysConfig from "@/config";
import store from '@/store'
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 */
tool.data = {
@ -50,7 +70,6 @@ tool.data = {
return localStorage.clear()
}
}
/*sessionStorage*/
tool.session = {
set(table, settings) {
@ -73,7 +92,6 @@ tool.session = {
return sessionStorage.clear();
}
}
/*cookie*/
tool.cookie = {
set(name, value, config = {}) {
@ -113,7 +131,6 @@ tool.cookie = {
document.cookie = `${name}=;expires=${exp.toGMTString()}`
}
}
/* Fullscreen */
tool.screen = function(element) {
var isFull = !!(document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement || document.fullscreenElement);
@ -139,12 +156,10 @@ tool.screen = function (element) {
}
}
}
/* 复制对象 */
tool.objCopy = function(obj) {
return JSON.parse(JSON.stringify(obj));
}
/* 日期格式化 */
tool.dateFormat = function(date, fmt = 'yyyy-MM-dd hh:mm:ss') {
date = new Date(date)
@ -167,7 +182,6 @@ tool.dateFormat = function (date, fmt='yyyy-MM-dd hh:mm:ss') {
}
return fmt;
}
/* 千分符 */
tool.groupSeparator = function(num) {
num = num + '';
@ -178,7 +192,6 @@ tool.groupSeparator = function (num) {
return $1 + ',';
}).replace(/\.$/, '');
}
/* 常用加解密 */
tool.crypto = {
//MD5加密
@ -217,5 +230,4 @@ tool.crypto = {
}
}
}
export default tool

View File

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