This commit is contained in:
ln1778 2024-06-20 14:52:37 +08:00
parent f510fc328a
commit fc13e32cd7
4 changed files with 20 additions and 15 deletions

View File

@ -3,7 +3,7 @@ import { mergeRecursive } from "./../utils/ruoyi";
import DictMeta from './DictMeta'
import DictData from './DictData'
import { getDicts as getDicts } from './../api/InventoryManagement';
import request from './../utils/request';
const DEFAULT_DICT_OPTIONS = {
@ -24,7 +24,7 @@ export default class Dict {
this.raw={}
}
init(options) {
init(options,apiurl) {
return new Promise((r)=>{
let params=Object.assign([],options);
if (options instanceof Array) {
@ -36,7 +36,8 @@ export default class Dict {
r();
throw new Error('need dict types')
}
getRequest(params).then((res)=>{
getRequest(params,apiurl).then((res)=>{
if(res&&res.datas){
const response=res.datas;
sessionStorage.setItem("dictdata",JSON.stringify(response));
@ -174,10 +175,19 @@ export default class Dict {
}
function getRequest(options) {
function getRequest(options,apiurl) {
if(apiurl&&apiurl!=""){
return request({
url: apiurl,
method: 'post',
data: {dict_code:Array.isArray(dictType)?dictType:[dictType]}
})
}else{
return getDicts(options);
}
}
/**

View File

@ -8,6 +8,7 @@ export default function (Vue, options) {
if (this.$options === undefined || this.$options.dicts === undefined || this.$options.dicts === null) {
return {}
}
const dict = new Dict()
dict.owner = this
return {
@ -25,7 +26,7 @@ export default function (Vue, options) {
let dicttime=sessionStorage.getItem("dicttime");
if(dicttime&&new Date().getTime()-Number(dicttime)>1000*60*720){
options.onCreated && options.onCreated(this.dict)
this.dict.init(this.$options.dicts).then(() => {
this.dict.init(this.$options.dicts,this.$options.apiurl).then(() => {
this.dictstatus = true;
sessionStorage.setItem("dicttime",new Date().getTime());
options.onReady && options.onReady(this.dict)
@ -72,7 +73,7 @@ export default function (Vue, options) {
}
} else {
options.onCreated && options.onCreated(this.dict)
this.dict.init(this.$options.dicts).then(() => {
this.dict.init(this.$options.dicts,this.$options.apiurl).then(() => {
this.dictstatus = true;
sessionStorage.setItem("dicttime",new Date().getTime());
options.onReady && options.onReady(this.dict)

View File

@ -36,10 +36,6 @@ const componentarr = [
Configuration
];
let dictapi=DataDict;
const setDicturl=(fn)=>{
dictapi=fn
}
const install = function (Vue) {
// 判断是否安装
if (install.installed) return;
@ -55,7 +51,7 @@ const install = function (Vue) {
valueField: 'dictValue',
//这个函数用来请求数据字典的数据,调用 getDicts() 函数,并使用传入的 dictMeta.type 来获取相应类型的数据字典
request(dictMeta) {
return dictapi(dictMeta.type).then(res => res.datas)
return getDicts(dictMeta.type).then(res => res.datas)
},
},
},
@ -69,9 +65,7 @@ if (typeof window !== "undefined" && window.Vue) {
install(window.Vue);
}
export default {
setDicturl:()=>{},
install,
...componentarr,
}

View File

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