新增:新增公共查询枚举字典 API,优化前端获取枚举数据的方式

This commit is contained in:
2023-02-26 21:49:03 +08:00
parent 8200ea822f
commit a79b3e0e96
18 changed files with 205 additions and 83 deletions

View File

@@ -1,9 +1,10 @@
import { createPinia } from 'pinia';
import useAppStore from './modules/app';
import useLoginStore from './modules/login';
import useDictStore from './modules/dict';
import useTabBarStore from './modules/tab-bar';
const pinia = createPinia();
export { useAppStore, useLoginStore, useTabBarStore };
export { useAppStore, useLoginStore, useDictStore, useTabBarStore };
export default pinia;

View File

@@ -0,0 +1,54 @@
import { defineStore } from 'pinia';
import { DictState, LabelValueState } from '@/store/modules/dict/types';
const useDictStore = defineStore('dict', {
state: () => ({ dict: [] as Array<DictState> }),
actions: {
// 获取字典
getDict(_name: string) {
if (_name === null && _name === '') {
return null;
}
try {
for (let i = 0; i < this.dict.length; i += 1) {
if (this.dict[i].name === _name) {
return this.dict[i].detail;
}
}
} catch (e) {
console.log(e);
}
return null;
},
// 设置字典
setDict(_name: string, detail: Array<LabelValueState>) {
if (_name !== null && _name !== '') {
this.dict.push({
name: _name,
detail,
});
}
},
// 删除字典
deleteDict(_name: string) {
let bln = false;
try {
for (let i = 0; i < this.dict.length; i += 1) {
if (this.dict[i].name === _name) {
this.dict.splice(i, 1);
return true;
}
}
} catch (e) {
bln = false;
}
return bln;
},
// 清空字典
cleanDict() {
this.dict = [];
},
},
});
export default useDictStore;

View File

@@ -0,0 +1,9 @@
export interface LabelValueState {
label: string;
value: any;
}
export interface DictState {
name: string;
detail: Array<LabelValueState>;
}