🌱 初步定义&获取终端参数

#195
This commit is contained in:
BTMuli
2026-01-01 19:41:44 +08:00
parent 3e31bae751
commit 15e0a60bb6
11 changed files with 498 additions and 259 deletions

View File

@@ -17,6 +17,7 @@ import showDialog from "@comp/func/dialog.js";
import showLoading from "@comp/func/loading.js";
import showSnackbar from "@comp/func/snackbar.js";
import OtherApi from "@req/otherReq.js";
import * as Sentry from "@sentry/vue";
import TGSqlite from "@Sql/index.js";
import TSUserAccount from "@Sqlm/userAccount.js";
import TSUserAchi from "@Sqlm/userAchi.js";
@@ -26,6 +27,7 @@ import useUserStore from "@store/user.js";
import { app, core, event, webviewWindow } from "@tauri-apps/api";
import type { Event, UnlistenFn } from "@tauri-apps/api/event";
import { getCurrentWindow, LogicalSize } from "@tauri-apps/api/window";
import { type CliMatches, getMatches } from "@tauri-apps/plugin-cli";
import { mkdir } from "@tauri-apps/plugin-fs";
import { openUrl } from "@tauri-apps/plugin-opener";
import TGLogger from "@utils/TGLogger.js";
@@ -256,6 +258,12 @@ async function listenOnInit(): Promise<void> {
} else console.error(e);
}
await checkUpdate();
try {
await handleCommands(await getMatches());
} catch (e) {
console.error("获取启动参数异常");
console.error(e);
}
});
}
@@ -410,6 +418,24 @@ async function handleWindowClose(): Promise<void> {
} else console.error(e);
}
}
// 处理命令行参数
async function handleCommands(cmds: CliMatches): Promise<void> {
if (cmds.subcommand === null) return;
Sentry.logger.info(`捕获到启动参数:${JSON.stringify(cmds)}`);
// 用户脚本
if (cmds.subcommand.name === "us") {
const usMatch = cmds.subcommand.matches;
await router.push({
name: "实用脚本",
query: {
uids: <Array<string>>usMatch.args.uids.value ?? [],
exit: `${usMatch.args.exit.value ?? false}`,
skip: `${usMatch.args.skip.value ?? false}`,
},
});
}
}
</script>
<style lang="css" scoped>
.app-container {

View File

@@ -80,9 +80,19 @@ import painterReq from "@req/painterReq.js";
import TSUserAccount from "@Sqlm/userAccount.js";
import useUserStore from "@store/user.js";
import { storeToRefs } from "pinia";
import { onMounted, ref, shallowRef, useTemplateRef } from "vue";
import { onBeforeMount, onMounted, ref, shallowRef, useTemplateRef } from "vue";
import { useRoute, useRouter } from "vue-router";
const route = useRoute();
const router = useRouter();
const { uid, briefInfo, cookie, account } = storeToRefs(useUserStore());
// 路由参数
const exitAfter = ref<boolean>(false);
const skipGeetest = ref<boolean>(true);
const targetUids = shallowRef<Array<string>>([]);
const accounts = shallowRef<Array<TGApp.App.Account.User>>([]);
const curAccount = shallowRef<TGApp.App.Account.User>();
const runScript = ref<boolean>(false);
@@ -90,9 +100,25 @@ const runAll = ref<boolean>(false);
const missionEl = useTemplateRef("mission");
const signEl = useTemplateRef("sign");
onBeforeMount(async () => {
if (Object.keys(route.query).length > 0) {
exitAfter.value = route.query.exit === "true";
skipGeetest.value = route.query.skip === "true";
if (route.query.uids) {
if (Array.isArray(route.query.uids)) {
targetUids.value = <Array<string>>route.query.uids;
} else {
targetUids.value = [route.query.uids];
}
}
await router.replace({ path: route.path, query: {} });
}
});
onMounted(async () => {
accounts.value = await TSUserAccount.account.getAllAccount();
curAccount.value = accounts.value.find((i) => i.uid === uid.value);
await showLoading.end();
});
async function loadAccount(ac: string): Promise<void> {

View File

@@ -68,7 +68,7 @@ async function getLunaHome(
.map((key) => `${key}=${cookie[key]}`)
.join("; "),
};
if (conf.host) if (conf.host) header["x-rpc-signgame"] = conf.host;
if (conf.host) header["x-rpc-signgame"] = conf.host;
const resp = await TGHttp<TGApp.BBS.Sign.HomeResp>(url, {
method: "GET",
query: params,

View File

@@ -1,6 +1,6 @@
/**
* 路由入口
* @since Beta v0.7.0
* @since Beta v0.9.1
*/
import { createRouter, createWebHistory } from "vue-router";
@@ -9,7 +9,7 @@ import routes from "./routes.js";
const router = createRouter({ history: createWebHistory(), routes: routes });
// 只有在特定页面忽略参数变化
const ignoreRoutes: ReadonlyArray<string> = ["酒馆", "话题"];
const ignoreRoutes: ReadonlyArray<string> = ["酒馆", "话题", "实用脚本"];
// TODO:路由重构 解决路由重复问题
router.afterEach((to, from) => {