mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-12-31 22:57:17 +08:00
新增:新增公共查询枚举字典 API,优化前端获取枚举数据的方式
This commit is contained in:
@@ -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;
|
||||
|
||||
54
continew-admin-ui/src/store/modules/dict/index.ts
Normal file
54
continew-admin-ui/src/store/modules/dict/index.ts
Normal 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;
|
||||
9
continew-admin-ui/src/store/modules/dict/types.ts
Normal file
9
continew-admin-ui/src/store/modules/dict/types.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export interface LabelValueState {
|
||||
label: string;
|
||||
value: any;
|
||||
}
|
||||
|
||||
export interface DictState {
|
||||
name: string;
|
||||
detail: Array<LabelValueState>;
|
||||
}
|
||||
Reference in New Issue
Block a user