diff --git a/ruoyi-ui/src/utils/dict/Dict.js b/ruoyi-ui/src/utils/dict/Dict.js index 22db32fe2..99ac4baac 100644 --- a/ruoyi-ui/src/utils/dict/Dict.js +++ b/ruoyi-ui/src/utils/dict/Dict.js @@ -37,7 +37,7 @@ export default class Dict { if (dictMeta.lazy) { return } - ps.push(loadDict(this, dictMeta)) + ps.push(removal(this, dictMeta)) }) return Promise.all(ps) } @@ -51,10 +51,30 @@ export default class Dict { if (dictMeta === undefined) { return Promise.reject(`the dict meta of ${type} was not found`) } - return loadDict(this, dictMeta) + return removal(this, dictMeta) } } +//过滤重复数据重复请求 +function removal(dict, dictMeta) { + const type = dictMeta.type + let that = dict.owner; + let ld; + if(__dictCache.get(type)){ + ld = __dictCache.get(type) + ld.then(dicts=>{ + dict.type[type].splice(0, Number.MAX_SAFE_INTEGER, ...dicts) + dicts.forEach(d => { + Vue.set(dict.label[type], d.value, d.label) + }) + }) + }else{ + ld = loadDict(dict, dictMeta); + __dictCache.set(type,ld) + } + return ld +} + /** * 加载字典 * @param {Dict} dict 字典 diff --git a/ruoyi-ui/src/utils/dict/index.js b/ruoyi-ui/src/utils/dict/index.js index d6fdb802c..c18e45ddc 100644 --- a/ruoyi-ui/src/utils/dict/index.js +++ b/ruoyi-ui/src/utils/dict/index.js @@ -1,6 +1,7 @@ import Dict from './Dict' import { mergeOptions } from './DictOptions' - +var __dictCache = new Map(); +window.__dictCache = __dictCache; export default function(Vue, options) { mergeOptions(options) Vue.mixin({