diff --git a/src/api/model/common.js b/src/api/model/common.js index 5648c05..0ca5239 100644 --- a/src/api/model/common.js +++ b/src/api/model/common.js @@ -1,8 +1,9 @@ import http from "@/utils/request" export default { upload: { + url: '/app/upload', post: async function(data, config = {}) { - return await http.post('/app/upload', data, config); + return await http.post(this.url, data, config); } }, uploadFile: { diff --git a/src/api/model/system.js b/src/api/model/system.js index 86af86f..9568dfc 100644 --- a/src/api/model/system.js +++ b/src/api/model/system.js @@ -6,10 +6,10 @@ export default { } }, table: { - get: async function(name = '', config = {}) { + get: async function(name = '') { return await http.get('/system/table/get', { name - }, config); + }, {cache:true}); } }, } \ No newline at end of file diff --git a/src/store/modules/cache.js b/src/store/modules/cache.js index 7aee258..62b4873 100644 --- a/src/store/modules/cache.js +++ b/src/store/modules/cache.js @@ -1,22 +1,20 @@ export default { - state: { - cacheList: {} - }, - mutations: { - setCache(state, { name, value }) { - state.cacheList[name] = value; + state: { + cacheList: {} }, - 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 = {}; + mutations: { + setCache(state, payload) { + const { + key, + value + } = payload; + state.cacheList[key] = value; + }, + removeCache(state, key) { + delete state.cacheList[key]; + }, + clearCache(state) { + state.cacheList = {}; + } } - } } \ No newline at end of file diff --git a/src/store/modules/global.js b/src/store/modules/global.js index 09a8c7e..fae4547 100644 --- a/src/store/modules/global.js +++ b/src/store/modules/global.js @@ -1,17 +1,16 @@ import config from "@/config"; -import tool from "@/utils/tool"; export default { state: { //移动端布局 ismobile: false, //布局 - layout: tool.data.get('layout') || config.LAYOUT, + layout: config.LAYOUT, //菜单是否折叠 toggle - menuIsCollapse: tool.data.get('layoutmenuiscollapse') || config.MENU_IS_COLLAPSE || false, + menuIsCollapse: config.MENU_IS_COLLAPSE || false, //多标签栏 - layoutTags: tool.data.get('layouttags') || config.LAYOUT_TAGS, + layoutTags: config.LAYOUT_TAGS, //显示页头 - layoutHeader: tool.data.get('layoutheader') || true, + layoutHeader: true, }, mutations: { SET_ismobile(state, key) { diff --git a/src/utils/request.js b/src/utils/request.js index c851ac6..c1e9b19 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -91,13 +91,9 @@ var http = { return new Promise((resolve, reject) => { // 缓存存在, 优先使用缓存 var cacheKey = ''; - if (typeof config.cache !== 'undefined' && !isNaN(config.cache) && config.cache > 0) { + if (typeof config.cache !== 'undefined' && config.cache) { cacheKey = tool.crypto.MD5(url + (new URLSearchParams(params)).toString()); - - - - - const cachedData = tool.data.get(cacheKey); + const cachedData = tool.store.get(cacheKey); if (cachedData) { return resolve(cachedData); } @@ -108,8 +104,8 @@ var http = { params: params, ...config }).then((response) => { - if (cacheKey && typeof config.cache !== 'undefined' && !isNaN(config.cache) && config.cache > 0) { - tool.data.set(cacheKey, response.data, config.cache); + if (cacheKey && typeof config.cache !== 'undefined' && config.cache) { + tool.store.set(cacheKey, response.data); } resolve(response.data); }).catch((error) => { diff --git a/src/utils/tool.js b/src/utils/tool.js index ad1f1c4..aa63d40 100644 --- a/src/utils/tool.js +++ b/src/utils/tool.js @@ -1,8 +1,5 @@ /* * @Descripttion: 工具集 - * @version: 1.2 - * @LastEditors: sakuya - * @LastEditTime: 2022年5月24日00:28:56 */ import CryptoJS from 'crypto-js'; import sysConfig from "@/config"; @@ -13,14 +10,13 @@ const tool = {} /* store */ tool.store = { set(key, data) { - return store.commit('setCache', key, data); + return store.commit('setCache', {key:key, value:data}); }, get(key) { - try { - return store.commit('getCache', key); - } catch (err) { - return null + if (!Object.prototype.hasOwnProperty.call(store.state.cache.cacheList, key)) { + store.state.cache.cacheList[key] = null; } + return store.state.cache.cacheList[key]; }, remove(key) { return store.commit('removeCache', key); diff --git a/src/views/system/table/index.vue b/src/views/system/table/index.vue index afc3384..5b5a9f5 100644 --- a/src/views/system/table/index.vue +++ b/src/views/system/table/index.vue @@ -106,15 +106,6 @@ } }); } - - - this.$tool.store.set('cacheKey', {uid:1}); - - - - console.log(this.$tool.store.get('cacheKey')) - - }, computed: { filterObj(){