| import * as menuServices from '@/services/api/menu'; | 
| import { flattenTree } from '@/utils'; | 
| import { DaPengAccessAdapter } from '@bole-core/components'; | 
| import { useQuery, useQueryClient } from '@tanstack/vue-query'; | 
|   | 
| type UseMenusOptions = { | 
|   params: MaybeRef<API.APIgetMenusParams>; | 
|   enabled?: MaybeRef<boolean>; | 
| }; | 
|   | 
| export function useMenus({ params, enabled = true }: UseMenusOptions) { | 
|   const queryClient = useQueryClient(); | 
|   | 
|   const { data, refetch } = useQuery({ | 
|     queryKey: ['menuServices/getMenus', params], | 
|     queryFn: async () => { | 
|       return await menuServices.getMenus(unref(params), { | 
|         showLoading: false, | 
|       }); | 
|     }, | 
|     placeholderData: () => [] as API.GetMenusQueryResultItem[], | 
|     staleTime: Infinity, | 
|     enabled: enabled, | 
|   }); | 
|   | 
|   const flattenMenus = computed(() => flattenTree(data.value)); | 
|   | 
|   function getMenuById(id: string) { | 
|     return flattenMenus.value.find((item) => item.id === id); | 
|   } | 
|   | 
|   return { | 
|     menusTree: data, | 
|     refetch, | 
|     getMenuById, | 
|   }; | 
| } | 
|   | 
| type UseMenuOptions = { | 
|   params: MaybeRef<API.APIgetMenuParams>; | 
|   enabled?: MaybeRef<boolean>; | 
| }; | 
|   | 
| export function useMenu({ params, enabled = true }: UseMenuOptions) { | 
|   const queryClient = useQueryClient(); | 
|   | 
|   const { data, refetch } = useQuery({ | 
|     queryKey: ['menuServices/getMenu', params], | 
|     queryFn: async () => { | 
|       return await menuServices.getMenu(unref(params), { | 
|         showLoading: false, | 
|       }); | 
|     }, | 
|     placeholderData: () => ({} as API.GetMenuQueryResult), | 
|     enabled: enabled, | 
|   }); | 
|   | 
|   const menuDefaultGroup = computed( | 
|     () => DaPengAccessAdapter.getMenuGroupAdapter(data.value?.groups ?? []) ?? {} | 
|   ); | 
|   | 
|   const menuFields = computed(() => { | 
|     return menuDefaultGroup.value.fields ?? []; | 
|   }); | 
|   | 
|   const menuPageButtons = computed(() => { | 
|     const pageButtonLocation = DaPengAccessAdapter.getButtonLocationAdapter( | 
|       menuDefaultGroup.value, | 
|       SubModuleKey[SubModuleType.PageButton] | 
|     ); | 
|     return pageButtonLocation?.buttons ?? []; | 
|   }); | 
|   | 
|   const menuDataButtons = computed(() => { | 
|     const pageButtonLocation = DaPengAccessAdapter.getButtonLocationAdapter( | 
|       menuDefaultGroup.value, | 
|       SubModuleKey[SubModuleType.DataButton] | 
|     ); | 
|     return pageButtonLocation?.buttons ?? []; | 
|   }); | 
|   | 
|   return { | 
|     menu: data, | 
|     refetch, | 
|     menuFields, | 
|     menuPageButtons, | 
|     menuDataButtons, | 
|   }; | 
| } |