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

@@ -3,7 +3,7 @@ import { createMessage } from '../pages/kv-message.ts';
import { WX_MP_APP_ID } from '../pages/kv-login.ts';
export const message = createMessage();
type LoginOpts = {
loginMethod: 'password' | 'phone' | 'wechat' | 'wechat-mp',
loginMethod: 'password' | 'phone' | 'wechat' | 'wechat-mp' | 'wechat-mp-ticket',
data: any,
el: HTMLElement
}
@@ -38,7 +38,11 @@ export const loginHandle = async (opts: LoginOpts) => {
console.warn('未知的登录方式:', loginMethod)
}
}
/**
* 使用用户名和密码登录
* @param data
* @returns
*/
const loginByPassword = async (data: { username: string, password: string }) => {
console.log('使用用户名密码登录:', data)
let needLogin = true; // 这里可以根据实际情况决定是否需要登录, 只能判断密码登录和手机号登录
@@ -185,4 +189,49 @@ const checkMpWechatInWx = async () => {
setTimeout(() => {
checkMpWechat();
}, 100);
}, 100);
export const getQrCode = async () => {
const res = await query.post({
path: 'wx',
key: 'get-qrcode-ticket'
})
if (res.code !== 200) {
message.error('获取二维码失败');
return null;
}
return res?.data as { ticket: string, url: string }
}
export const checkMpQrCodeLogin = (ticket: string) => {
let run = true;
const fetchLoginStatus = async () => {
const res = await query.post({
path: 'wx',
key: 'check-qrcode-login',
payload: { ticket }
})
if (res.code === 200) {
message.success('登录成功');
clearTimeout(timer);
redirectHome();
} else {
// message.error(res.message || '登录失败');
if (res.code === 401) {
console.log('等待扫码登录...');
} else {
console.log('扫码登录状态:', res);
}
if (run) {
setTimeout(fetchLoginStatus, 2000);
}
}
}
const timer = setTimeout(fetchLoginStatus, 2000);
const close = () => {
console.log('停止检测扫码登录状态');
clearTimeout(timer);
run = false
}
return close;
}