diff --git a/napcat.webui/src/backend/shell.ts b/napcat.webui/src/backend/shell.ts index efc7f013..0819e0b8 100644 --- a/napcat.webui/src/backend/shell.ts +++ b/napcat.webui/src/backend/shell.ts @@ -74,6 +74,26 @@ export class QQLoginManager { } return false; } + public async checkQQLoginStatusWithQrcode(): Promise<{ qrcodeurl: string, isLogin: string } | undefined> { + try { + const QQLoginResponse = await fetch(`${this.apiPrefix}/QQLogin/CheckLoginStatus`, { + method: 'POST', + headers: { + Authorization: 'Bearer ' + this.retCredential, + 'Content-Type': 'application/json', + }, + }); + if (QQLoginResponse.status == 200) { + const QQLoginResponseJson = await QQLoginResponse.json(); + if (QQLoginResponseJson.code == 0) { + return QQLoginResponseJson.data; + } + } + } catch (error) { + console.error('Error checking QQ login status:', error); + } + return undefined; + } public async checkWebUiLogined(): Promise { try { diff --git a/napcat.webui/src/components/QQLogin.vue b/napcat.webui/src/components/QQLogin.vue index 13d4b674..bd46608a 100644 --- a/napcat.webui/src/components/QQLogin.vue +++ b/napcat.webui/src/components/QQLogin.vue @@ -2,28 +2,14 @@

QQ Login

@@ -47,7 +33,7 @@ const selectedAccount = ref(''); const qrcodeCanvas = ref(null); const qqLoginManager = new QQLoginManager(localStorage.getItem('auth') || ''); let heartBeatTimer: number | null = null; - +let qrcodeUrl: string = ''; const selectAccount = async (accountName: string): Promise => { const { result, errMsg } = await qqLoginManager.setQuickLogin(accountName); if (result) { @@ -73,19 +59,26 @@ const generateQrCode = (data: string, canvas: HTMLCanvasElement | null): void => }; const HeartBeat = async (): Promise => { - const isLogined = await qqLoginManager.checkQQLoginStatus(); - if (isLogined) { + const isLogined = await qqLoginManager.checkQQLoginStatusWithQrcode(); + if (isLogined?.isLogin) { if (heartBeatTimer) { clearInterval(heartBeatTimer); } + //判断是否已经调转 + if (router.currentRoute.value.path !== '/dashboard/basic-info') { + return; + } await router.push({ path: '/dashboard/basic-info' }); + } else if (isLogined?.qrcodeurl && qrcodeUrl !== isLogined.qrcodeurl) { + qrcodeUrl = isLogined.qrcodeurl; + generateQrCode(qrcodeUrl, qrcodeCanvas.value); } }; const InitPages = async (): Promise => { quickLoginList.value = await qqLoginManager.getQQQuickLoginList(); - const qrcodeData = await qqLoginManager.getQQLoginQrcode(); - generateQrCode(qrcodeData, qrcodeCanvas.value); + qrcodeUrl = await qqLoginManager.getQQLoginQrcode(); + generateQrCode(qrcodeUrl, qrcodeCanvas.value); heartBeatTimer = window.setInterval(HeartBeat, 3000); }; diff --git a/src/webui/src/api/QQLogin.ts b/src/webui/src/api/QQLogin.ts index b2d17f00..ba78451f 100644 --- a/src/webui/src/api/QQLogin.ts +++ b/src/webui/src/api/QQLogin.ts @@ -33,6 +33,7 @@ export const QQCheckLoginStatusHandler: RequestHandler = async (req, res) => { message: 'success', data: { isLogin: await WebUiDataRuntime.getQQLoginStatus(), + qrcodeurl: await WebUiDataRuntime.getQQLoginQrcodeURL() }, }); };