This commit is contained in:
ln1778 2024-06-20 16:17:29 +08:00
parent a47e763254
commit 69e9f881da
4 changed files with 21 additions and 26 deletions

View File

@ -40,7 +40,7 @@ export default class Dict {
r(); r();
throw new Error('need dict types') throw new Error('need dict types')
} }
getRequest(params,this.apiurl).then((res)=>{ this.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));
@ -95,7 +95,7 @@ export default class Dict {
throw new Error('need dict types') throw new Error('need dict types')
} }
getRequest(params,this.apiurl).then((res)=>{ this.getRequest(params).then((res)=>{
if(res&&res.datas){ if(res&&res.datas){
const response=res.datas; const response=res.datas;
Object.keys(response).map((k,i)=>{ Object.keys(response).map((k,i)=>{
@ -173,30 +173,21 @@ export default class Dict {
if (dictMeta === undefined) { if (dictMeta === undefined) {
return Promise.reject(`the dict meta of ${type} was not found`) return Promise.reject(`the dict meta of ${type} was not found`)
} }
return loadDict(this, dictMeta) return this.loadDict(this, dictMeta,this.apiurl)
} }
} getRequest(options) {
function getRequest(options,apiurl) {
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)?options:[options]} data: {dict_code:Array.isArray(options)?options:[options]}
}); });
} }
loadDict(dict, dictMeta,apiurl) {
return request({
url: apiurl||"/api/sysdict/get_dict",
/** method: 'post',
* 加载字典 data: {dict_code:Array.isArray(dictMeta)?options:[dictMeta]}
* @param {Dict} dict 字典 }).then(response => {
* @param {DictMeta} dictMeta 字典元数据
* @returns {Promise}
*/
function loadDict(dict, dictMeta) {
return dictMeta.request(dictMeta)
.then(response => {
const type = dictMeta.type const type = dictMeta.type
let dicts = dictMeta.responseConverter(response, dictMeta) let dicts = dictMeta.responseConverter(response, dictMeta)
@ -212,5 +203,8 @@ function loadDict(dict, dictMeta) {
Vue.set(dict.label[type], d.value, d.label) Vue.set(dict.label[type], d.value, d.label)
}) })
return dicts return dicts
}) });
} }
}

View File

@ -119,7 +119,7 @@ export default function (Vue, options) {
return filters&&filters.label || '-' return filters&&filters.label || '-'
}, },
getDict(name) { getDict(name) {
new Promise((r)=>{ return new Promise((r)=>{
this.dict = new Dict(this.apiurl); this.dict = new Dict(this.apiurl);
this.dict.owner = this; this.dict.owner = this;
if(this.apiurl){ if(this.apiurl){

View File

@ -1,6 +1,6 @@
{ {
"name": "erp-element-ui", "name": "erp-element-ui",
"version": "1.0.44", "version": "1.0.46",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@ -10,8 +10,9 @@ import axios from 'axios'
import { MessageBox, Message } from 'element-ui'; import { MessageBox, Message } from 'element-ui';
// import cancelClass from './cancelToken' // import cancelClass from './cancelToken'
console.log(window.VUE_APP_BASE_API,"window.VUE_APP_BASE_API")
const service = axios.create({ 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 // 接口超时 timeout: 1000 * 60 * 2 // 接口超时
}) })