🎨 fix(login): 初步检验 login_ticket

This commit is contained in:
BTMuli
2023-04-10 17:14:12 +08:00
parent acfe64c96b
commit 2b3e3cc871
2 changed files with 8 additions and 4 deletions

View File

@@ -50,14 +50,14 @@ async fn mys_login(handle: AppHandle) {
let mys_window = WindowBuilder::new( let mys_window = WindowBuilder::new(
&handle, &handle,
"mys-login", /* the unique window label */ "mys-login", /* the unique window label */
WindowUrl::External("https://bbs.mihoyo.com/ys/".parse().unwrap()), WindowUrl::External("https://user.mihoyo.com".parse().unwrap()),
) )
.build() .build()
.unwrap(); .unwrap();
// 执行 js 代码 // 执行 js 代码
let js_code = " let js_code = "
const cookie = document.cookie; const cookie = document.cookie;
if(cookie == null || cookie == ''){ if(cookie === null || cookie.includes('login_ticket') === false) {
alert('请在该网页登录后关闭窗口再试'); alert('请在该网页登录后关闭窗口再试');
} else { } else {
fetch('http://localhost:8000/login?cookie=' + cookie); fetch('http://localhost:8000/login?cookie=' + cookie);

View File

@@ -106,7 +106,7 @@
重新获取 Cookie 重新获取 Cookie
</v-list-item-title> </v-list-item-title>
<template #append> <template #append>
<v-btn class="card-btn" @click="readCookie()"> <v-btn class="card-btn" @click="showCookie()">
<template #prepend> <template #prepend>
<img src="../assets/icons/circle-check.svg" alt="check"> <img src="../assets/icons/circle-check.svg" alt="check">
查看 Cookie 查看 Cookie
@@ -330,10 +330,14 @@ function submitHome () {
snackbar.value = true; snackbar.value = true;
} }
async function showCookie () {
const cookie = hk4eStore.getCookie();
alert(`Cookie 获取成功!\n\n${cookie}`);
}
// 获取 Cookie // 获取 Cookie
async function readCookie () { async function readCookie () {
const cookie = hk4eStore.getCookie(); const cookie = hk4eStore.getCookie();
// todo 验证 cookie 是否有效
const tryReadCookie = await tauri.invoke("read_cookie") as string || cookie; const tryReadCookie = await tauri.invoke("read_cookie") as string || cookie;
if (cookie === null || tryReadCookie === "") { if (cookie === null || tryReadCookie === "") {
snackbarText.value = "Cookie 为空!"; snackbarText.value = "Cookie 为空!";