添加getRegionRoleInfo事件处理

This commit is contained in:
BTMuli
2025-10-25 21:04:04 +08:00
parent 68dead3d84
commit 65e948c34c
5 changed files with 197 additions and 187 deletions

View File

@@ -8,7 +8,7 @@ mod utils;
use tauri::{AppHandle, Manager, WebviewWindowBuilder};
use tauri_utils::config::WebviewUrl;
static BBS_VERSION: &'static str = "2.93.0";
static BBS_VERSION: &'static str = "2.95.1";
#[tauri::command]
pub async fn create_mhy_client(handle: AppHandle, func: String, url: String) {

View File

@@ -42,7 +42,7 @@
</template>
<script lang="ts" setup>
import TMiImg from "@comp/app/t-mi-img.vue";
import { openUrl } from "@tauri-apps/plugin-opener";
import TGClient from "@utils/TGClient.js";
type TpUgcLevel = { insert: { level: TGApp.BBS.UGC.Level } };
type TpUgcLevelProps = { data: TpUgcLevel };
@@ -52,9 +52,7 @@ const props = defineProps<TpUgcLevelProps>();
async function toLevel(): Promise<void> {
let url = `https://act.miyoushe.com/ys/ugc_community/mx/#/pages/level-detail/index?`;
url = `${url}id=${props.data.insert.level.level_id}&region=${props.data.insert.level.region}`;
// TODO: 存在BUG
// await TGClient.open("web_act_thin", url.toString());
await openUrl(url);
await TGClient.open("web_act_thin", url.toString());
}
</script>
<style lang="scss" scoped>

View File

@@ -1,247 +1,246 @@
/**
* @file types/Plugins/JSBridge.d.ts
* @description JSBridge 插件相关类型定义文件
* @since Beta v0.6.0
* JSBridge 插件相关类型定义文件
* @since Beta v0.8.4
*/
/**
* @description JSBridge 插件相关类型命名
* @since Beta v0.6.0
* @namespace TGApp.Plugins.JSBridge
* @memberof TGApp.Plugins
*/
declare namespace TGApp.Plugins.JSBridge {
/**
* @description JSBridge 通用 arg 参数
* JSBridge 通用 arg 参数
* @since Beta v0.3.9
* @interface Arg
* @template T
* @property {string} method - 方法名
* @property {T} payload - 参数
* @property {string} callback - 回调函数名
* @return Arg
*/
interface Arg<T> {
type Arg<T> = {
/** 方法名 */
method: string;
/** 参数 */
payload: T;
/** 回调函数名 */
callback: string;
}
};
/**
* @description 通用 arg 参数-无参数
* 通用 arg 参数-无参数
* @since Beta v0.3.9
* @interface NullArg
* @return NullArg
*/
type NullArg = Arg<null>;
/**
* @description configShare 方法参数
* configShare 方法参数
* @since Beta v0.3.9
* @interface ConfigSharePayload
* @property {boolean} enable - 是否启用分享
* @return ConfigSharePayload
*/
interface ConfigSharePayload {
type ConfigSharePayload = {
/** 是否启用分享 */
enable: boolean;
}
};
/**
* @description eventTrack 方法参数
* eventTrack 方法参数
* @since Beta v0.3.9
* @interface EventTrackPayload
* @property {object} pageInfo - 页面信息
* @property {string} pageInfo.page_path - 页面路径
* @property {string} pageInfo.page_name - 页面名称
* @property {string} pageInfo.sub_page_path - 子页面路径
* @property {string} pageInfo.sub_page_name - 子页面名称
* @property {string} pageInfo.source_path - 来源页面路径
* @property {string} pageInfo.source_name - 来源页面名称
* @property {string} pageInfo.page_id - 页面 ID
* @property {string} pageInfo.page_type - 页面类型
* @property {string} pageInfo.source_id - 来源 ID
* @property {unknown} pageInfo.extra_info - 额外信息
* @property {object} eventInfo - 事件信息
* @property {string} eventInfo.time - 事件时间
* @property {number} eventInfo.action_id - 事件 ID
* @property {string} eventInfo.btn_name - 按钮名称
* @property {string} eventInfo.module_id - 模块 ID
* @property {string} eventInfo.module_name - 模块名称
* @property {unknown} eventInfo.extra_info - 额外信息
* @property {object} commonInfo - 公共信息
* @property {object} commonInfo.extra_info - 额外信息
* @property {string} commonInfo.extra_info.game_id - 游戏 ID
* @property {string} commonInfo.extra_info.view_type - 视图类型
* @return EventTrackPayload
*/
interface EventTrackPayload {
type EventTrackPayload = {
/** 页面信息 */
pageInfo: {
/** 页面路径 */
page_path: string;
/** 页面名称 */
page_name: string;
/** 子页面路径 */
sub_page_path: string;
/** 子页面名称 */
sub_page_name: string;
/** 来源页面路径 */
source_path: string;
/** 来源页面名称 */
source_name: string;
/** 页面 ID */
page_id: string;
/** 页面类型 */
page_type: string;
/** 来源 ID */
source_id: string;
/** 额外信息 */
extra_info: unknown;
};
/** 事件信息 */
eventInfo: {
/** 事件发生时间 */
time: string;
/** 事件 ID */
action_id: number;
/** 按钮名称 */
btn_name: string;
/** 模块 ID */
module_id: string;
/** 模块名称 */
module_name: string;
/** 额外信息 */
extra_info: unknown;
};
/** 公共信息 */
commonInfo: {
/** 额外信息 */
extra_info: {
/** 游戏 ID */
game_id: string;
/** 视图类型 */
view_type: string;
};
};
}
};
/**
* @description getActionTicket 方法参数
* getActionTicket 方法参数
* @since Beta v0.3.9
* @interface GetActionTicketPayload
* @property {string} action_type
* @return GetActionTicketPayload
*/
interface GetActionTicketPayload {
type GetActionTicketPayload = {
/** 行为类型 */
action_type: string;
}
};
/**
* @description genAuthkey 方法参数
* genAuthkey 方法参数
* @since Beta v0.3.9
* @interface GenAuthkeyPayload
* @return GenAuthkeyPayload
*/
type GenAuthkeyPayload = Record<string, string>;
/**
* @description getCookieToken 方法参数
* getCookieToken 方法参数
* @since Beta v0.3.9
* @interface GetCookieTokenPayload
* @property {boolean} forceRefresh - 是否强制刷新
* @return GetCookieTokenPayload
*/
interface GetCookieTokenPayload {
type GetCookieTokenPayload = {
/** 是否强制刷新 */
forceRefresh: boolean;
}
};
/**
* @description getDS2 方法参数
* getDS2 方法参数
* @since Beta v0.3.9
* @interface GetDS2Payload
* @property {Record<string,string|number>|string} query - 查询参数
* @property {Record<string,string|number>|string} body - 请求体
* @return GetDS2Payload
*/
interface GetDS2Payload {
type GetDS2Payload = {
/** 查询参数 */
query: Record<string, string | number> | string;
/** 请求体 */
body: Record<string, string | number> | string;
}
};
/**
* @description onClickImg 方法参数
* onClickImg 方法参数
* @since Beta v0.3.9
* @interface OnClickImgPayload
* @property {Array<object>} image_list - 图片列表
* @property {string} image_list[].url - 图片链接
* @property {string} image_list[].format - 图片格式
* @return OnClickImgPayload
*/
interface OnClickImgPayload {
type OnClickImgPayload = {
/** 图片列表 */
image_list: Array<{
/** 图片链接 */
url: string;
/** 图片格式 */
format: string;
}>;
}
};
/**
* @description openApplication 方法参数
* openApplication 方法参数
* @since Beta v0.3.9
* @interface OpenApplicationPayload
* @property {number} gameCenterId - 游戏中心对应 id
* @return OpenApplicationPayload
*/
interface OpenApplicationPayload {
type OpenApplicationPayload = {
/** 游戏中心对应 id */
gameCenterId: number;
}
};
/**
* @description 打开系统浏览器
* openSystemBrowser 方法参数
* @since Beta v0.6.0
* @interface OpenSystemBrowserPayload
* @property {string} open_url - 打开的链接
* @return OpenSystemBrowserPayload
*/
interface OpenSystemBrowserPayload {
type OpenSystemBrowserPayload = {
/** 打开的链接 */
open_url: string;
}
};
/**
* @description pushPage 方法参数
* pushPage 方法参数
* @since Beta v0.3.9
* @interface PushPagePayload
* @property {string} page - 页面地址
* @return PushPagePayload
*/
interface PushPagePayload {
type PushPagePayload = {
/** 页面地址 */
page: string;
}
};
/**
* @description setPresentationStyle 方法参数
* setPresentationStyle 方法参数
* @since Beta v0.3.9
* @interface SetPresentationStylePayload
* @property {string} style - 窗口样式
* @property {unknown} navigationBar - 导航栏
* @property {string} statusBar.style - 状态栏模式
* @return SetPresentationStylePayload
*/
interface SetPresentationStylePayload {
type SetPresentationStylePayload = {
/** 窗口样式 */
style: string;
/** 导航栏 */
navigationBar: unknown;
/** 状态栏模式 */
statusBar: {
/** 状态栏模式 */
style: string;
};
}
};
/**
* @description share 方法参数
* share 方法参数
* @since Beta v0.3.9
* @interface SharePayload
* @property {string} type - 分享类型 // screenshot
* @property {object} content - 分享内容
* @property {boolean} content?.preview - 是否预览
* @return SharePayload
*/
type SharePayload =
| {
type: "default";
content: {
title: string;
description: string;
link: string;
image_url: string;
};
}
| {
type: "screenshot";
content: {
preview: boolean;
};
}
| {
type: "image";
content: {
image_url?: string;
image_base64?: string;
};
};
type SharePayload = SharePayloadDefault | SharePayloadScreenshot | SharePayloadImage;
/**
* share 方法参数-默认分享
* @since Beta v0.8.4
*/
type SharePayloadDefault = {
/** 分享类型,默认值"default" */
type: "default";
/** 分享内容 */
content: {
/** 标题 */
title: string;
/** 描述 */
description: string;
/** 链接 */
link: string;
/** 图片链接 */
image_url: string;
};
};
/**
* share 方法参数-截图分享
* @since Beta v0.8.4
*/
type SharePayloadScreenshot = {
/** 分享类型,值为"screenshot" */
type: "screenshot";
/** 分享内容 */
content: {
/** 是否预览 */
preview: boolean;
};
};
/**
* share 方法参数-图片分享
* @since Beta v0.8.4
*/
type SharePayloadImage = {
/** 分享类型,值为"image" */
type: "image";
/** 分享内容 */
content: {
/** 图片链接(可选) */
image_url?: string;
/** 图片的 Base64 编码(可选) */
image_base64?: string;
};
};
/**
* getRegionRoleInfo 方法参数
* @since Beta v0.8.4
*/
type GetRegionRoleInfoPayload = {
/** 游戏 biz 标识 */
game_biz: string;
};
}

View File

@@ -1,27 +1,26 @@
/**
* @file utils/TGBbs.ts
* @description 关于 BBS 的工具函数
* @since Beta v0.8.0
* 关于 BBS 的工具函数
* @since Beta v0.8.4
*/
/**
* @description salt 类型
* @since Beta v0.7.3
* salt 类型
* @since Beta v0.8.4
*/
export type SaltKey = "K2" | "LK2" | "X4" | "X6" | "PROD";
const BBS_VERSION: Readonly<string> = "2.93.0";
const BBS_VERSION: Readonly<string> = "2.95.1";
const BBS_UA_MOBILE: Readonly<string> = `Mozilla/5.0 (Linux; Android 12) Mobile miHoYoBBS/${BBS_VERSION}`;
const BBS_UA_PC: Readonly<string> = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) miHoYoBBS/${BBS_VERSION}`;
/**
* @description salt 值
* @version 2.93.0
* @since Beta v0.8.0
* salt 值
* @version 2.95.1
* @since Beta v0.8.4
*/
const BBS_SALT: Readonly<Record<SaltKey, string>> = {
K2: "idMMaGYmVgPzh3wxmWudUXKUPGidO7GM",
LK2: "G1ktdwFL4IyGkHuuWSmz0wUe9Db9scyK",
K2: "sfYPEgpxkOe1I3XVMLdwp1Lyt9ORgZsq",
LK2: "sidQFEglajEz7FA0Aj7HQPV88zpf17SO",
X4: "xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs",
X6: "t0qEgfub6cvueAPgR5m9aQWWVciEer7v",
PROD: "t0qEgfub6cvueAPgR5m9aQWWVciEer7v",

View File

@@ -1,6 +1,5 @@
/**
* @file utils/TGClient.ts
* @desc 负责米游社客户端的 callback 处理
* 负责米游社客户端的 callback 处理
* @since Beta v0.8.3
*/
@@ -23,9 +22,6 @@ import TGLogger from "./TGLogger.js";
import { createPost } from "./TGWindow.js";
import { getDeviceInfo } from "./toolFunc.js";
// invoke 参数
type InvokeArg = { func: string };
class Client {
private listener: UnlistenFn | undefined;
private route: string[] = [];
@@ -43,10 +39,9 @@ class Client {
}
/**
* @func run
* 运行米游社客户端
* @since Beta v0.3.4
* @desc 运行米游社客户端
* @returns {void} - 无返回值
* @returns Promise<void>
*/
async run(): Promise<void> {
if (this.listener === undefined) {
@@ -58,15 +53,12 @@ class Client {
}
}
/* 内置函数 */
/**
* @func callback
* 回调函数
* @since Beta v0.5.0
* @desc 回调函数
* @param {string} callback - 回调函数名
* @param {object} data - 回调数据
* @returns {void} - 无返回值
* @returns Promise<void>
*/
async callback(callback: string, data: object): Promise<void> {
const response = { retcode: 0, message: "success", data: data ?? {} };
@@ -76,12 +68,11 @@ class Client {
}
/**
* @func getSaveImgJS
* 获取保存图片的 JS
* @since Beta v0.5.1
* @desc 获取保存图片的 JS
* @param {string} url - 图片链接
* @param {string} format - 图片格式
* @returns {string} - JS
* @returns JS代码字符串
*/
getSaveImgJS(url: string, format: string): string {
return `javascript:(async function() {
@@ -104,9 +95,8 @@ class Client {
}
/**
* @func getUrl
* 获取 url
* @since Beta v0.5.0
* @desc 获取 url
* @param {string} func - 方法名
* @returns {string} - url
*/
@@ -130,9 +120,8 @@ class Client {
}
/**
* @func handleCallback
* 处理米游社客户端的 callback
* @since Beta v0.6.1
* @desc 处理米游社客户端的 callback
* @param {Event<string>} arg - 事件参数
* @returns {Promise<void>} - 返回值
*/
@@ -162,14 +151,16 @@ class Client {
<TGApp.Plugins.JSBridge.Arg<TGApp.Plugins.JSBridge.EventTrackPayload>>argParse,
);
break;
case "getStatusBarHeight":
await this.getStatusBarHeight(<TGApp.Plugins.JSBridge.NullArg>argParse);
break;
case "genAuthKey":
await this.genAuthKey(
<TGApp.Plugins.JSBridge.Arg<TGApp.Plugins.JSBridge.GenAuthkeyPayload>>argParse,
);
break;
case "getActionTicket":
await this.getActionTicket(
<TGApp.Plugins.JSBridge.Arg<TGApp.Plugins.JSBridge.GetActionTicketPayload>>argParse,
);
break;
case "getCookieInfo":
await this.getCookieInfo(<TGApp.Plugins.JSBridge.NullArg>argParse);
break;
@@ -178,14 +169,6 @@ class Client {
<TGApp.Plugins.JSBridge.Arg<TGApp.Plugins.JSBridge.GetCookieTokenPayload>>argParse,
);
break;
case "getActionTicket":
await this.getActionTicket(
<TGApp.Plugins.JSBridge.Arg<TGApp.Plugins.JSBridge.GetActionTicketPayload>>argParse,
);
break;
case "getHTTPRequestHeaders":
await this.getHTTPRequestHeaders(<TGApp.Plugins.JSBridge.NullArg>argParse);
break;
case "getDS":
await this.getDS(<TGApp.Plugins.JSBridge.NullArg>argParse);
break;
@@ -194,6 +177,17 @@ class Client {
<TGApp.Plugins.JSBridge.Arg<TGApp.Plugins.JSBridge.GetDS2Payload>>argParse,
);
break;
case "getHTTPRequestHeaders":
await this.getHTTPRequestHeaders(<TGApp.Plugins.JSBridge.NullArg>argParse);
break;
case "getRegionRoleInfo":
await this.getRegionRoleInfo(
<TGApp.Plugins.JSBridge.Arg<TGApp.Plugins.JSBridge.GetRegionRoleInfoPayload>>argParse,
);
break;
case "getStatusBarHeight":
await this.getStatusBarHeight(<TGApp.Plugins.JSBridge.NullArg>argParse);
break;
case "getUserInfo":
await this.getUserInfo(<TGApp.Plugins.JSBridge.NullArg>argParse);
break;
@@ -437,7 +431,7 @@ class Client {
await TGLogger.Error(`[TGClient][open] ${e}`);
}
}
await core.invoke<InvokeArg>("create_mhy_client", { func, url });
await core.invoke("create_mhy_client", { func, url });
await this.loadJSBridge();
}
@@ -657,6 +651,26 @@ class Client {
await this.callback(arg.callback, data);
}
/**
* 获取对应区服的角色信息
* @since Beta v0.8.4
* @param {TGApp.Plugins.JSBridge.Arg<TGApp.Plugins.JSBridge.GetRegionRoleInfoPayload>} arg - 方法参数
* @returns {Promise<void>} - 无返回值
*/
async getRegionRoleInfo(
arg: TGApp.Plugins.JSBridge.Arg<TGApp.Plugins.JSBridge.GetRegionRoleInfoPayload>,
): Promise<void> {
const user = useUserStore();
const data = {
region: user.account.region,
game_uid: user.account.gameUid,
nickname: user.account.nickname,
user_label: user.account.nickname,
region_name: user.account.regionName,
};
await this.callback(arg.callback, data);
}
/**
* @func getUserInfo
* @since Beta v0.3.9