diff --git a/template/types/globals.d.ts b/template/types/globals.d.ts index 1064ffd..a7bfca1 100644 --- a/template/types/globals.d.ts +++ b/template/types/globals.d.ts @@ -1,17 +1,125 @@ +type ExtensionMenuParent = + | 'topbar' + | 'global' + | 'toolbox' + | 'access' + | 'cluster' + | 'workspace' + | 'project' + | 'platformSettings'; + +interface ExtensionAction { + actionType?: + | 'url-router' + | 'url-current-tab' + | 'url-new-tab' + | 'url-new-window' + | 'v3-modal' + | 'modal' + | 'sheet'; + actionValue?: string; +} + +interface ExtensionMenu extends ExtensionAction { + parent: ExtensionMenuParent; + name: string; + link?: string; + title: string; + icon?: string; + order?: number; + desc?: string; + skipAuth?: boolean; + authKey?: string; + authAction?: string; + children?: ExtensionMenu[]; + ksModule?: string; + clusterModule?: string; + workspaceModule?: string; +} + +interface Extension { + routes?: Record[]; + routesByPatch?: Record[]; + menus?: ExtensionMenu[]; + locales?: Record; + isCheckLicense?: boolean; + events?: Record; +} + +interface Options { + isSkipLicenseCheck?: boolean; + extensionName?: string; +} + +interface GlobalsConfig { + kubesphereEdition?: 'ks' | 'kse' | undefined; + isKsEdition?: boolean; + isKseEdition?: boolean; + importRemoteExtensions?: { + includes?: string[]; + excludes?: string[]; + }; + [key: string]: any; +} + interface Globals { - app?: any; - config?: any; - installedExtensions?: any; - context?: any; - run?: any; - user?: any; - manifest?: Record; + currentCluster?: string; + config: GlobalsConfig; + manifest: Record; + ksConfig: Record; + licenseInfo: { + formattedLicenses: Record[]; + }; + user: Record; + runtime: string; + clusterRole: string; + installedExtensions: { + name: string; + extensionName: string; + link: string; + resourceVersion: string; + }[]; + context: { + events: Record; + routes: Record[]; + routesByPatch: Record; + injectionPoints: Record; + locales: Record; + registerLocales: (locales: Record | undefined) => void; + registerExtension: (extension: Extension, options?: Options) => void; + registerExtensions: (extensions: Extension[], options?: Options) => void; + }; + emitter: { + all: any; + on: any; + off: any; + emit: any; + }; + run?: () => Promise; + clusterConfig?: Record; + theme: Record; + useDefaultTheme: boolean; + defaultTheme: Record; + // TODO 新增别名 + workspacesAliasName: Record; + projectAliasName: Record>; + clustersAliasName: Record; + userAliasName: Record; + platformRolesAliasName: Record; + ignoreSubRouteChange?: boolean; +} + +interface TFunction { + (key: string | string[], options?: Record): string; + + (key: string | string[], defaultValue?: string, options?: Record): string; } interface Window { - globals: Globals; - t: any; + readonly globals: Globals; + readonly t: TFunction; } -declare var t: any; -declare var globals: any; +declare const globals: Globals; +declare const t: TFunction; +// eslint-disable-next-line @typescript-eslint/naming-convention