vue-app-sdk
Version:
94 lines (93 loc) • 2.1 kB
TypeScript
import { MaybeArray } from '@rhao/types-base';
import { AppSDKInternalInstance, Plugin, PluginID } from '../..';
import { Directive } from 'vue';
/**
* 功能授权列表,`*` 代表所有权限
*/
export type AuthList = '*' | string[];
/**
* 操作符
*/
export type Operator = 'or' | 'and';
export interface AuthOptions {
/**
* 授权指令
* @default 'auth'
*/
directiveName?: string;
}
/**
* Auth Plugin ID
*/
export declare const AUTH_ID: PluginID<Auth>;
/**
* 功能授权插件
*/
export declare class Auth implements Plugin {
/**
* 配置项
*/
options: AuthOptions;
constructor(
/**
* 配置项
*/
options?: AuthOptions);
id: PluginID<Auth>;
/**
* 授权指令
*/
directive: Directive<Element, MaybeArray<string>>;
/**
* 授权列表
*/
private _list;
/**
* 授权列表
* @readonly
*/
get list(): AuthList;
/**
* 未授权时是否允许提示
*/
private _allowTip;
/**
* 授权
* @param list 授权列表
*
* @example
* ```ts
* // 设置用户权限编码列表
* fetchUser().then((user) => auth.empower(user.permissions))
*
* function fetchUser() {
* return Promise.resolve({ id: 1, name: 'admin', permissions: ['list:add', 'list:edit'] })
* }
* ```
*/
empower: (list: AuthList) => void;
/**
* 验证功能权限
* @param codes 功能列表
* @param op 操作符
*
* @example
* ```ts
* // 单功能鉴权
* auth.verify('list:add')
*
* // 多功能鉴权,满足单一功能编码
* auth.verify(['list:add', 'list:edit'], 'or')
*
* // 多功能鉴权,需同时满足所有功能编码
* auth.verify(['list:add', 'list:edit'], 'and')
* ```
*/
verify: (codes: MaybeArray<string>, op?: Operator) => boolean;
install: (sdk: AppSDKInternalInstance) => void;
}
declare module 'vue' {
interface ComponentCustomProperties {
vAuth: Auth['directive'];
}
}