<%_ if (position === 'import') { _%>
  <%_ if (clientTheme === 'antd' && clientFramework === 'react') { _%>
import { TargetType } from '@/models/enumerations/target-type.model';
  <%_ } _%>
<%_ } _%>
<%_ if (position === 'method') { _%>
  <%_ if (clientTheme === 'vben' && clientFramework === 'vue') { _%>
  // prettier-ignore
  treeByLogin(): Promise<any> {
    return defHttp.get({ url: `${apiUrl}/current-user` });
  },
  <%_ } _%>
  <%_ if (clientTheme === 'antd' && clientFramework === 'react') { _%>
// prettier-ignore
function transformViewPermissionsToMenus(viewPermissions: IViewPermission[]): any[] {
    const result: any[] = [];
    viewPermissions.forEach(viewPermission => {
      const route: any = {};
      // menu.disabled = viewPermission.disabled ?? undefined;
      // menu.externalLink = viewPermission.externalLink ?? undefined;
      // menu.group = viewPermission.group ?? undefined;
      // menu.hide = viewPermission.hide ?? undefined;
      // menu.hideInBreadcrumb = viewPermission.hideInBreadcrumb ?? undefined;
      // menu.i18n = viewPermission.i18n ?? undefined;
      route.path = viewPermission.link ?? undefined;
      route.name = viewPermission.code ?? undefined;
      route.icon = viewPermission.icon ?? undefined;
      route.component = viewPermission.componentFile ?? undefined;
      route.redirect = viewPermission.redirect ?? undefined;
      // menu.link = viewPermission.link ?? undefined;
      switch (viewPermission.target) {
        case TargetType.BLANK:
          route.target = '_blank';
          break;
        case TargetType.PARENT:
          route.target = '_parent';
          break;
        case TargetType.SELF:
          route.target = '_self';
          break;
        case TargetType.TOP:
          route.target = '_top';
      }
      route.text = viewPermission.text ?? undefined;
      // menu.shortcut = viewPermission.shortcut ?? undefined;
      // menu.shortcutRoot = viewPermission.shortcutRoot ?? undefined;
      // menu.reuse = viewPermission.reuse ?? undefined;
      if (viewPermission.children) {
        route.routes = transformViewPermissionsToMenus(viewPermission.children);
      }
      result.push(route);
    });
    return result;
  }

export async function treeByLogin(): Promise<any> {
  return new Promise<IViewPermission[]>((resolve, reject) => {
    request(`${apiUrl}/current-user`, { skipErrorHandler: true, method: 'GET' })
      .then(res => { resolve(transformViewPermissionsToMenus(res)); })
      .catch(err => { reject(err);});
   });
}
  <%_ } _%>
  <%_ if (clientFramework === 'angular' && clientFramework === 'alain') { _%>

  treeByLogin(): Observable<PageData<IViewPermission>> {
    return this.http.get<IViewPermission[]>(`${this.resourceUrl}/current-user`, {}, { observe: 'response' }).pipe(
      map(res => {
        return {
          total: Number(res.headers.get('X-Total-Count') || '0'),
          items: res.body,
        } as PageData<IViewPermission>;
      }),
    );
  }
  <%_ } _%>
<%_ } _%>
