1234567891011121314151617181920212223 |
- 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<DictRecord[] | undefined>, isLoading: Ref<boolean>] => {
- 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 ?? ''
- }
|