import { useQuery } from '@tanstack/vue-query' import { getDict } from '@/service/system' import { DictRecord } from '@/interface/dict' import { Ref } from 'vue' /** * 根据类型获取字典 * @param dictType */ export const useDict = ( dictType: string ): [data: Ref, isLoading: Ref] => { const { data, isLoading } = useQuery(['dictList', dictType], async () => await getDict(dictType)) return [data, isLoading] } /** * 获取对应字典label * */ export const getDictName = (value: number, targetDict: DictRecord[]): string => { const target = targetDict?.find((item) => String(item.value) === String(value)) return target?.label ?? '' }