class SysDictData { constructor(dict) { this.dict = dict } async init(dictNames) { const ps = []; dictNames.forEach((name) => { Vue.set(this.dict.type, name, null) ps.push( getDictOptions(name).then((res) => { const dictValue = res.map(v => { return { text: v.name, label: v.name, value: v.code, raw: v } }) this.dict.type[name] = Object.freeze(dictValue) }) ) }) await Promise.all(ps) } } window.dictData = {} window.dictData.install = function (Vue) { Vue.mixin({ data() { if (this.$options.dicts instanceof Array && this.$options.dicts.length > 0) { return {dict: {type: {}}}; } else { return {} } }, created() { if (this.$options.dicts instanceof Array && this.$options.dicts.length > 0) { new SysDictData(this.dict).init(this.$options.dicts); } } }) } if (window.Vue) { Vue.use(window.dictData) }