add kv-login modules

This commit is contained in:
2025-11-28 20:22:58 +08:00
parent 2ae2b3ab4c
commit 6ff8d7acde
4 changed files with 48 additions and 8 deletions

2
packages/kv-login/.npmrc Normal file
View File

@@ -0,0 +1,2 @@
//npm.xiongxiao.me/:_authToken=${ME_NPM_TOKEN}
//registry.npmjs.org/:_authToken=${NPM_TOKEN}

View File

@@ -1,22 +1,31 @@
{ {
"name": "kv-login", "name": "@kevisual/kv-login",
"version": "0.0.1", "version": "0.0.1",
"description": "", "description": "",
"main": "index.js", "main": "src/main.ts",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build", "build": "vite build --config vite-lib.config.ts",
"prepub": "rm -rf ./dist && pnpm run build", "build:test": "vite build",
"pub":"ev deploy ./dist -k kv-login-test -v 0.0.1 -u -y yes" "prepub": "rm -rf ./dist && pnpm run build:test",
"pub": "ev deploy ./dist -k kv-login-test -v 0.0.1 -u -y yes"
}, },
"keywords": [], "keywords": [],
"author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)", "author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
"license": "MIT", "license": "MIT",
"packageManager": "pnpm@10.19.0", "packageManager": "pnpm@10.19.0",
"publishConfig": {
"access": "public"
},
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"@kevisual/query-login": "^0.0.6", "@kevisual/query-login": "^0.0.6",
"lit-html": "^3.3.1", "lit-html": "^3.3.1",
"qrcode": "^1.5.4" "qrcode": "^1.5.4"
},
"exports": {
".": "./dist/kv-login.es.js",
"./kv-login.es.js": "./dist/kv-login.es.js",
"./kv-login.umd.js": "./dist/kv-login.umd.js"
} }
} }

View File

@@ -13,14 +13,30 @@ const DefaultLoginMethods: LoginMethod[] = [
{ id: 'password', name: '密码登录', icon: '🔒' }, { id: 'password', name: '密码登录', icon: '🔒' },
{ id: 'wechat', name: '微信登录', icon: '💬', appid: "wx9378885c8390e09b" }, { id: 'wechat', name: '微信登录', icon: '💬', appid: "wx9378885c8390e09b" },
{ id: 'wechat-mp', name: '微信公众号登录', icon: '💬', appid: WX_MP_APP_ID }, { id: 'wechat-mp', name: '微信公众号登录', icon: '💬', appid: WX_MP_APP_ID },
// { id: 'phone', name: '手机号登录', icon: '📱' } { id: 'phone', name: '手机号登录', icon: '📱' }
] ]
type LoginMethods = 'password' | 'phone' | 'wechat' | 'wechat-mp' type LoginMethods = 'password' | 'phone' | 'wechat' | 'wechat-mp'
const getLoginMethodByDomain = (): LoginMethod[] => {
const domain = window.location.hostname
let methods: LoginMethods[] = []
switch (domain) {
case 'kevisual.xiongxiao.me':
methods = ['password', 'wechat-mp']
break;
case 'kevisual.cn':
methods = ['password', 'wechat']
break;
default:
methods = ['password', 'phone', 'wechat', 'wechat-mp']
break;
}
return DefaultLoginMethods.filter(method => methods.includes(method.id))
}
console.log('可用登录方式:', getLoginMethodByDomain().map(m => m.name).join(', '));
class KvLogin extends HTMLElement { class KvLogin extends HTMLElement {
private selectedMethod: LoginMethods = 'password' private selectedMethod: LoginMethods = 'password'
private loginMethods: LoginMethod[] = DefaultLoginMethods private loginMethods: LoginMethod[] = getLoginMethodByDomain();
setLoginMethods(methods: LoginMethod[]) { setLoginMethods(methods: LoginMethod[]) {
this.loginMethods = methods this.loginMethods = methods
this.render() this.render()
@@ -34,6 +50,7 @@ class KvLogin extends HTMLElement {
this.render() this.render()
this.bindEvents() this.bindEvents()
checkWechat() checkWechat()
} }
#clearTimer: any = null; #clearTimer: any = null;
private selectLoginMethod(methodId: LoginMethods) { private selectLoginMethod(methodId: LoginMethods) {

View File

@@ -0,0 +1,12 @@
import { defineConfig } from 'vite';
const entry = './src/main.ts';
export default defineConfig({
build: {
lib: {
entry,
name: 'KvLogin',
fileName: (format) => `kv-login.${format}.js`,
}
}
});