Files
frontend_hmi_station/src/store/system/dict.ts
2026-01-12 17:17:58 +08:00

64 lines
1.1 KiB
TypeScript

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,
};
});