整合js工具类
This commit is contained in:
@@ -12,6 +12,9 @@
|
|||||||
"main": "src/apps/index.js",
|
"main": "src/apps/index.js",
|
||||||
"files": [
|
"files": [
|
||||||
"src/components",
|
"src/components",
|
||||||
|
"src/common/util.js",
|
||||||
|
"src/common/dict.js",
|
||||||
|
"src/common/monent.js",
|
||||||
"src/apps",
|
"src/apps",
|
||||||
"src/saas"
|
"src/saas"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,50 +1,66 @@
|
|||||||
import request from "./axios";
|
|
||||||
import store from "../store";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 封装字典工具类
|
* 封装字典工具类
|
||||||
*/
|
*/
|
||||||
const $dict = {
|
const $dict = {
|
||||||
vueStore: null,
|
instance: null,
|
||||||
url: "/admin/dictionary/queryValsByCodeList",
|
url: "/admin/dictionary/queryValsByCodeList",
|
||||||
setUrl(v) {
|
init(config) {
|
||||||
this.url = v
|
this.instance = config?.instance
|
||||||
|
this.url = config?.url || this.url
|
||||||
|
},
|
||||||
|
dicts() {
|
||||||
|
return uni.getStorageSync('dicts') || [];
|
||||||
},
|
},
|
||||||
load(...code) {
|
load(...code) {
|
||||||
if (!this.vueStore) this.vueStore = store
|
return this.instance && this.instance.post(this.url, null, {
|
||||||
return request.post(this.url, null, {
|
withoutToken:true,
|
||||||
params: {
|
params: {
|
||||||
codeList: code.join(',')
|
codeList: code.toString()
|
||||||
}
|
}
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
this.vueStore.commit("setDicts", res.data)
|
if (res && res.data) {
|
||||||
|
let cacheDicts = {},
|
||||||
|
meta = {};
|
||||||
|
this.dicts().map((e) => (cacheDicts[e.key] = e));
|
||||||
|
res.data.map((e) => (meta[e.key] = e));
|
||||||
|
let dicts = {...cacheDicts, ...meta};
|
||||||
|
uni.setStorageSync('dicts', Object.values(dicts));
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getDict(key) {
|
getDict(key) {
|
||||||
let dict = this.vueStore.getters.getDict(key)
|
if (this.dicts().length) {
|
||||||
return dict ? dict.values : []
|
let dict = this.dicts().find((e) => e.key == key);
|
||||||
|
return dict ? dict.values : [];
|
||||||
|
} else return [];
|
||||||
},
|
},
|
||||||
getValue(key, label) {
|
getValue(key, label) {
|
||||||
let dict = this.vueStore.getters.getDict(key)
|
if (this.dicts().length) {
|
||||||
if (dict) {
|
let dict = this.dicts().find((e) => e.key == key);
|
||||||
let item = dict.values.find(v => v.dictName == label)
|
if (dict) {
|
||||||
return item ? item.dictValue : label
|
let item = dict.values.find((v) => v.dictName == label);
|
||||||
} else return label
|
return item ? item.dictValue : label;
|
||||||
|
} else return label;
|
||||||
|
} else return label;
|
||||||
},
|
},
|
||||||
getLabel(key, value) {
|
getLabel(key, value) {
|
||||||
let dict = this.vueStore.getters.getDict(key)
|
if (this.dicts().length) {
|
||||||
if (dict) {
|
let dict = this.dicts().find((e) => e.key == key);
|
||||||
let item = dict.values.find(v => v.dictValue == value)
|
if (dict) {
|
||||||
return item ? item.dictName : value
|
let item = dict.values.find((v) => v.dictValue == value);
|
||||||
} else return value
|
return item ? item.dictName : value;
|
||||||
|
} else return value ? value : '';
|
||||||
|
} else return value ? value : '';
|
||||||
},
|
},
|
||||||
getColor(key, value) {
|
getColor(key, value) {
|
||||||
let dict = this.vueStore.getters.getDict(key)
|
if (this.dicts().length) {
|
||||||
if (dict) {
|
let dict = this.dicts().find((e) => e.key == key);
|
||||||
let item = dict.values.find(v => v.dictValue == value)
|
if (dict) {
|
||||||
return item ? item.dictColor : value
|
let item = dict.values.find((v) => v.dictValue == value);
|
||||||
} else return value
|
return item ? item.dictColor : value;
|
||||||
},
|
} else return value;
|
||||||
|
} else return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default $dict
|
export default $dict
|
||||||
|
|||||||
Reference in New Issue
Block a user