fix: fix bugs

This commit is contained in:
2025-11-30 21:40:41 +08:00
parent 6ff8d7acde
commit 01c7a59e02
7 changed files with 118 additions and 56 deletions

View File

@@ -1,5 +1,5 @@
import { render, html } from 'lit-html'
import { loginHandle, checkWechat } 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';
export const WX_MP_APP_ID = "wxff97d569b1db16b6";
@@ -13,9 +13,10 @@ const DefaultLoginMethods: LoginMethod[] = [
{ id: 'password', name: '密码登录', icon: '🔒' },
{ id: 'wechat', name: '微信登录', icon: '💬', appid: "wx9378885c8390e09b" },
{ id: 'wechat-mp', name: '微信公众号登录', icon: '💬', appid: WX_MP_APP_ID },
{ id: 'wechat-mp-ticket', name: '微信公众号登录', icon: '💬' },
{ id: 'phone', name: '手机号登录', icon: '📱' }
]
type LoginMethods = 'password' | 'phone' | 'wechat' | 'wechat-mp'
type LoginMethods = 'password' | 'phone' | 'wechat' | 'wechat-mp' | 'wechat-mp-ticket';
const getLoginMethodByDomain = (): LoginMethod[] => {
const domain = window.location.hostname
let methods: LoginMethods[] = []
@@ -24,10 +25,10 @@ const getLoginMethodByDomain = (): LoginMethod[] => {
methods = ['password', 'wechat-mp']
break;
case 'kevisual.cn':
methods = ['password', 'wechat']
methods = ['password', 'wechat', 'wechat-mp-ticket']
break;
default:
methods = ['password', 'phone', 'wechat', 'wechat-mp']
methods = ['password', 'phone', 'wechat', 'wechat-mp', 'wechat-mp-ticket']
break;
}
return DefaultLoginMethods.filter(method => methods.includes(method.id))
@@ -224,6 +225,31 @@ class KvLogin extends HTMLElement {
</div>
`
}
private renderWechatMpTicketForm() {
const that = this;
setTimeout(async () => {
const data = await getQrCode();
if (!data) return;
const imgEl = that.shadowRoot!.querySelector('.qrcode') as HTMLImageElement;
if (data.url) {
imgEl.src = data.url;
// TODO: 轮询检测登录状态
const clear = checkMpQrCodeLogin(data.ticket)
// 当切换登录方式时,停止轮询
that.#clearTimer = clear
}
}, 0)
return html`
<div class="wechat-login">
<div class="qr-container">
<div class="qr-placeholder">
<img class="qrcode" width="300" height="300" data-appid="" data-size="200" data-ticket=""></img>
<p class="qr-desc">请使用微信扫描二维码登录</p>
</div>
</div>
</div>
`
}
private sendVerificationCode() {
console.log('发送验证码')
@@ -248,6 +274,8 @@ class KvLogin extends HTMLElement {
return this.renderWechatForm()
case 'wechat-mp':
return this.renderWechatMpForm()
case 'wechat-mp-ticket':
return this.renderWechatMpTicketForm()
default:
return this.renderPasswordForm()
}