初始化产品库

This commit is contained in:
aixianling
2021-11-15 10:29:05 +08:00
parent 8f735a4ffe
commit 5440b43b9c
306 changed files with 54508 additions and 3 deletions

50
src/common/dict.js Normal file
View File

@@ -0,0 +1,50 @@
import request from "./axios";
import store from "../store";
/**
* 封装字典工具类
*/
const $dict = {
vueStore: null,
url: "/admin/dictionary/queryValsByCodeList",
setUrl(v) {
this.url = v
},
load(...code) {
if (!this.vueStore) this.vueStore = store
return request.post(this.url, null, {
params: {
codeList: code.join(',')
}
}).then((res) => {
this.vueStore.commit("setDicts", res.data)
})
},
getDict(key) {
let dict = this.vueStore.getters.getDict(key)
return dict ? dict.values : []
},
getValue(key, label) {
let dict = this.vueStore.getters.getDict(key)
if (dict) {
let item = dict.values.find(v => v.dictName == label)
return item ? item.dictValue : label
} else return label
},
getLabel(key, value) {
let dict = this.vueStore.getters.getDict(key)
if (dict) {
let item = dict.values.find(v => v.dictValue == value)
return item ? item.dictName : value
} else return value
},
getColor(key, value) {
let dict = this.vueStore.getters.getDict(key)
if (dict) {
let item = dict.values.find(v => v.dictValue == value)
return item ? item.dictColor : value
} else return value
},
}
export default $dict