From 5e440a7dc434c43eb828fa62cf9c12b0078b8565 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期一, 20 一月 2025 11:36:18 +0800 Subject: [PATCH] !173 发布 5.3.0-BETA 公测版本 Merge pull request !173 from 疯狂的狮子Li/dev --- src/store/modules/dict.ts | 55 +++++++++++++++++++++---------------------------------- 1 files changed, 21 insertions(+), 34 deletions(-) diff --git a/src/store/modules/dict.ts b/src/store/modules/dict.ts index 2f937b9..cd1a41d 100644 --- a/src/store/modules/dict.ts +++ b/src/store/modules/dict.ts @@ -1,29 +1,15 @@ export const useDictStore = defineStore('dict', () => { - const dict = ref< - Array<{ - key: string; - value: DictDataOption[]; - }> - >([]); + const dict = ref<Map<string, DictDataOption[]>>(new Map()); /** * 鑾峰彇瀛楀吀 * @param _key 瀛楀吀key */ const getDict = (_key: string): DictDataOption[] | null => { - if (_key == null && _key == '') { + if (!_key) { return null; } - try { - for (let i = 0; i < dict.value.length; i++) { - if (dict.value[i].key == _key) { - return dict.value[i].value; - } - } - } catch (e) { - return null; - } - return null; + return dict.value.get(_key) || null; }; /** @@ -32,11 +18,15 @@ * @param _value 瀛楀吀value */ const setDict = (_key: string, _value: DictDataOption[]) => { - if (_key !== null && _key !== '') { - dict.value.push({ - key: _key, - value: _value - }); + if (!_key) { + return false; + } + try { + dict.value.set(_key, _value); + return true; + } catch (e) { + console.error('Error in setDict:', e); + return false; } }; @@ -45,25 +35,22 @@ * @param _key */ const removeDict = (_key: string): boolean => { - let bln = false; - try { - for (let i = 0; i < dict.value.length; i++) { - if (dict.value[i].key == _key) { - dict.value.splice(i, 1); - return true; - } - } - } catch (e) { - bln = false; + if (!_key) { + return false; } - return bln; + try { + return dict.value.delete(_key); + } catch (e) { + console.error('Error in removeDict:', e); + return false; + } }; /** * 娓呯┖瀛楀吀 */ const cleanDict = (): void => { - dict.value = []; + dict.value.clear(); }; return { -- Gitblit v1.9.3