| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- import { type AccountFormState, type PeopleModel, transformAccount } from '@/model';
- import type { UserModel } from '@/model/system.model';
- import request from '@/request/alova';
- import router from '@/router';
- interface Menu {
- label: string;
- title: string;
- key: string;
- children?: Menu[];
- }
- export interface AccountModel {
- token: string;
- local: PeopleModel;
- menus?: Menu[];
- user?: UserModel;
- }
- export function loginMethod(data: AccountFormState) {
- return request.Post<string, { access_token: string }>(`/auth/token`, data, {
- transform(data, headers) {
- return `Bearer ${data.access_token}`;
- },
- });
- }
- export function accountMethod(token: string) {
- return request.Get<AccountModel>(`/system/user/getInfo`, {
- headers: { Authorization: token },
- transform(data: any, headers) {
- return {
- token,
- local: transformAccount(data.user),
- user: data.user,
- };
- },
- meta: { unconvert: true },
- });
- }
- export function getMenusMethod(account: AccountModel) {
- const routes = new Set(router.getRoutes().map((route) => route.path));
- const transformMenus = (data: any[], prefix?: string) => {
- const menus: Menu[] = [];
- if (!Array.isArray(data)) return menus;
- for (const menu of data) {
- const path = [prefix, menu?.path].filter((v) => v != null).join('/');
- const title = menu?.meta?.title ?? path;
- const children = transformMenus(menu.children, path === '/' ? '' : path);
- if (children.length > 1) {
- menus.push({ key: path, title, label: title, children });
- } else if (children.length === 1) {
- menus.push(children[0]);
- } else if (routes.has(path)) {
- menus.push({ key: path, title, label: title });
- }
- }
- return menus;
- };
- return request.Get<AccountModel, any[]>(`/system/menu/getRouters`, {
- headers: { Authorization: account.token },
- transform(data) {
- // data.push(
- // {
- // path: '/follow',
- // meta: {
- // title: '随访管理',
- // },
- // children: [
- // {
- // path: 'plan',
- // meta: {
- // title: '随访计划',
- // },
- // },
- // {
- // path: 'task',
- // meta: {
- // title: '随访任务',
- // },
- // },
- // {
- // path: 'assessment',
- // meta: {
- // title: '随访评估',
- // },
- // },
- // ],
- // },
- // {
- // path: '/tcmRecuperation',
- // meta: {
- // title: '中医调养',
- // },
- // children: [
- // {
- // path: 'preserve',
- // meta: {
- // title: '服务项目维护',
- // },
- // },
- // {
- // path: 'system',
- // meta: {
- // title: '系统服务包',
- // },
- // },
- // {
- // path: 'institution',
- // meta: {
- // title: '机构服务包',
- // },
- // },
- // ],
- // }
- // );
- // console.log(data);
- return { ...account, menus: transformMenus(data) };
- },
- });
- }
|