import { computed } from 'vue' import { useDictStore } from '@/stores/modules/dict' import type { TagType } from '@/types/crud' /** * 读取某个字典类型的字典项,返回三种视图: * - items: 响应式字典项数组(label/value/colorType/sort) * - tagMap: value → { label, type },供表格标签列使用 * - options: { label, value }[],供下拉选择使用 */ export function useDict(code: string) { const store = useDictStore() const items = computed(() => store.dicts[code] ?? []) const tagMap = computed(() => { const map: Record = {} for (const it of items.value) { map[it.value] = { label: it.label, type: (it.colorType ?? 'info') as TagType } } return map }) const options = computed(() => items.value.map((it) => ({ label: it.label, value: it.value }))) return { items, tagMap, options } }