no message
This commit is contained in:
parent
01eeb6db39
commit
7db9708231
22
src/store/modules/cache.js
Normal file
22
src/store/modules/cache.js
Normal 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 = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
@ -4,11 +4,31 @@
|
|||||||
* @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 = {
|
||||||
@ -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,7 +92,6 @@ tool.session = {
|
|||||||
return sessionStorage.clear();
|
return sessionStorage.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*cookie*/
|
/*cookie*/
|
||||||
tool.cookie = {
|
tool.cookie = {
|
||||||
set(name, value, config = {}) {
|
set(name, value, config = {}) {
|
||||||
@ -113,7 +131,6 @@ tool.cookie = {
|
|||||||
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);
|
||||||
@ -139,12 +156,10 @@ tool.screen = function (element) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 复制对象 */
|
/* 复制对象 */
|
||||||
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)
|
||||||
@ -167,7 +182,6 @@ tool.dateFormat = function (date, fmt='yyyy-MM-dd hh:mm:ss') {
|
|||||||
}
|
}
|
||||||
return fmt;
|
return fmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 千分符 */
|
/* 千分符 */
|
||||||
tool.groupSeparator = function(num) {
|
tool.groupSeparator = function(num) {
|
||||||
num = num + '';
|
num = num + '';
|
||||||
@ -178,7 +192,6 @@ tool.groupSeparator = function (num) {
|
|||||||
return $1 + ',';
|
return $1 + ',';
|
||||||
}).replace(/\.$/, '');
|
}).replace(/\.$/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 常用加解密 */
|
/* 常用加解密 */
|
||||||
tool.crypto = {
|
tool.crypto = {
|
||||||
//MD5加密
|
//MD5加密
|
||||||
@ -217,5 +230,4 @@ tool.crypto = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default tool
|
export default tool
|
@ -106,6 +106,15 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.$tool.store.set('cacheKey', {uid:1});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
console.log(this.$tool.store.get('cacheKey'))
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
filterObj(){
|
filterObj(){
|
||||||
|
Loading…
Reference in New Issue
Block a user