mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-06 08:32:51 +08:00
🐛 修复扫码登录异常
This commit is contained in:
@@ -26,11 +26,12 @@ import TOverlay from "@comp/app/t-overlay.vue";
|
|||||||
import showLoading from "@comp/func/loading.js";
|
import showLoading from "@comp/func/loading.js";
|
||||||
import showSnackbar from "@comp/func/snackbar.js";
|
import showSnackbar from "@comp/func/snackbar.js";
|
||||||
import QrcodeVue from "qrcode.vue";
|
import QrcodeVue from "qrcode.vue";
|
||||||
import { computed, onUnmounted, ref, watch } from "vue";
|
import { onUnmounted, ref, watch } from "vue";
|
||||||
|
|
||||||
import { generateShareImg } from "@/utils/TGShare.js";
|
import { generateShareImg } from "@/utils/TGShare.js";
|
||||||
import hk4eReq from "@/web/request/hk4eReq.js";
|
import hk4eReq from "@/web/request/hk4eReq.js";
|
||||||
import PassportReq from "@/web/request/passportReq.js";
|
import PassportReq from "@/web/request/passportReq.js";
|
||||||
|
import passportReq from "@/web/request/passportReq.js";
|
||||||
import takumiReq from "@/web/request/takumiReq.js";
|
import takumiReq from "@/web/request/takumiReq.js";
|
||||||
|
|
||||||
type ToGameLoginEmits = (e: "success", data: TGApp.App.Account.Cookie) => void;
|
type ToGameLoginEmits = (e: "success", data: TGApp.App.Account.Cookie) => void;
|
||||||
@@ -39,21 +40,28 @@ type ToGameLoginEmits = (e: "success", data: TGApp.App.Account.Cookie) => void;
|
|||||||
let cycleTimer: NodeJS.Timeout | null = null;
|
let cycleTimer: NodeJS.Timeout | null = null;
|
||||||
|
|
||||||
const model = defineModel<boolean>({ default: false });
|
const model = defineModel<boolean>({ default: false });
|
||||||
const isLauncherCode = defineModel<boolean>("launcher", { default: false });
|
const isLauncherCode = defineModel<boolean>("launcher", { default: true });
|
||||||
const emits = defineEmits<ToGameLoginEmits>();
|
const emits = defineEmits<ToGameLoginEmits>();
|
||||||
const codeUrl = ref<string>();
|
const codeUrl = ref<string>();
|
||||||
const codeTicket = computed<string>(() => {
|
const codeTicket = ref<string>("");
|
||||||
if (!codeUrl.value) return "";
|
|
||||||
const url = new URL(codeUrl.value);
|
|
||||||
return url.searchParams.get("ticket") || "";
|
|
||||||
});
|
|
||||||
|
|
||||||
watch(model, async (value) => {
|
watch(
|
||||||
if (value) {
|
() => model.value,
|
||||||
await freshQr();
|
async () => {
|
||||||
cycleTimer = setInterval(cycleGetData, 1000);
|
if (model.value) {
|
||||||
}
|
await freshQr();
|
||||||
});
|
if (cycleTimer) {
|
||||||
|
clearInterval(cycleTimer);
|
||||||
|
cycleTimer = null;
|
||||||
|
}
|
||||||
|
if (isLauncherCode.value) cycleTimer = setInterval(cycleGetDataLauncher, 1000);
|
||||||
|
else cycleTimer = setInterval(cycleGetDataGame, 5000);
|
||||||
|
} else {
|
||||||
|
if (cycleTimer) clearInterval(cycleTimer);
|
||||||
|
cycleTimer = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
async function share(): Promise<void> {
|
async function share(): Promise<void> {
|
||||||
const shareDom = document.querySelector<HTMLDivElement>(".tog-box");
|
const shareDom = document.querySelector<HTMLDivElement>(".tog-box");
|
||||||
@@ -65,25 +73,26 @@ async function share(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function freshQr(): Promise<void> {
|
async function freshQr(): Promise<void> {
|
||||||
let res;
|
if (isLauncherCode.value) {
|
||||||
if (isLauncherCode.value) res = await PassportReq.qrLogin.create();
|
const resp = await passportReq.qrLogin.create();
|
||||||
else res = await hk4eReq.loginQr.create();
|
if ("retcode" in resp) {
|
||||||
console.log(res);
|
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
|
||||||
if ("retcode" in res) {
|
return;
|
||||||
showSnackbar.error(`[${res.retcode}] ${res.message}`);
|
}
|
||||||
|
codeUrl.value = resp.url;
|
||||||
|
codeTicket.value = resp.ticket;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
codeUrl.value = res.url;
|
const resp = await hk4eReq.loginQr.create();
|
||||||
|
if ("retcode" in resp) {
|
||||||
|
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
codeUrl.value = resp.url;
|
||||||
|
codeTicket.value = new URL(codeUrl.value).searchParams.get("ticket") || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
async function cycleGetData() {
|
async function cycleGetDataLauncher(): Promise<void> {
|
||||||
if (cycleTimer === null || codeTicket.value === "") return;
|
|
||||||
if (isLauncherCode.value) await cycleGetDataLauncher(cycleTimer);
|
|
||||||
else await cycleGetDataGame(cycleTimer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
async function cycleGetDataLauncher(timer: NodeJS.Timeout): Promise<void> {
|
|
||||||
const res = await PassportReq.qrLogin.query(codeTicket.value);
|
const res = await PassportReq.qrLogin.query(codeTicket.value);
|
||||||
console.log(res);
|
console.log(res);
|
||||||
if ("retcode" in res) {
|
if ("retcode" in res) {
|
||||||
@@ -91,7 +100,7 @@ async function cycleGetDataLauncher(timer: NodeJS.Timeout): Promise<void> {
|
|||||||
if (res.retcode === -106) {
|
if (res.retcode === -106) {
|
||||||
await freshQr();
|
await freshQr();
|
||||||
} else {
|
} else {
|
||||||
clearInterval(timer);
|
if (cycleTimer) clearInterval(cycleTimer);
|
||||||
cycleTimer = null;
|
cycleTimer = null;
|
||||||
model.value = false;
|
model.value = false;
|
||||||
}
|
}
|
||||||
@@ -99,7 +108,7 @@ async function cycleGetDataLauncher(timer: NodeJS.Timeout): Promise<void> {
|
|||||||
}
|
}
|
||||||
if (res.status === "Created" || res.status === "Scanned") return;
|
if (res.status === "Created" || res.status === "Scanned") return;
|
||||||
if (res.status === "Confirmed") {
|
if (res.status === "Confirmed") {
|
||||||
clearInterval(timer);
|
if (cycleTimer) clearInterval(cycleTimer);
|
||||||
cycleTimer = null;
|
cycleTimer = null;
|
||||||
const ck: TGApp.App.Account.Cookie = {
|
const ck: TGApp.App.Account.Cookie = {
|
||||||
account_id: res.user_info.aid,
|
account_id: res.user_info.aid,
|
||||||
@@ -115,8 +124,7 @@ async function cycleGetDataLauncher(timer: NodeJS.Timeout): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-undef
|
async function cycleGetDataGame(): Promise<void> {
|
||||||
async function cycleGetDataGame(timer: NodeJS.Timeout): Promise<void> {
|
|
||||||
const res = await hk4eReq.loginQr.state(codeTicket.value);
|
const res = await hk4eReq.loginQr.state(codeTicket.value);
|
||||||
console.log(res);
|
console.log(res);
|
||||||
if ("retcode" in res) {
|
if ("retcode" in res) {
|
||||||
@@ -124,7 +132,7 @@ async function cycleGetDataGame(timer: NodeJS.Timeout): Promise<void> {
|
|||||||
if (res.retcode === -106) {
|
if (res.retcode === -106) {
|
||||||
await freshQr();
|
await freshQr();
|
||||||
} else {
|
} else {
|
||||||
clearInterval(timer);
|
if (cycleTimer) clearInterval(cycleTimer);
|
||||||
cycleTimer = null;
|
cycleTimer = null;
|
||||||
model.value = false;
|
model.value = false;
|
||||||
}
|
}
|
||||||
@@ -132,7 +140,7 @@ async function cycleGetDataGame(timer: NodeJS.Timeout): Promise<void> {
|
|||||||
}
|
}
|
||||||
if (res.stat === "Init" || res.stat === "Scanned") return;
|
if (res.stat === "Init" || res.stat === "Scanned") return;
|
||||||
if (res.stat === "Confirmed") {
|
if (res.stat === "Confirmed") {
|
||||||
clearInterval(timer);
|
if (cycleTimer) clearInterval(cycleTimer);
|
||||||
cycleTimer = null;
|
cycleTimer = null;
|
||||||
if (res.payload.proto === "Raw") {
|
if (res.payload.proto === "Raw") {
|
||||||
showSnackbar.error(`返回数据异常:${res.payload}`);
|
showSnackbar.error(`返回数据异常:${res.payload}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user