import { InjectionKey, App } from 'vue'; import { Router, RouteLocationNormalized } from 'vue-router'; import { Request } from '@vtj/utils'; import { ContextMode } from '../constants'; export interface AccessOptions { /** * 开启session, token 储存到cookie,关闭浏览器将登录失效 */ session: boolean; /** * 请求头和cookie记录token名称 */ authKey: string; /** * 本地缓存key前缀 */ storagePrefix: string; /** * 本地缓存key */ storageKey: string; /** * 路由拦截白名单 */ whiteList?: string[] | ((to: RouteLocationNormalized) => boolean); /** * 未授权页面路由路径 */ unauthorized?: string | (() => void); /** * 授权登录页面 pathname */ auth?: string | ((search: string) => void); /** * 判断是否登录页面 * @param path * @returns */ isAuth?: (to: RouteLocationNormalized) => boolean; /** * 重定向参数名 */ redirectParam?: string; /** * 未登录响应状态码 */ unauthorizedCode?: number; /** * 提示信息方法 * @param message * @returns */ alert?: (message: string, options?: Record) => Promise; /** * 未登录提示文本 */ unauthorizedMessage?: string; /** * 无权限提示 */ noPermissionMessage?: string; /** * RSA解密私钥 */ privateKey?: string; /** * 应用编码 */ appName?: string; /** * 请求响应数据状态的key */ statusKey?: string; } export interface AccessData { token: string; permissions: Record | string[]; [index: string]: any; } export interface AccessConnectParams { /** * 请求类 */ request?: Request | null; /** * 路由 */ router?: Router | null; /** * 模式 */ mode?: ContextMode; } export declare const ACCESS_KEY: InjectionKey; export declare class Access { options: AccessOptions; private data; private mode?; private interceptResponse; private isTipShowing; constructor(options: Partial); enableIntercept(): void; disableIntercept(): void; connect(params: AccessConnectParams): void; login(data: AccessData | string | string[]): void; clear(): void; logout(): void; getData(): AccessData | null; getToken(): string | undefined; can(code: string | string[] | ((p: Record | string[]) => boolean)): boolean; some(code: string | string[]): boolean; install(app: App): void; private isAuthPath; toLogin(): void; private setData; private loadData; isLogined(): boolean; private hasRoutePermission; private setGuard; private guard; private isWhiteList; private isUnauthorized; private showUnauthorizedAlert; showTip(content: string): Promise; private setRequest; } export declare function useAccess(): Access; declare module 'vue' { interface ComponentCustomProperties { $access: Access; } }