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

@@ -23,7 +23,7 @@
"@astrojs/sitemap": "^3.6.0",
"@floating-ui/dom": "^1.7.4",
"@kevisual/context": "^0.0.4",
"@kevisual/kv-login": "^0.0.7",
"@kevisual/kv-login": "^0.0.8",
"@kevisual/query": "0.0.29",
"@kevisual/query-login": "^0.0.7",
"@kevisual/registry": "^0.0.1",

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) {

10
pnpm-lock.yaml generated
View File

@@ -27,8 +27,8 @@ importers:
specifier: ^0.0.4
version: 0.0.4
'@kevisual/kv-login':
specifier: ^0.0.7
version: 0.0.7(@kevisual/query@0.0.29(ws@8.18.0)(zod@3.25.76))
specifier: ^0.0.8
version: 0.0.8(@kevisual/query@0.0.29(ws@8.18.0)(zod@3.25.76))
'@kevisual/query':
specifier: 0.0.29
version: 0.0.29(ws@8.18.0)(zod@3.25.76)
@@ -880,8 +880,8 @@ packages:
'@kevisual/context@0.0.4':
resolution: {integrity: sha512-HJeLeZQLU+7tCluSfOyvkgKLs0HjCZrdJlZgEgKRSa8XTwZfMAUt6J7qZTbrZAHBlPtX68EPu/PI8JMCeu3WAQ==}
'@kevisual/kv-login@0.0.7':
resolution: {integrity: sha512-PB4AultJdrnSf9Knz3zTCdMzE8TS7JbNpoaL9gQJDEpePXNhZrsnKNXMyd0XFh6f3GNhrc39cA/O4SsOlZlx2w==}
'@kevisual/kv-login@0.0.8':
resolution: {integrity: sha512-N6nDCwI0sZkjQAiJf7JpyVvn5x3Nf2qWp9U9vzSMDyYeV/PHNzMZIr42Woma2MGFwcjMRjcnJxIC7HWARVLLsQ==}
'@kevisual/query-login@0.0.6':
resolution: {integrity: sha512-ZdX+sxeQaM3PV9fZXofMlxFz1RmpYIkoi47exzUgw6DADjEryBAQKRXe2/oL20NsBTV8owqaagRqffAVjq5c5g==}
@@ -4374,7 +4374,7 @@ snapshots:
'@kevisual/context@0.0.4': {}
'@kevisual/kv-login@0.0.7(@kevisual/query@0.0.29(ws@8.18.0)(zod@3.25.76))':
'@kevisual/kv-login@0.0.8(@kevisual/query@0.0.29(ws@8.18.0)(zod@3.25.76))':
dependencies:
'@kevisual/context': 0.0.4
'@kevisual/query-login': 0.0.7(@kevisual/query@0.0.29(ws@8.18.0)(zod@3.25.76))