From a54f30acc136df4e4c3c2f6c29469358efb90b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Fri, 15 Nov 2024 16:45:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BF=BB=E6=96=B0=E9=99=A4=E4=BA=86?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=9A=84=E6=89=80=E6=9C=89?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- napcat.webui/src/backend/shell.ts | 136 +++ napcat.webui/src/components/QQLogin.vue | 63 +- napcat.webui/src/components/WebUiLogin.vue | 59 +- static/assets/index-Cz7mtj1A.css | 1 + static/assets/index-xw9jld-V.js | 970 +++++++++++++++++++++ static/index.html | 4 +- 6 files changed, 1184 insertions(+), 49 deletions(-) create mode 100644 napcat.webui/src/backend/shell.ts create mode 100644 static/assets/index-Cz7mtj1A.css create mode 100644 static/assets/index-xw9jld-V.js diff --git a/napcat.webui/src/backend/shell.ts b/napcat.webui/src/backend/shell.ts new file mode 100644 index 00000000..12f2b7fe --- /dev/null +++ b/napcat.webui/src/backend/shell.ts @@ -0,0 +1,136 @@ +export class QQLoginManager { + private retCredential: string; + + constructor(retCredential: string) { + this.retCredential = retCredential; + } + + public async checkQQLoginStatus(): Promise { + try { + let QQLoginResponse = await fetch('../api/QQLogin/CheckLoginStatus', { + method: 'POST', + headers: { + 'Authorization': "Bearer " + this.retCredential, + 'Content-Type': 'application/json' + } + }); + if (QQLoginResponse.status == 200) { + let QQLoginResponseJson = await QQLoginResponse.json(); + if (QQLoginResponseJson.code == 0) { + return QQLoginResponseJson.data.isLogin; + } + } + } catch (error) { + console.error("Error checking QQ login status:", error); + } + return false; + } + + public async checkWebUiLogined(): Promise { + try { + let LoginResponse = await fetch('../api/auth/check', { + method: 'POST', + headers: { + 'Authorization': "Bearer " + this.retCredential, + 'Content-Type': 'application/json' + } + }); + if (LoginResponse.status == 200) { + let LoginResponseJson = await LoginResponse.json(); + if (LoginResponseJson.code == 0) { + return true; + } + } + } catch (error) { + console.error("Error checking web UI login status:", error); + } + return false; + } + + public async loginWithToken(token: string): Promise { + try { + let loginResponse = await fetch('../api/auth/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ token: token }) + }); + const loginResponseJson = await loginResponse.json(); + let retCode = loginResponseJson.code; + if (retCode === 0) { + this.retCredential = loginResponseJson.data.Credential; + return this.retCredential; + } + } catch (error) { + console.error("Error logging in with token:", error); + } + return null; + } + + public async getQQLoginQrcode(): Promise { + try { + let QQLoginResponse = await fetch('../api/QQLogin/GetQQLoginQrcode', { + method: 'POST', + headers: { + 'Authorization': "Bearer " + this.retCredential, + 'Content-Type': 'application/json' + } + }); + if (QQLoginResponse.status == 200) { + let QQLoginResponseJson = await QQLoginResponse.json(); + if (QQLoginResponseJson.code == 0) { + return QQLoginResponseJson.data.qrcode || ""; + } + } + } catch (error) { + console.error("Error getting QQ login QR code:", error); + } + return ""; + } + + public async getQQQuickLoginList(): Promise { + try { + let QQLoginResponse = await fetch('../api/QQLogin/GetQuickLoginList', { + method: 'POST', + headers: { + 'Authorization': "Bearer " + this.retCredential, + 'Content-Type': 'application/json' + } + }); + if (QQLoginResponse.status == 200) { + let QQLoginResponseJson = await QQLoginResponse.json(); + if (QQLoginResponseJson.code == 0) { + return QQLoginResponseJson.data || []; + } + } + } catch (error) { + console.error("Error getting QQ quick login list:", error); + } + return []; + } + + public async setQuickLogin(uin: string): Promise<{ result: boolean, errMsg: string }> { + try { + let QQLoginResponse = await fetch('../api/QQLogin/SetQuickLogin', { + method: 'POST', + headers: { + 'Authorization': "Bearer " + this.retCredential, + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ uin: uin }) + }); + if (QQLoginResponse.status == 200) { + let QQLoginResponseJson = await QQLoginResponse.json(); + if (QQLoginResponseJson.code == 0) { + return { result: true, errMsg: "" }; + } else { + return { result: false, errMsg: QQLoginResponseJson.message }; + } + } + } catch (error) { + console.error("Error setting quick login:", error); + } + return { result: false, errMsg: "接口异常" }; + } +} \ No newline at end of file diff --git a/napcat.webui/src/components/QQLogin.vue b/napcat.webui/src/components/QQLogin.vue index 4e6517c1..3ec8da12 100644 --- a/napcat.webui/src/components/QQLogin.vue +++ b/napcat.webui/src/components/QQLogin.vue @@ -2,52 +2,41 @@