forked from elunez/eladmin-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request elunez#37 from moxun1639/2.3dev
简化数据字典,支持单组件内多字典同时使用,全局混入,组件不配置字典时,不对data附加dict属性
- Loading branch information
Showing
4 changed files
with
65 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Vue from 'vue' | ||
import { get as getDictDetail } from '@/api/dictDetail' | ||
|
||
export default class Dict { | ||
constructor (dict) { | ||
this.dict = dict | ||
} | ||
|
||
async init (names, completeCallback) { | ||
if (names === undefined || name === null) { | ||
throw new Error('need dict names') | ||
} | ||
const ps = [] | ||
names.forEach(n => { | ||
Vue.set(this.dict.dict, n, {}) | ||
Vue.set(this.dict.label, n, {}) | ||
Vue.set(this.dict, n, []) | ||
ps.push(getDictDetail(n).then(data => { | ||
this.dict[n].splice(0, 0, ...data.content) | ||
data.content.forEach(d => { | ||
Vue.set(this.dict.dict[n], d.value, d) | ||
Vue.set(this.dict.label[n], d.value, d.label) | ||
}) | ||
})) | ||
}) | ||
await Promise.all(ps) | ||
completeCallback() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Dict from './Dict' | ||
|
||
const install = function (Vue) { | ||
Vue.mixin({ | ||
data () { | ||
if (this.$options.dicts instanceof Array) { | ||
const dict = { | ||
dict: {}, | ||
label: {}, | ||
} | ||
return { | ||
dict, | ||
} | ||
} | ||
return {} | ||
}, | ||
created () { | ||
if (this.$options.dicts instanceof Array) { | ||
new Dict(this.dict).init(this.$options.dicts, () => { | ||
this.$nextTick(() => { | ||
this.$emit('dictReady') | ||
}) | ||
}) | ||
} | ||
}, | ||
}) | ||
} | ||
|
||
export default { install } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters