diff --git a/src/components/home/t-pool.vue b/src/components/home/t-pool.vue index fb0d6ee6..91b7518c 100644 --- a/src/components/home/t-pool.vue +++ b/src/components/home/t-pool.vue @@ -52,8 +52,9 @@ import { ref, onMounted, onUnmounted } from "vue"; import { useRouter } from "vue-router"; import Mys from "../../plugins/Mys"; +import { useAppStore } from "../../store/modules/app"; import { useHomeStore } from "../../store/modules/home"; -import { createTGWindow } from "../../utils/TGWindow"; +import { createPost, createTGWindow } from "../../utils/TGWindow"; import { stamp2LastTime } from "../../utils/toolFunc"; // vue @@ -176,13 +177,8 @@ async function toOuter(url: string, title: string): Promise { } function toPost(pool: TGApp.Plugins.Mys.Gacha.RenderCard): void { - const path = router.resolve({ - name: "帖子详情", - params: { - post_id: pool.postId.toString(), - }, - }).href; - createTGWindow(path, "Sub_window", `Post_${pool.postId} ${pool.title}`, 960, 720, false, false); + const isDev = useAppStore().devMode; + createPost(pool.postId.toString(), isDev); } onUnmounted(() => { diff --git a/src/components/home/t-position.vue b/src/components/home/t-position.vue index 6c2e3850..49af4ca4 100644 --- a/src/components/home/t-position.vue +++ b/src/components/home/t-position.vue @@ -48,7 +48,8 @@ import { ref, onMounted, onUnmounted } from "vue"; import { useRouter } from "vue-router"; import Mys from "../../plugins/Mys"; -import { createTGWindow } from "../../utils/TGWindow"; +import { useAppStore } from "../../store/modules/app"; +import { createPost } from "../../utils/TGWindow"; import { stamp2LastTime } from "../../utils/toolFunc"; // vue @@ -105,16 +106,9 @@ onMounted(async () => { loading.value = false; }); -async function toPost(card: TGApp.Plugins.Mys.Position.RenderCard): Promise { - // 获取路由路径 - const path = router.resolve({ - name: "帖子详情", - params: { - post_id: card.postId, - }, - }).href; - // 打开新窗口 - createTGWindow(path, "Sub_window", `Post_${card.postId} ${card.title}`, 960, 720, false, false); +function toPost(card: TGApp.Plugins.Mys.Position.RenderCard): void { + const isDev = useAppStore().devMode; + createPost(card.postId.toString(), isDev); } onUnmounted(() => { diff --git a/src/utils/TGWindow.ts b/src/utils/TGWindow.ts index 07efc7ea..cc69f351 100644 --- a/src/utils/TGWindow.ts +++ b/src/utils/TGWindow.ts @@ -1,11 +1,11 @@ /** * @file utils TGWindow.ts - * @description 用于创建TG窗口的工具 - * @author BTMuli - * @since Alpha v0.1.2 + * @description 窗口创建相关工具函数 + * @since Beta v0.3.3 */ import { window as TauriWindow } from "@tauri-apps/api"; + /** * @description 创建TG窗口 * @since Alpha v0.1.2 @@ -54,3 +54,32 @@ export function createTGWindow( }); }); } + +/** + * @description 打开帖子 + * @since Beta v0.3.3 + * @param {TGApp.Plugins.Mys.News.RenderCard|string} item 帖子内容或ID + * @param {boolean} isDev 是否为开发模式 + * @returns {void} + */ +export function createPost( + item: TGApp.Plugins.Mys.News.RenderCard | string, + isDev: boolean = false, +): void { + let postId, postTitle, jsonTitle; + if (typeof item === "string") { + postId = item; + postTitle = `Post_${postId}`; + jsonTitle = `Post_${postId}_JSON`; + } else { + postId = item.postId.toString(); + postTitle = `Post_${postId} ${item.title}`; + jsonTitle = `Post_${postId}_JSON ${item.title}`; + } + const postPath = `/post_detail/${postId}`; + const jsonPath = `/post_detail_json/${postId}`; + if (isDev) { + createTGWindow(jsonPath, "Dev_JSON", jsonTitle, 960, 720, false, false); + } + createTGWindow(postPath, "Sub_window", postTitle, 960, 720, false, false); +} diff --git a/src/views/t-news.vue b/src/views/t-news.vue index 2ca71f12..0b74fd44 100644 --- a/src/views/t-news.vue +++ b/src/views/t-news.vue @@ -1,9 +1,13 @@