import { EntityDict } from 'oak-domain/lib/types'; import { Feature } from '../types/Feature'; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { Cache } from './cache'; import { LocalStorage } from './localStorage'; interface UserFeature extends Feature { getUserId(allowUnloggedIn?: boolean): string | undefined; isRoot(): boolean; } /** * 1、destEntity如果不写,只对root可见 * 2、destEntity为一些特殊的Entity时,actions/path可以不写 * 当前只支持userRelation,对此entity可以授权的用户可见 */ export interface Menu { destEntity?: T | ''; actions?: Array; path?: string; url: string; } export interface ConsoleContext { entity: keyof ED; entityId: string; } export type ConsoleAccessState = 'loading' | 'ready' | 'error'; export type ConsoleAvailableMenu> = OMenu & { sourceEntity?: keyof ED; available: boolean | null; }; export default abstract class Console> extends Feature { protected cache: Cache; protected localStorage: LocalStorage; protected abstract entities: (keyof ED)[]; protected abstract menus: OMenu[]; protected user: UserFeature; protected userId?: string; protected isRoot?: boolean; protected consoleContext?: ConsoleContext; private availMenus; private unsubFns; private accessState; private accessError?; private accessLoadGeneration; private contextLoaded; private contextLoadPromise?; private getEntityProjection; protected getContextEntities(): (keyof ED)[]; protected getRelationEntities(): (keyof ED)[]; protected isContextEntity(entity: keyof ED): boolean; protected isRelationEntity(entity: keyof ED): boolean; protected checkMenuAvailable(_menu: ConsoleAvailableMenu, _context: ConsoleContext): boolean | null | undefined; protected initializeDefaultContext(): void | Promise; private initialize; private ensureContextLoaded; private saveContext; private onUserChanged; private initAvailMenus; private checkAvailMenus; constructor(cache: Cache, localStorage: LocalStorage, user: UserFeature, getEntityProjection: (entity: T) => ED[T]['Projection']); private loadContext; setContext(entity: keyof ED, entityId: string): void; getContext(): ConsoleContext | undefined; getAccessState(): ConsoleAccessState; getAccessError(): unknown; reloadAccess(): Promise; getAvailMenus(): ConsoleAvailableMenu[]; /** * 检查当前url是否可以访问 * @param url * @returns * true: 可以访问 * false: 无权访问 * null: 上下文不匹配 * undefined: menu中没有此url */ checkUrlAvailable(url: string): boolean | null | undefined; } export {};