| | |
| | | import { Route } from '@/router'; |
| | | import type { OperationBtnType, ColumnPropsMap } from '@bole-core/components'; |
| | | import type { OperationBtnType, ColumnPropsMap, ModuleColumnDto } from '@bole-core/components'; |
| | | import { |
| | | useAccess as useBoleAccess, |
| | | useGroupColumns as useBoleGroupColumns, |
| | |
| | | } from '@bole-core/components'; |
| | | import type { Ref, ComputedRef } from 'vue'; |
| | | import { myClient } from '@/constants/query'; |
| | | import * as menuServices from '@/services/api/menu'; |
| | | |
| | | type UseAccessOptions = { |
| | | operationBtnMap?: Record<string, OperationBtnType>; |
| | |
| | | |
| | | const moduleId = route.meta.moduleId; |
| | | |
| | | const groupName = 'default'; |
| | | |
| | | return useBoleAccess({ |
| | | queryKey: ['baseModuleServices/getCurrentSubModuleList', { moduleId }], |
| | | queryKey: ['menuServices/getMenu', { moduleId }], |
| | | service: async () => { |
| | | // return await baseModuleServices.getCurrentSubModuleList({ moduleId }, { showLoading: false }); |
| | | return await Promise.resolve({ |
| | | pageButton: [], |
| | | dataButton: [], |
| | | column: [], |
| | | }); |
| | | const res = await menuServices.getMenu({ id: moduleId }); |
| | | const group = res.groups.find((g) => g.group === groupName); |
| | | const pageButtonLocation = group?.buttonLocations?.find?.( |
| | | (buttonLocation) => buttonLocation.location === SubModuleKey[SubModuleType.PageButton] |
| | | ); |
| | | const dataButtonLocation = group?.buttonLocations?.find?.( |
| | | (buttonLocation) => buttonLocation.location === SubModuleKey[SubModuleType.DataButton] |
| | | ); |
| | | return { |
| | | pageButton: menuButtonAdapter(pageButtonLocation, SubModuleType.PageButton), |
| | | dataButton: menuButtonAdapter(dataButtonLocation, SubModuleType.DataButton), |
| | | column: menuFieldsAdapter(group?.fields ?? []), |
| | | }; |
| | | }, |
| | | ...options, |
| | | }); |
| | | } |
| | | |
| | | function menuButtonAdapter(buttonLocation: API.GetMenuQueryResultButtonLocation, buttonType) { |
| | | const buttons = buttonLocation?.buttons ?? []; |
| | | return buttons.map((x) => ({ |
| | | id: x.id, |
| | | moduleId: '', |
| | | parentId: '', |
| | | enCode: x.code, |
| | | name: x.name, |
| | | sortCode: x.sort, |
| | | buttonType: buttonType, |
| | | hasCheck: x.isChecked, |
| | | })); |
| | | } |
| | | |
| | | function menuFieldsAdapter(fields: API.GetMenuQueryResultField[]) { |
| | | return fields.map((x) => ({ |
| | | id: x.id, |
| | | moduleId: '', |
| | | parentId: '', |
| | | enCode: x.code, |
| | | name: x.name, |
| | | sortCode: x.sort, |
| | | width: Number(x.width), |
| | | hasCheck: x.isChecked, |
| | | fixed: false, |
| | | isShow: true, |
| | | })); |
| | | } |
| | | |
| | | export function useClearSubModule() { |
| | | function clearSubModule() { |
| | | myClient.removeQueries({ queryKey: ['baseModuleServices/getCurrentSubModuleList'] }); |
| | | myClient.removeQueries({ queryKey: ['menuServices/getMenu'] }); |
| | | } |
| | | |
| | | return { clearSubModule }; |
| | |
| | | /** |
| | | * 对columns进行分组 |
| | | */ |
| | | export function useGroupColumns(columns: Ref<API.ModuleColumnDto[]>, groups: string[]) { |
| | | export function useGroupColumns(columns: Ref<ModuleColumnDto[]>, groups: string[]) { |
| | | //@ts-ignore |
| | | return useBoleGroupColumns(columns, groups); |
| | | } |