使用
async getDict() {
const dic = []
await this.$dictUtil.getDict('CSA_ID_TYPE', 'individual').then((data) => {
this.dic.idType = data
console.log('this.dic.idType :', this.dic.idType);
})
},
main.js
import dictUtil from './modules/crmCommon/dictUtil' Vue.prototype.$dictUtil = dictUtil
dicUtils.js
import store from '@/framework/store' import Vue from 'vue'
函数说明:getDict函数用于获取单个字典的所有值,返回的语言可指定,也可不指定可使用浏览器语言
可能使用的情景:下拉框中的字典值、avue-crud、avue-form中指定字典值
参数说明:
code 字符串,字典项的名称
language:默认为当前浏览器设置的language,不传递该参数则使用默认值,特殊情况下可传递language指定字典语言类型
字典语言类型如下:
en:英语
es:西班牙语
fr:法语
返回值说明
dict:[
{
lable:"",
value:"",
parentCode:"",
},
{
lable:"",
value:"",
parentCode:"",
}
]
----------------------------------------------
//已在全局注册 使用示例
Vue.prototype.$dictUtil.getDict('CSA_ID_TYPE').then(data => {
console.log('新的字典值函数取到得知',data)
this.idDict=data
})
export default {
getDict: function (code, parentDictItemCode) {
return new Promise((resolve) => {
let dic = []
Vue.axios({
url: '/api-smc/api/dict/v2/getDict',
method: 'POST',
data: {
dictCode: code,
parentDictItemCode: parentDictItemCode,
dateTime: new Date().getTime()
}
}).then(data => {
if (data.length > 0) {
dic = getDicFromRaw(data)
}
setTimeout(function () {
Vue.prototype.$cache.set(code, data, 720 * 60)
}, 100)
resolve(dic)
})
})
},