import { reactive } from 'vue'; import { dictData } from "@/api/user"; // 初始化全局响应式字典缓存 let dictCache = uni.getStorageSync("dictCache"); const reactiveDictCache = reactive(dictCache ? JSON.parse(dictCache) : {}); /** * 获取字典数据(带缓存) */ export const getDictOptions = async (dictType) => { if (!reactiveDictCache[dictType]) { const response = await dictData(dictType); reactiveDictCache[dictType] = response.data; // 将更新后的缓存保存回本地存储 uni.setStorageSync('dictCache', JSON.stringify(reactiveDictCache)); } return reactiveDictCache[dictType]; }; /** * 同步获取字典标签 */ export const getDictLabelSync = (dictType, value) => { const dictOptions = reactiveDictCache[dictType] || []; const item = dictOptions.find(item => item.value === String(value)); return item?.label || ''; }; export const DICT_TYPE = { SYSTEM_CAZT: 'system_cazt', SYSTEM_LSDJ: 'system_lsdj', SYSTEM_CFLX: 'system_cflx', SYSTEM_QYXZ: 'system_qyxz', SYSTEM_LSPZ: 'system_lspz' };