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

View File

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