=> {
const userCheck = 'user-check';
const url = new URL(location.href);
const redirect = url.searchParams.get('redirect');
@@ -185,11 +192,16 @@ export const checkPluginLogin = async () => {
setTimeout(() => {
window.open(newRedirectUrl.toString(), '_blank');
}, 2000);
- return;
+ return { code: 200, data: { redirectUrl } }
}
// 刷新token失败,登陆页自己跳转
}
- console.log('checkKey', checkKey, redirectUrl);
+ return {
+ code: 400,
+ data: {
+ redirectUrl: ''
+ }
+ }
}
const isWechat = () => {
const ua = navigator.userAgent.toLowerCase();
diff --git a/src/modules/query.ts b/src/modules/query.ts
index 43b43a4..229b2b3 100644
--- a/src/modules/query.ts
+++ b/src/modules/query.ts
@@ -1,10 +1,11 @@
import { Query } from '@kevisual/query'
-import { QueryLoginBrowser } from '@kevisual/query-login';
+import { QueryLoginBrowser } from '@kevisual/api/query-login';
-export const queryBase = new Query()
+export const queryBase = new Query({})
-export const query = new QueryLoginBrowser({
+export const queryLogin = new QueryLoginBrowser({
query: queryBase,
})
+export const query = queryLogin;
diff --git a/src/pages/kv-login.ts b/src/pages/kv-login.ts
index 2632e14..020661d 100644
--- a/src/pages/kv-login.ts
+++ b/src/pages/kv-login.ts
@@ -1,6 +1,6 @@
import { render, html } from 'lit-html'
import { unsafeHTML } from 'lit-html/directives/unsafe-html.js'
-import { loginHandle, checkWechat, getQrCode, checkMpQrCodeLogin, redirectHome } from '../modules/login-handle.ts'
+import { loginHandle, checkWechat, getQrCode, checkMpQrCodeLogin } from '../modules/login-handle.ts'
import { setWxerwma } from '../modules/wx/ws-login.ts';
import { useCreateLoginQRCode } from '../modules/wx-mp/qr.ts';
import { eventEmitter } from '../modules/mitt.ts';
@@ -27,9 +27,9 @@ const icons: any = {
wxOpenSvg
}
const DefaultLoginMethods: LoginMethod[] = [
+ { id: 'wechat', name: '微信登录', icon: 'wxmpSvg', appid: "wx9378885c8390e09b" },
{ id: 'password', name: '密码登录', icon: 'pwd' },
{ id: 'web', name: '网页登录', icon: 'web' },
- { id: 'wechat', name: '微信登录', icon: 'wxmpSvg', appid: "wx9378885c8390e09b" },
{ id: 'wechat-mp', name: '微信公众号', icon: 'wxOpenSvg', appid: WX_MP_APP_ID },
{ id: 'wechat-mp-ticket', name: '微信公众号', icon: 'wxOpenSvg' },
{ id: 'phone', name: '手机号登录', icon: 'phone' }
@@ -63,10 +63,13 @@ const getLoginMethodByDomain = (): LoginMethod[] => {
const getLoginMethod = (methods: LoginMethods[]): LoginMethod[] => {
return DefaultLoginMethods.filter(method => methods.includes(method.id))
}
+export const findLoginMethod = (methodId: LoginMethods): LoginMethod | undefined => {
+ return DefaultLoginMethods.find(method => method.id === methodId);
+}
class KvLogin extends HTMLElement {
private selectedMethod: LoginMethods = 'password'
- private loginMethods: LoginMethod[] = getLoginMethodByDomain();
+ private loginMethods: LoginMethod[] = [];
setLoginMethods(methods: LoginMethod[]) {
this.loginMethods = methods
this.render()
@@ -77,23 +80,37 @@ class KvLogin extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' })
- this.render()
this.bindEvents()
checkWechat()
const method = this.getAttribute('method');
+ let id = this.id;
+ if (!id) {
+ id = `${Math.random().toString(36).substring(2, 9)}`;
+ this.id = id;
+ }
+ let methodSetFlag = false;
if (method) {
const methods = method ? method.split(',') as LoginMethods[] : [];
if (methods.length > 0) {
- const loginMethods = methods.filter(m => LoginMethods.includes(m));
+ let loginMethods: LoginMethod[] = [];
+ for (const m of methods) {
+ const finded = findLoginMethod(m);
+ if (finded?.id) {
+ loginMethods.push(finded);
+ }
+ }
if (loginMethods.length > 0) {
- this.loginMethods = getLoginMethod(loginMethods)
- this.selectedMethod = loginMethods[0]
- return;
+ methodSetFlag = true;
+ this.loginMethods = loginMethods;
+ this.selectedMethod = loginMethods[0].id;
}
}
+ }
+ if (!methodSetFlag) {
this.loginMethods = getLoginMethodByDomain();
this.selectedMethod = this.loginMethods[0].id;
}
+ this.render()
}
#clearTimer: any = null;
private selectLoginMethod(methodId: LoginMethods) {
@@ -253,6 +270,14 @@ class KvLogin extends HTMLElement {
}
private renderWechatForm() {
+ let weixinLogin = document.querySelector('#weixinLogin');
+ if (!weixinLogin) {
+ weixinLogin = document.createElement('div');
+ weixinLogin.id = 'weixinLogin';
+ const id = this.id;
+ const host = document.querySelector(`#${id}`)!;
+ host.appendChild(weixinLogin);
+ }
return html`
diff --git a/vite.config.ts b/vite.config.ts
index c56a679..a384a0a 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -1,8 +1,9 @@
import { defineConfig } from 'vite';
+import { resolve } from 'path';
const idDev = process.env.NODE_ENV === 'development';
export default defineConfig({
- base: idDev ? '/' : '/root/kv-login-test/',
+ base: idDev ? '/' : '/root/login/',
server: {
proxy: {
'/api': {
diff --git a/web.html b/web.html
index 83dce49..d9c30f8 100644
--- a/web.html
+++ b/web.html
@@ -4,17 +4,9 @@
-
KvMessage Demo
-
-
+ 登录页面
+
+