入职一个半月..对业务不是很熟悉。但是感觉这么写获取字典表数据还是挺好的。哈哈
方法二: 调用仅仅需要传入Key值即可。如果是其他方法可以做相应的修改。
export const setDicValue2=(dicInfoKey) => {
let _this=this
let p =new Promise(( resolve => {
axios.post(config.GET_DICINFO_BYKEY, {
keyword: dicInfoKey
})
.then(function (res) {
if (res.data.status == "200") {
resolve(res.data.data)
}
else {
_this.$message({
type: "error",
message: res.data.message,
duration: "1000"
})
}
})
.catch(function (res) {
_this.$message({
type:"error",
message:res.message,
duration:"1000"
})
});
} ))
return p
}
请求字典:即同一url。根据不同的参数返回值列表,vue可以将数据响应式的渲染到视图中。
//key为字典的key值,value为data对象中的数组名称,sourceList=[]
let getDicKV={
"PRODUCE_SOURCE":"sourceList",
"PROCEDURE_TYPE":"procedureList",
"PLANNING_PLAN_STATUS":"statusList",
"PRODUCE_TYPE":"produceTypeList"
}
/*
* 遍历kv键值对,依次设置列表值
* */
for(let key in getDicKV){
axiosPostLoadDicDataList(_this,key,getDicKV[key])
}
/*
* 加载字典列表数据方法
*
* _this为调用对象
* dicInfoKey为key值
* listname为字典数组名称
* isFour判断数据是否在res响应流的四级菜单中,True/false
* 调用示例 helpTools.axiosPostLoadDicDataList(_this,"PRODUCE_TYPE","checkList")
* */
export const axiosPostLoadDicDataList = (_this,dicInfoKey,listname,isFour) => {
axios.post(config.GET_DICINFO_BYKEY, {
keyword: dicInfoKey
})
.then(function (res) {
if (res.data.status == "200") {
if (!isFour) {
_this[listname] = res.data.data
}
else {
_this[listname] = res.data.data.row
}
}
else {
_this.$message({
type: "error",
message: res.data.message,
duration: "1000"
})
}
})
.catch(function (res) {
_this.$message({
type:"error",
message:res.message,
duration:"1000"
})
});
}