diff --git a/src/pages/User/Gacha.vue b/src/pages/User/Gacha.vue index 13803a00..422e6bc7 100644 --- a/src/pages/User/Gacha.vue +++ b/src/pages/User/Gacha.vue @@ -283,25 +283,11 @@ async function getGachaLogs(pool: string, endId: string = "0", check?: string): // 导入按钮点击事件 async function handleImportBtn(isV4: boolean): Promise { - if (isV4) { - const checkConfirm = await showConfirm({ title: "确定导入UIGFv4格式的祈愿数据?" }); - if (!checkConfirm) { - showSnackbar({ color: "cancel", text: "已取消 UIGF v4 格式导入" }); - return; - } - await TGLogger.Info("[UserGacha][handleImportBtn] 导入祈愿数据(v4)"); - } else { - await TGLogger.Info("[UserGacha][handleImportBtn] 导入祈愿数据"); - } + await TGLogger.Info(`[UserGacha][handleImportBtn] 导入祈愿数据${isV4 ? "(v4)" : ""}`); const selectedFile = await open({ multiple: false, - title: "选择要导入的祈愿数据文件", - filters: [ - { - name: "UIGF JSON", - extensions: ["json"], - }, - ], + title: "导入UIGF文件", + filters: [{ name: "UIGF JSON", extensions: ["json"] }], defaultPath: await path.downloadDir(), directory: false, }); @@ -311,11 +297,8 @@ async function handleImportBtn(isV4: boolean): Promise { } const check = await verifyUigfData(selectedFile, isV4); if (!check) return; - if (isV4) { - await importUigf4(selectedFile); - } else { - await importUigf(selectedFile); - } + if (isV4) await importUigf4(selectedFile); + else await importUigf(selectedFile); } // 导入 v4 版本的祈愿数据 @@ -393,13 +376,8 @@ async function exportUigf(): Promise { return; } const file = await save({ - title: "选择导出祈愿数据的文件路径", - filters: [ - { - name: "UIGF JSON", - extensions: ["json"], - }, - ], + title: "导出祈愿数据", + filters: [{ name: "UIGF JSON", extensions: ["json"] }], defaultPath: `${await path.downloadDir()}${path.sep()}UIGF_${uidCur.value}.json`, }); if (!file) { diff --git a/src/utils/TGClient.ts b/src/utils/TGClient.ts index 6d1215a2..2ca6dd7a 100644 --- a/src/utils/TGClient.ts +++ b/src/utils/TGClient.ts @@ -1,7 +1,7 @@ /** * @file utils/TGClient.ts * @desc 负责米游社客户端的 callback 处理 - * @since Beta v0.6.0 + * @since Beta v0.6.3 */ import { event, core, webviewWindow } from "@tauri-apps/api"; @@ -456,10 +456,7 @@ class TGClient { try { await windowFind.destroy(); } catch (e) { - showSnackbar({ - text: `[TGClient][open] ${e}`, - color: "error", - }); + showSnackbar({ text: `[TGClient][open] ${e}`, color: "error" }); await TGLogger.Error(`[TGClient][open] ${e}`); } } @@ -479,9 +476,7 @@ class TGClient { this.route.pop(); if (this.route.length === 0) { const windowFind = await webviewWindow.WebviewWindow.getByLabel("mhy_client"); - if (windowFind != null) { - await windowFind.destroy(); - } + if (windowFind != null) await windowFind.destroy(); return; } const url = this.route[this.route.length - 1]; @@ -535,10 +530,7 @@ class TGClient { ): Promise { const userStore = useUserStore(); if (!userStore.cookie) return; - const cookie = { - mid: userStore.cookie.mid, - stoken: userStore.cookie.stoken, - }; + const cookie = { mid: userStore.cookie.mid, stoken: userStore.cookie.stoken }; const res = await TGRequest.User.getAuthkey2(cookie, arg.payload); await this.callback(arg.callback, res.data); } @@ -577,17 +569,13 @@ class TGClient { async getCookieInfo(arg: TGApp.Plugins.JSBridge.NullArg): Promise { const user = useUserStore(); if (!user.cookie) return; - const data = { - ltoken: user.cookie.ltoken, - ltuid: user.cookie.ltuid, - login_ticket: "", - }; + const data = { ltoken: user.cookie.ltoken, ltuid: user.cookie.ltuid, login_ticket: "" }; await this.callback(arg.callback, data); } /** * @func getCookieToken - * @since Beta v0.5.5 + * @since Beta v0.6.3 * @desc 获取米游社客户端的 cookie_token * @param {TGApp.Plugins.JSBridge.Arg} arg - 请求参数 * @returns {void} - 无返回值 @@ -599,34 +587,25 @@ class TGClient { if (!user.cookie) return; if (arg.payload.forceRefresh) { const res = await getCookieTokenBySToken(user.cookie.mid, user.cookie.stoken); - if (typeof res !== "string") { - return; - } + if (typeof res !== "string") return; user.cookie.cookie_token = res; await TGSqlite.saveAppData("cookie", JSON.stringify(user.cookie)); } - // todo 优化代码 const executeJS = `javascript:(function(){ - let domainCur = window.location.hostname; - if(domainCur.endsWith('.miyoushe.com')) { - domainCur = '.miyoushe.com'; - } else { - domainCur = '.mihoyo.com'; - } - document.cookie = "account_id_v2=${user.cookie.account_id};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;"; - document.cookie = "cookie_token=${user.cookie.cookie_token};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;"; - document.cookie = "ltuid_v2=${user.cookie.ltuid};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;"; - document.cookie = "ltoken=${user.cookie.ltoken};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;"; - document.cookie = "account_id=${user.cookie.account_id};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;"; - document.cookie = "account_mid_v2=${user.cookie.mid};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;"; - document.cookie = "ltuid_v2=${user.cookie.ltuid};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;"; - document.cookie = "ltmid_v2=${user.cookie.mid};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;"; + let domainCur = window.location.hostname; + if (domainCur.endsWith('.miyoushe.com')) domainCur = '.miyoushe.com'; + else domainCur = '.mihoyo.com'; + document.cookie = 'account_id=${user.cookie!.account_id}; domain=' + domainCur + '; path=/; max-age=31536000'; + document.cookie = 'account_id_v2=${user.cookie!.account_id}; domain=' + domainCur + '; path=/; max-age=31536000'; + document.cookie = 'account_mid_v2=${user.cookie!.mid}; domain=' + domainCur + '; path=/; max-age=31536000'; + document.cookie = 'cookie_token=${user.cookie!.cookie_token}; domain=' + domainCur + '; path=/; max-age=31536000'; + document.cookie = 'ltmid_v2=${user.cookie!.mid}; domain=' + domainCur + '; path=/; max-age=31536000'; + document.cookie = 'ltoken=${user.cookie!.ltoken}; domain=' + domainCur + '; path=/; max-age=31536000'; + document.cookie = 'ltuid_v2=${user.cookie!.ltuid}; domain=' + domainCur + '; path=/; max-age=31536000'; })();`; console.info(`[getCookieToken] ${executeJS}`); await core.invoke("execute_js", { label: "mhy_client", js: executeJS }); - const data = { - cookie_token: user.cookie.cookie_token, - }; + const data = { cookie_token: user.cookie.cookie_token }; await this.callback(arg.callback, data); } @@ -638,9 +617,7 @@ class TGClient { * @returns {void} - 无返回值 */ async getDS(arg: TGApp.Plugins.JSBridge.NullArg): Promise { - const data = { - DS: getDS4JS("lk2", 1, undefined, undefined), - }; + const data = { DS: getDS4JS("lk2", 1, undefined, undefined) }; await this.callback(arg.callback, data); } @@ -691,9 +668,7 @@ class TGClient { * @returns {void} - 无返回值 */ async getStatusBarHeight(arg: TGApp.Plugins.JSBridge.NullArg): Promise { - const data = { - statusBarHeight: 0, - }; + const data = { statusBarHeight: 0 }; await this.callback(arg.callback, data); } @@ -750,15 +725,9 @@ class TGClient { text: `不支持的操作:OpenApplication(${JSON.stringify(arg.payload)})`, color: "error", }); - await new Promise((resolve) => { - setTimeout(() => { - resolve(); - }, 1500); - }); + await new Promise((resolve) => setTimeout(() => resolve(), 1500)); const windowFind = await webviewWindow.WebviewWindow.getByLabel("mhy_client"); - if (windowFind !== null) { - await windowFind.setFocus(); - } + if (windowFind !== null) await windowFind.setFocus(); } /** @@ -792,11 +761,7 @@ class TGClient { if (appWindow != null) { await appWindow.setFocus(); } - showSnackbar({ - text: `未知链接:${arg.payload.page}`, - color: "error", - timeout: 3000, - }); + showSnackbar({ text: `未知链接:${arg.payload.page}`, color: "error", timeout: 3000 }); await new Promise((resolve) => { setTimeout(() => { resolve();