增加字典功能

This commit is contained in:
tao
2025-12-29 17:20:34 +08:00
parent 0bc46dbd14
commit ae56afcf93
8 changed files with 333 additions and 0 deletions

63
src/store/dict.ts Normal file
View 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,
};
});

View File

@@ -2,3 +2,4 @@ export * from './auth';
export * from './user';
export * from './pwo';
export * from './job';
export * from './dict';