add kv-login modules
This commit is contained in:
2
packages/kv-login/.npmrc
Normal file
2
packages/kv-login/.npmrc
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
//npm.xiongxiao.me/:_authToken=${ME_NPM_TOKEN}
|
||||||
|
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
|
||||||
@@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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) {
|
||||||
|
|||||||
12
packages/kv-login/vite-lib.config.ts
Normal file
12
packages/kv-login/vite-lib.config.ts
Normal 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`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user