| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- import type { Recordable } from '@vben/types';
- import { requestClient } from '#/api/request';
- export namespace SystemMenuApi {
- /** 徽标颜色集合 */
- export const BadgeVariants = [
- 'default',
- 'destructive',
- 'primary',
- 'success',
- 'warning',
- ] as const;
- /** 徽标类型集合 */
- export const BadgeTypes = ['dot', 'normal'] as const;
- /** 菜单类型集合 */
- export const MenuTypes = [
- 'catalog',
- 'menu',
- 'embedded',
- 'link',
- 'button',
- ] as const;
- /** 系统菜单 */
- export interface SystemMenu {
- [key: string]: any;
- /** 后端权限标识 */
- authCode: string;
- /** 子级 */
- children?: SystemMenu[];
- /** 组件 */
- component?: string;
- /** 菜单ID */
- id: string;
- /** 菜单元数据 */
- meta?: {
- /** 激活时显示的图标 */
- activeIcon?: string;
- /** 作为路由时,需要激活的菜单的Path */
- activePath?: string;
- /** 固定在标签栏 */
- affixTab?: boolean;
- /** 在标签栏固定的顺序 */
- affixTabOrder?: number;
- /** 徽标内容(当徽标类型为normal时有效) */
- badge?: string;
- /** 徽标类型 */
- badgeType?: (typeof BadgeTypes)[number];
- /** 徽标颜色 */
- badgeVariants?: (typeof BadgeVariants)[number];
- /** 在菜单中隐藏下级 */
- hideChildrenInMenu?: boolean;
- /** 在面包屑中隐藏 */
- hideInBreadcrumb?: boolean;
- /** 在菜单中隐藏 */
- hideInMenu?: boolean;
- /** 在标签栏中隐藏 */
- hideInTab?: boolean;
- /** 菜单图标 */
- icon?: string;
- /** 内嵌Iframe的URL */
- iframeSrc?: string;
- /** 是否缓存页面 */
- keepAlive?: boolean;
- /** 外链页面的URL */
- link?: string;
- /** 同一个路由最大打开的标签数 */
- maxNumOfOpenTab?: number;
- /** 无需基础布局 */
- noBasicLayout?: boolean;
- /** 是否在新窗口打开 */
- openInNewWindow?: boolean;
- /** 菜单排序 */
- order?: number;
- /** 额外的路由参数 */
- query?: Recordable<any>;
- /** 菜单标题 */
- title?: string;
- };
- /** 菜单名称 */
- name: string;
- /** 路由路径 */
- path: string;
- /** 父级ID */
- pid: string;
- /** 重定向 */
- redirect?: string;
- /** 菜单类型 */
- type: (typeof MenuTypes)[number];
- }
- }
- /**
- * 获取菜单数据列表
- */
- async function getMenuList() {
- return requestClient.get<Array<SystemMenuApi.SystemMenu>>(
- '/system/menu/list',
- );
- }
- async function isMenuNameExists(
- name: string,
- id?: SystemMenuApi.SystemMenu['id'],
- ) {
- return requestClient.get<boolean>('/system/menu/name-exists', {
- params: { id, name },
- });
- }
- async function isMenuPathExists(
- path: string,
- id?: SystemMenuApi.SystemMenu['id'],
- ) {
- return requestClient.get<boolean>('/system/menu/path-exists', {
- params: { id, path },
- });
- }
- /**
- * 创建菜单
- * @param data 菜单数据
- */
- async function createMenu(
- data: Omit<SystemMenuApi.SystemMenu, 'children' | 'id'>,
- ) {
- return requestClient.post('/system/menu', data);
- }
- /**
- * 更新菜单
- *
- * @param id 菜单 ID
- * @param data 菜单数据
- */
- async function updateMenu(
- id: string,
- data: Omit<SystemMenuApi.SystemMenu, 'children' | 'id'>,
- ) {
- return requestClient.put(`/system/menu/${id}`, data);
- }
- /**
- * 删除菜单
- * @param id 菜单 ID
- */
- async function deleteMenu(id: string) {
- return requestClient.delete(`/system/menu/${id}`);
- }
- export {
- createMenu,
- deleteMenu,
- getMenuList,
- isMenuNameExists,
- isMenuPathExists,
- updateMenu,
- };
|