增加字典功能
This commit is contained in:
63
src/store/dict.ts
Normal file
63
src/store/dict.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
|
||||
export const useDictStore = defineStore("dict", () => {
|
||||
const dict = ref<any[]>([]);
|
||||
|
||||
// 获取字典
|
||||
function getDict(_key: string) {
|
||||
if (_key == null && _key == "") {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
dict.value.forEach(item => {
|
||||
if (item.key == _key) {
|
||||
return item.value;
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 设置字典
|
||||
function setDict(_key: string, value: string | number) {
|
||||
if (!_key) return;
|
||||
dict.value.push({
|
||||
key: _key,
|
||||
value: value
|
||||
});
|
||||
}
|
||||
|
||||
// 删除字典
|
||||
function removeDict(_key: string) {
|
||||
var bln = false;
|
||||
try {
|
||||
dict.value.forEach((item, index) => {
|
||||
if (item.key == _key) {
|
||||
dict.value.splice(index, 1);
|
||||
bln = true;
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
bln = false;
|
||||
}
|
||||
return bln;
|
||||
}
|
||||
|
||||
// 清空字典
|
||||
function cleanDict() {
|
||||
dict.value = new Array();
|
||||
}
|
||||
// 初始字典
|
||||
function initDict() { }
|
||||
|
||||
return {
|
||||
dict,
|
||||
getDict,
|
||||
setDict,
|
||||
removeDict,
|
||||
cleanDict,
|
||||
initDict,
|
||||
};
|
||||
});
|
||||
@@ -2,3 +2,4 @@ export * from './auth';
|
||||
export * from './user';
|
||||
export * from './pwo';
|
||||
export * from './job';
|
||||
export * from './dict';
|
||||
|
||||
Reference in New Issue
Block a user