/** 菜单管理列表加载适配(任务 54):GET /api/admin/permission-menus(admin) → 展示树。 */ import { http } from '@/api/http' import { unwrap } from '@/api/envelope' import { ADMIN_MENU_TYPE, buildMenuManageTree, parseMenuManageItem, parseMenuManageList, toMenuCreateRequest, type MenuManageForm, type MenuManageNode, } from './menu-manage-model' export const MENUS_ENDPOINT = '/api/admin/permission-menus' /** 拉取扁平可编辑菜单节点。 */ export async function fetchMenuManageNodes(): Promise { const { data } = await http.get(MENUS_ENDPOINT, { params: { menuType: ADMIN_MENU_TYPE } }) return parseMenuManageList(data) } /** 拉取并按 parentId 组装成展示树。 */ export async function loadMenuManageTree(): Promise { return buildMenuManageTree(await fetchMenuManageNodes()) } /** 新建菜单:POST /api/admin/permission-menus,返回后端落库节点。 */ export async function createMenu(form: MenuManageForm): Promise { const { data } = await http.post(MENUS_ENDPOINT, toMenuCreateRequest(form)) const created = parseMenuManageItem(unwrap(data)) if (!created) throw new Error('创建菜单响应异常:缺少菜单数据') return created }