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",
"description": "",
"main": "index.js",
"main": "src/main.ts",
"scripts": {
"dev": "vite",
"build": "vite build",
"prepub": "rm -rf ./dist && pnpm run build",
"pub":"ev deploy ./dist -k kv-login-test -v 0.0.1 -u -y yes"
"build": "vite build --config vite-lib.config.ts",
"build:test": "vite build",
"prepub": "rm -rf ./dist && pnpm run build:test",
"pub": "ev deploy ./dist -k kv-login-test -v 0.0.1 -u -y yes"
},
"keywords": [],
"author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
"license": "MIT",
"packageManager": "pnpm@10.19.0",
"publishConfig": {
"access": "public"
},
"type": "module",
"dependencies": {
"@kevisual/query-login": "^0.0.6",
"lit-html": "^3.3.1",
"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: 'wechat', name: '微信登录', icon: '💬', appid: "wx9378885c8390e09b" },
{ 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'
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 {
private selectedMethod: LoginMethods = 'password'
private loginMethods: LoginMethod[] = DefaultLoginMethods
private loginMethods: LoginMethod[] = getLoginMethodByDomain();
setLoginMethods(methods: LoginMethod[]) {
this.loginMethods = methods
this.render()
@@ -34,6 +50,7 @@ class KvLogin extends HTMLElement {
this.render()
this.bindEvents()
checkWechat()
}
#clearTimer: any = null;
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`,
}
}
});