diff --git a/dict/Dict.js b/dict/Dict.js index 7fa30d6..2c1e9b1 100644 --- a/dict/Dict.js +++ b/dict/Dict.js @@ -40,7 +40,7 @@ export default class Dict { r(); throw new Error('need dict types') } - getRequest(params,this.apiurl).then((res)=>{ + this.getRequest(params).then((res)=>{ if(res&&res.datas){ const response=res.datas; sessionStorage.setItem("dictdata",JSON.stringify(response)); @@ -95,7 +95,7 @@ export default class Dict { throw new Error('need dict types') } - getRequest(params,this.apiurl).then((res)=>{ + this.getRequest(params).then((res)=>{ if(res&&res.datas){ const response=res.datas; Object.keys(response).map((k,i)=>{ @@ -173,32 +173,23 @@ export default class Dict { if (dictMeta === undefined) { return Promise.reject(`the dict meta of ${type} was not found`) } - return loadDict(this, dictMeta) + return this.loadDict(this, dictMeta,this.apiurl) } -} - - -function getRequest(options,apiurl) { + 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)?options:[options]} }); } - - - -/** - * 加载字典 - * @param {Dict} dict 字典 - * @param {DictMeta} dictMeta 字典元数据 - * @returns {Promise} - */ -function loadDict(dict, dictMeta) { - return dictMeta.request(dictMeta) - .then(response => { + loadDict(dict, dictMeta,apiurl) { + return request({ + url: apiurl||"/api/sysdict/get_dict", + method: 'post', + data: {dict_code:Array.isArray(dictMeta)?options:[dictMeta]} + }).then(response => { const type = dictMeta.type - + let dicts = dictMeta.responseConverter(response, dictMeta) if (!(dicts instanceof Array)) { console.error('the return of responseConverter must be Array.') @@ -212,5 +203,8 @@ function loadDict(dict, dictMeta) { Vue.set(dict.label[type], d.value, d.label) }) return dicts - }) -} + }); + } +} + + diff --git a/dict/index.js b/dict/index.js index 18df17f..54a4ccb 100644 --- a/dict/index.js +++ b/dict/index.js @@ -119,7 +119,7 @@ export default function (Vue, options) { return filters&&filters.label || '-' }, getDict(name) { - new Promise((r)=>{ + return new Promise((r)=>{ this.dict = new Dict(this.apiurl); this.dict.owner = this; if(this.apiurl){ diff --git a/package.json b/package.json index c85314d..464cdbc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "erp-element-ui", - "version": "1.0.44", + "version": "1.0.46", "description": "", "main": "index.js", "scripts": { diff --git a/utils/request.js b/utils/request.js index c95d036..72a0f11 100644 --- a/utils/request.js +++ b/utils/request.js @@ -10,8 +10,9 @@ import axios from 'axios' import { MessageBox, Message } from 'element-ui'; // import cancelClass from './cancelToken' +console.log(window.VUE_APP_BASE_API,"window.VUE_APP_BASE_API") const service = axios.create({ - baseURL: window.VUE_APP_BASE_API?window.VUE_APP_BASE_API:"http://dev-erp-api.xtkj99.com:7890", // api 的 base_url + baseURL: window.VUE_APP_BASE_API||(process.env.VUE_APP_BASE_API)||"http://dev-erp-api.xtkj99.com:7890", // api 的 base_url timeout: 1000 * 60 * 2 // 接口超时 })