Files
yunzerwebsiteallinone/platform/src/composables/useDict.js
T
2026-11-16 17:22:50 +08:00

42 lines
1.1 KiB
JavaScript

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