This commit is contained in:
ln1778 2024-06-20 15:20:05 +08:00
parent 5933f71cef
commit 3919ce012c
2 changed files with 20 additions and 8 deletions

View File

@ -22,9 +22,10 @@ export default class Dict {
this.label = {}
this.type = {}
this.raw={}
this.apiurl="/api/sysdict/get_dict";
}
init(options,apiurl) {
init(options,url) {
return new Promise((r)=>{
let params=Object.assign([],options);
if (options instanceof Array) {
@ -37,7 +38,10 @@ export default class Dict {
throw new Error('need dict types')
}
getRequest(params,apiurl).then((res)=>{
if(url){
this.apiurl=url;
}
getRequest(params).then((res)=>{
if(res&&res.datas){
const response=res.datas;
sessionStorage.setItem("dictdata",JSON.stringify(response));
@ -175,9 +179,9 @@ export default class Dict {
}
function getRequest(options,apiurl) {
function getRequest(options) {
return request({
url: apiurl||"/api/sysdict/get_dict",
url: this.apiurl||"/api/sysdict/get_dict",
method: 'post',
data: {dict_code:Array.isArray(options)?dictType:[options]}
});

View File

@ -5,13 +5,20 @@ export default function (Vue, options) {
mergeOptions(options)
Vue.mixin({
data() {
let apiurl="/api/sysdict/get_dict";
if (this.$options === undefined || this.$options.dicts === undefined || this.$options.dicts === null) {
return {}
}
const dict = new Dict()
dict.owner = this
const dict = new Dict();
if(this.$options.dictapiurl){
apiurl=this.$options.dictapiurl;
dict.apiurl=this.$options.dictapiurl;
}
dict.owner = this;
return {
apiurl,
dict,
dictstatus: false,
requesttime:0,
@ -114,6 +121,7 @@ export default function (Vue, options) {
new Promise((r)=>{
this.dict = new Dict();
this.dict.owner = this;
this.dict.apiurl=this.apiurl;
this.dict.getDict(name).then(() => {
r(this.dict);
})