|
@@ -4,7 +4,11 @@ import type { SystemModel, TransformData } from '#/api';
|
|
|
|
|
|
|
|
import { http } from '#/api';
|
|
import { http } from '#/api';
|
|
|
import { fromRole } from '#/api/model';
|
|
import { fromRole } from '#/api/model';
|
|
|
-import { fromMenus } from '#/api/model/menu';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ filterMenusByPermissions,
|
|
|
|
|
+ fromTreeSelectMenus,
|
|
|
|
|
+ type TreeSelectMenuNode,
|
|
|
|
|
+} from '#/api/model/menu';
|
|
|
|
|
|
|
|
export namespace AccessModel {
|
|
export namespace AccessModel {
|
|
|
export interface LoginParams {
|
|
export interface LoginParams {
|
|
@@ -21,42 +25,19 @@ export namespace AccessModel {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function loginMethod(data: AccessModel.LoginParams) {
|
|
export function loginMethod(data: AccessModel.LoginParams) {
|
|
|
- return http.post<AccessModel.LoginResponse>(`/login`, data, {
|
|
|
|
|
|
|
+ return http.post<AccessModel.LoginResponse>(`/manager/auth/token`, data, {
|
|
|
meta: { login: true, visitor: true },
|
|
meta: { login: true, visitor: true },
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function getAccessMenuMethod(permissions?: string[]) {
|
|
export function getAccessMenuMethod(permissions?: string[]) {
|
|
|
- return http.post<SystemModel.Menu[], TransformData[]>(
|
|
|
|
|
- `/admin/menu/allMenu`,
|
|
|
|
|
- void 0,
|
|
|
|
|
|
|
+ return http.get<SystemModel.Menu[], TreeSelectMenuNode[]>(
|
|
|
|
|
+ `/manager/system/menu/treeselect`,
|
|
|
{
|
|
{
|
|
|
transform(data) {
|
|
transform(data) {
|
|
|
- const menus = fromMenus(data);
|
|
|
|
|
|
|
+ const menus = fromTreeSelectMenus(data);
|
|
|
if (!permissions?.length) return menus;
|
|
if (!permissions?.length) return menus;
|
|
|
- const forEach = (
|
|
|
|
|
- permissions: Set<string>,
|
|
|
|
|
- menus: SystemModel.Menu[],
|
|
|
|
|
- parentMenu: SystemModel.Menu[] = [],
|
|
|
|
|
- ) => {
|
|
|
|
|
- for (const menu of menus) {
|
|
|
|
|
- const id = menu.id;
|
|
|
|
|
- if (permissions.has(id)) {
|
|
|
|
|
- permissions.delete(id);
|
|
|
|
|
- if (menu.type === 'menu') parentMenu.push(menu);
|
|
|
|
|
- else if (menu.type === 'catalog' && menu.children?.length) {
|
|
|
|
|
- const parent = { ...menu, children: [] };
|
|
|
|
|
- parentMenu.push(parent);
|
|
|
|
|
- forEach(permissions, menu.children, parent.children);
|
|
|
|
|
- }
|
|
|
|
|
- } else if (menu.type === 'catalog' && menu.children?.length) {
|
|
|
|
|
- forEach(permissions, menu.children, parentMenu);
|
|
|
|
|
- }
|
|
|
|
|
- if (permissions.size === 0) break;
|
|
|
|
|
- }
|
|
|
|
|
- return parentMenu;
|
|
|
|
|
- };
|
|
|
|
|
- return forEach(new Set(permissions), menus);
|
|
|
|
|
|
|
+ return filterMenusByPermissions(permissions, menus);
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
);
|
|
);
|
|
@@ -64,7 +45,7 @@ export function getAccessMenuMethod(permissions?: string[]) {
|
|
|
|
|
|
|
|
export function getUserInfoMethod(token?: string) {
|
|
export function getUserInfoMethod(token?: string) {
|
|
|
return http.get<UserInfo & { roles: SystemModel.Role[] }, TransformData>(
|
|
return http.get<UserInfo & { roles: SystemModel.Role[] }, TransformData>(
|
|
|
- `/getInfo`,
|
|
|
|
|
|
|
+ `/manager/system/user/getInfo`,
|
|
|
{
|
|
{
|
|
|
headers: { Authorization: token },
|
|
headers: { Authorization: token },
|
|
|
transform(data, headers) {
|
|
transform(data, headers) {
|
|
@@ -82,5 +63,5 @@ export function getUserInfoMethod(token?: string) {
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
);
|
|
);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|