mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
🤔 add(login): 添加 invoke,暂时没有更好的方案了
This commit is contained in:
@@ -1,10 +1,33 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use tauri::Manager;
|
||||
#[tauri::command]
|
||||
async fn mys_login(handle: AppHandle) {
|
||||
// 创建新窗口
|
||||
let mys_window = WindowBuilder::new(
|
||||
&handle,
|
||||
"mys-login", /* the unique window label */
|
||||
WindowUrl::External("https://bbs.mihoyo.com/ys/".parse().unwrap()),
|
||||
)
|
||||
.build()
|
||||
.unwrap();
|
||||
// 执行 js 代码
|
||||
let js_code = "
|
||||
var cookie = document.cookie;
|
||||
if(cookie == null || cookie == ''){
|
||||
alert('请在该网页登录后关闭窗口再试');
|
||||
} else {
|
||||
prompt('请复制以下内容', `mys-login:${cookie}`);
|
||||
}
|
||||
";
|
||||
mys_window.eval(js_code).ok().unwrap();
|
||||
}
|
||||
|
||||
use tauri::{AppHandle, Manager, WindowBuilder, WindowUrl};
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![mys_login])
|
||||
.setup(|app| {
|
||||
#[cfg(debug_assertions)] // only include this code on debug builds
|
||||
{
|
||||
|
||||
@@ -98,6 +98,11 @@
|
||||
</v-btn>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item title="获取Cookie" @click="tryConfirm('getCookie')">
|
||||
<template #prepend>
|
||||
<v-icon>mdi-cookie</v-icon>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-subheader inset class="config-header">
|
||||
路径
|
||||
</v-list-subheader>
|
||||
@@ -127,7 +132,7 @@ import { getBuildTime } from "../utils/TGBuild";
|
||||
import TLoading from "../components/t-loading.vue";
|
||||
import TConfirm from "../components/t-confirm.vue";
|
||||
// tauri
|
||||
import { dialog, fs, app, os } from "@tauri-apps/api";
|
||||
import { dialog, fs, app, os, tauri } from "@tauri-apps/api";
|
||||
// store
|
||||
import { useAppStore } from "../store/modules/app";
|
||||
import { useHomeStore } from "../store/modules/home";
|
||||
@@ -209,6 +214,11 @@ function tryConfirm (oper: string) {
|
||||
confirmOper.value = "delApp";
|
||||
confirmShow.value = true;
|
||||
break;
|
||||
case "getCookie":
|
||||
confirmText.value = "请根据新窗口的提示操作。";
|
||||
confirmOper.value = "getCookie";
|
||||
confirmShow.value = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,6 +234,9 @@ async function doConfirm (oper: string) {
|
||||
case "delApp":
|
||||
await initAppData();
|
||||
break;
|
||||
case "getCookie":
|
||||
await getCookie();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -289,11 +302,16 @@ async function submitHome () {
|
||||
return;
|
||||
}
|
||||
// 设置
|
||||
await homeStore.setShowValue(show);
|
||||
homeStore.setShowValue(show);
|
||||
snackbarText.value = "已修改!";
|
||||
snackbarColor.value = "success";
|
||||
snackbar.value = true;
|
||||
}
|
||||
|
||||
// 获取 Cookie
|
||||
async function getCookie () {
|
||||
await tauri.invoke("mys_login");
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="css" scoped>
|
||||
|
||||
Reference in New Issue
Block a user