import { defineStore } from 'pinia'; import { ref } from 'vue'; import { setCache, getCache, removeCache, ArrToObj } from '@/utils'; export const global = defineStore('global', () => { const dict = ref(getCache('dict') || {}); // 获取字典列表(简化实现) const getDicts = async () => { // 作业功能暂不需要字典 }; // 获取字典 const getDict = (key: string, full = false) => { const d = dict.value.find ? dict.value.find((i: anyObj) => i.code === key) : null; const child = d ? d.children : []; if (full) { return { dict: child, dictObj: ArrToObj(child, 'value', 'code'), }; } return child; }; // 获取未读(简化实现) const getUnread = async () => { // 作业功能暂不需要未读数 }; const clear = () => { dict.value = {}; removeCache('dict'); }; return { dict, getDicts, getDict, getUnread, clear, }; });