49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
class SysDictData {
|
|
constructor(dict) {
|
|
this.dict = dict
|
|
}
|
|
|
|
async init(dictNames) {
|
|
const ps = []
|
|
dictNames.forEach((name) => {
|
|
Vue.set(this.dict.type, name, null)
|
|
ps.push(
|
|
$.get("/open/common/dictOptions", { code: name }).then((res) => {
|
|
const dictValue = res.data.map((v) => {
|
|
return {
|
|
name: v.name,
|
|
text: v.name,
|
|
label: v.name,
|
|
code: 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).then()
|
|
}
|
|
}
|
|
})
|
|
}
|
|
if (window.Vue) {
|
|
Vue.use(window.dictData)
|
|
}
|