import { computed } from 'vue' import { useDictStore } from '@/stores/dict' export function useDictionary(code) { const dictStore = useDictStore() dictStore.ensure(code) const items = computed(() => dictStore.getDictItemsSync(code)) const options = computed(() => items.value.map((it) => ({ label: it.item_label, value: it.item_value, tag_type: it.tag_type }))) return { items, options, label: (value, fallback) => dictStore.getDictLabel(code, value, fallback), tagType: (value, fallback) => dictStore.getDictTagType(code, value, fallback), find: (value) => dictStore.getDictItem(code, value) } } export function useDictLabel(code) { const dictStore = useDictStore() dictStore.ensure(code) return (value, fallback) => dictStore.getDictLabel(code, value, fallback) } export function useDictTagType(code) { const dictStore = useDictStore() dictStore.ensure(code) return (value, fallback) => dictStore.getDictTagType(code, value, fallback) } export function useDictPreload(codes) { const dictStore = useDictStore() return () => dictStore.preloadDicts(codes) } export default useDictionary