This commit is contained in:
2025-12-05 18:06:49 +08:00
parent d217c8cec1
commit 35d7272872
4 changed files with 34 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@kevisual/kv-login",
"version": "0.0.7",
"version": "0.0.8",
"description": "",
"main": "src/main.ts",
"scripts": {

View File

@@ -31,24 +31,35 @@ const DefaultLoginMethods: LoginMethod[] = [
{ id: 'wechat-mp-ticket', name: '微信公众号', icon: 'wxOpenSvg' },
{ id: 'phone', name: '手机号登录', icon: 'phone' }
]
const LoginMethods = ['password', 'phone', 'wechat', 'wechat-mp', 'wechat-mp-ticket'] as const;
type LoginMethods = 'password' | 'phone' | 'wechat' | 'wechat-mp' | 'wechat-mp-ticket';
const getLoginMethodByDomain = (): LoginMethod[] => {
const domain = window.location.hostname
let domain = window.location.host
let methods: LoginMethods[] = []
const has51015 = domain.includes('51015');
if (has51015) {
domain = 'localhost:51015'
}
switch (domain) {
case 'kevisual.xiongxiao.me':
methods = ['password', 'wechat-mp']
break;
case 'kevisual.cn':
methods = ['password', 'wechat', 'wechat-mp-ticket']
methods = ['password', 'wechat-mp-ticket', 'wechat',]
break;
case 'localhost:51015':
methods = ['password']
break
default:
methods = ['password', 'phone', 'wechat', 'wechat-mp', 'wechat-mp-ticket']
break;
}
return DefaultLoginMethods.filter(method => methods.includes(method.id))
}
const getLoginMethod = (methods: LoginMethods[]): LoginMethod[] => {
return DefaultLoginMethods.filter(method => methods.includes(method.id))
}
class KvLogin extends HTMLElement {
private selectedMethod: LoginMethods = 'password'
@@ -66,7 +77,20 @@ class KvLogin extends HTMLElement {
this.render()
this.bindEvents()
checkWechat()
const method = this.getAttribute('method');
if (method) {
const methods = method ? method.split(',') as LoginMethods[] : [];
if (methods.length > 0) {
const loginMethods = methods.filter(m => LoginMethods.includes(m));
if (loginMethods.length > 0) {
this.loginMethods = getLoginMethod(loginMethods)
this.selectedMethod = loginMethods[0]
return;
}
}
this.loginMethods = getLoginMethodByDomain();
this.selectedMethod = this.loginMethods[0].id;
}
}
#clearTimer: any = null;
private selectLoginMethod(methodId: LoginMethods) {