127 lines
2.6 KiB
TypeScript
127 lines
2.6 KiB
TypeScript
type LoginMethods = 'password' | 'phone' | 'wechat' | 'wechat-mp' | 'wechat-mp-ticket';
|
|
|
|
interface KvLoginEventMap {
|
|
login: CustomEvent<{
|
|
method: LoginMethods;
|
|
data: LoginFormData[LoginMethods] | any;
|
|
}>;
|
|
/**
|
|
* 登录方式切换事件
|
|
*/
|
|
methodChange: CustomEvent<{
|
|
method: LoginMethods;
|
|
previousMethod?: LoginMethods;
|
|
}>;
|
|
/**
|
|
* 登录验证失败事件
|
|
*/
|
|
validationError: CustomEvent<{
|
|
method: LoginMethods;
|
|
errors: string[];
|
|
formData: LoginFormData[LoginMethods] | any;
|
|
}>;
|
|
}
|
|
|
|
interface KvLogin extends HTMLElement {
|
|
/**
|
|
* 设置登录方式
|
|
*/
|
|
setLoginMethods(methods: LoginMethod[]): void;
|
|
/**
|
|
* 添加自定义登录方式
|
|
*/
|
|
addLoginMethod(method: LoginMethod): void;
|
|
/**
|
|
* 移除登录方式
|
|
*/
|
|
removeLoginMethod(methodId: LoginMethods): void;
|
|
/**
|
|
* 获取当前选中的登录方式
|
|
*/
|
|
getSelectedMethod(): LoginMethods;
|
|
/**
|
|
* 设置默认登录方式
|
|
*/
|
|
setDefaultMethod(methodId: LoginMethods): void;
|
|
|
|
addEventListener<K extends keyof KvLoginEventMap>(
|
|
type: K,
|
|
listener: (this: KvLogin, ev: KvLoginEventMap[K]) => void,
|
|
options?: boolean | AddEventListenerOptions
|
|
): void;
|
|
removeEventListener<K extends keyof KvLoginEventMap>(
|
|
type: K,
|
|
listener: (this: KvLogin, ev: KvLoginEventMap[K]) => void,
|
|
options?: boolean | EventListenerOptions
|
|
): void;
|
|
}
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'kv-login': KvLogin;
|
|
}
|
|
|
|
namespace JSX {
|
|
interface IntrinsicElements {
|
|
'kv-login': KvLoginAttributes;
|
|
}
|
|
}
|
|
}
|
|
|
|
interface KvLoginAttributes extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> {
|
|
/**
|
|
* 自定义登录方式配置
|
|
*/
|
|
loginMethods?: LoginMethod[];
|
|
/**
|
|
* 自定义样式类名
|
|
*/
|
|
customClass?: string;
|
|
/**
|
|
* 是否显示登录方式选择器
|
|
*/
|
|
showMethodSelector?: boolean;
|
|
/**
|
|
* 默认选中的登录方式
|
|
*/
|
|
defaultMethod?: LoginMethods;
|
|
}
|
|
|
|
interface LoginMethod {
|
|
id: LoginMethods;
|
|
name: string;
|
|
icon: string | any; // 可以是emoji字符串、SVG字符串或其他图标类型
|
|
appid?: string;
|
|
disabled?: boolean;
|
|
order?: number; // 用于排序
|
|
}
|
|
|
|
interface LoginFormData {
|
|
password?: {
|
|
username: string;
|
|
password: string;
|
|
};
|
|
phone?: {
|
|
phone: string;
|
|
code: string;
|
|
};
|
|
wechat?: {
|
|
wechatCode: string;
|
|
};
|
|
'wechat-mp'?: {
|
|
wechatMpCode: string;
|
|
};
|
|
'wechat-mp-ticket'?: {
|
|
wechatMpCode: string;
|
|
ticket: string;
|
|
};
|
|
}
|
|
|
|
export {
|
|
KvLogin,
|
|
KvLoginEventMap,
|
|
KvLoginAttributes,
|
|
LoginMethods,
|
|
LoginMethod,
|
|
LoginFormData
|
|
}; |