61 lines
2.2 KiB
TypeScript
61 lines
2.2 KiB
TypeScript
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<ED extends EntityDict & BaseEntityDict, T extends keyof ED> {
|
||
destEntity?: T | '';
|
||
actions?: Array<ED[T]['Action']>;
|
||
path?: string;
|
||
url: string;
|
||
}
|
||
export interface ConsoleContext<ED extends EntityDict & BaseEntityDict> {
|
||
entity: keyof ED;
|
||
entityId: string;
|
||
}
|
||
export default abstract class Console<ED extends EntityDict & BaseEntityDict, OMenu extends Menu<ED, keyof ED>> extends Feature {
|
||
protected cache: Cache<ED>;
|
||
protected localStorage: LocalStorage;
|
||
protected abstract entities: (keyof ED)[];
|
||
protected abstract menus: OMenu[];
|
||
protected user: UserFeature;
|
||
protected userId?: string;
|
||
protected isRoot?: boolean;
|
||
protected consoleContext?: ConsoleContext<ED>;
|
||
private availMenus;
|
||
private unsubFns;
|
||
private initialize;
|
||
private saveContext;
|
||
private onUserChanged;
|
||
private initAvailMenus;
|
||
private checkAvailMenus;
|
||
constructor(cache: Cache<ED>, localStorage: LocalStorage, user: UserFeature, getEntityProjection: <T extends keyof ED>(entity: T) => ED[T]['Projection']);
|
||
private loadContext;
|
||
setContext(entity: keyof ED, entityId: string): void;
|
||
getContext(): ConsoleContext<ED> | undefined;
|
||
getAvailMenus(): (OMenu & {
|
||
sourceEntity?: keyof ED;
|
||
available: boolean | null;
|
||
})[];
|
||
/**
|
||
* 检查当前url是否可以访问
|
||
* @param url
|
||
* @returns
|
||
* true: 可以访问
|
||
* false: 无权访问
|
||
* null: 上下文不匹配
|
||
* undefined: menu中没有此url
|
||
*/
|
||
checkUrlAvailable(url: string): boolean | null | undefined;
|
||
}
|
||
export {};
|