You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.2 KiB
TypeScript

3 years ago
export const useDictStore = defineStore('dict', () => {
const dict = ref<Map<string, DictDataOption[]>>(new Map());
3 years ago
/**
*
* @param _key key
*/
const getDict = (_key: string): DictDataOption[] | null => {
if (!_key) {
return null;
}
return dict.value.get(_key) || null;
};
3 years ago
/**
*
* @param _key key
* @param _value value
*/
const setDict = (_key: string, _value: DictDataOption[]) => {
if (!_key) {
return false;
}
try {
dict.value.set(_key, _value);
return true;
} catch (e) {
console.error('Error in setDict:', e);
return false;
}
};
3 years ago
/**
*
* @param _key
*/
const removeDict = (_key: string): boolean => {
if (!_key) {
return false;
}
try {
return dict.value.delete(_key);
} catch (e) {
console.error('Error in removeDict:', e);
return false;
}
};
3 years ago
/**
*
*/
const cleanDict = (): void => {
dict.value.clear();
};
3 years ago
return {
dict,
getDict,
setDict,
removeDict,
cleanDict
};
3 years ago
});
export default useDictStore;