From 2bafb6d49154e40f86607b6b75d408ed59b78d47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= Date: Mon, 24 Feb 2025 14:39:08 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=B1=20=E7=82=B9=E8=B5=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/TGBbs.ts | 4 +-- src/views/t-post-json.vue | 7 +++++- src/views/t-post.vue | 41 +++++++++++++++++++++++++++++-- src/web/request/apiHubReq.ts | 26 ++++++++++++++++++++ src/web/utils/getRequestHeader.ts | 10 ++++---- 5 files changed, 78 insertions(+), 10 deletions(-) diff --git a/src/utils/TGBbs.ts b/src/utils/TGBbs.ts index 02f393f3..80c6d393 100644 --- a/src/utils/TGBbs.ts +++ b/src/utils/TGBbs.ts @@ -1,10 +1,10 @@ /** * @file utils/TGBbs.ts * @description 关于 BBS 的工具函数 - * @since Beta v0.6.10 + * @since Beta v0.6.10/v0.7.0 */ -const BBS_VERSION: Readonly = "2.81.1"; +const BBS_VERSION: Readonly = "2.82.0"; const BBS_UA_MOBILE: Readonly = `Mozilla/5.0 (Linux; Android 12) Mobile miHoYoBBS/${BBS_VERSION}`; /** diff --git a/src/views/t-post-json.vue b/src/views/t-post-json.vue index 5f4d46a7..62f05ba9 100644 --- a/src/views/t-post-json.vue +++ b/src/views/t-post-json.vue @@ -12,12 +12,15 @@ import TSwitchTheme from "@comp/app/t-switchTheme.vue"; import showLoading from "@comp/func/loading.js"; import showSnackbar from "@comp/func/snackbar.js"; import Mys from "@Mys/index.js"; +import { storeToRefs } from "pinia"; import { onMounted, ref, shallowRef } from "vue"; import JsonViewer from "vue-json-viewer"; import { useRoute } from "vue-router"; +import { useUserStore } from "@/store/modules/user.js"; import TGLogger from "@/utils/TGLogger.js"; +const { cookie } = storeToRefs(useUserStore()); const postId = Number(useRoute().params.post_id); const isEmpty = ref(false); const jsonData = shallowRef(); @@ -29,7 +32,9 @@ onMounted(async () => { await showLoading.empty("未获取到PostID"); return; } - const resp = await Mys.Post.getPostFull(postId); + let ck: Record | undefined = undefined; + if (cookie.value) ck = { ltoken: cookie.value.ltoken, ltuid: cookie.value.ltuid }; + const resp = await Mys.Post.getPostFull(postId, ck); if ("retcode" in resp) { await showLoading.empty("获取数据失败", `[${resp.retcode}]${resp.message}`); showSnackbar.error(`[${resp.retcode}]${resp.message}`); diff --git a/src/views/t-post.vue b/src/views/t-post.vue index 48cfa933..5e91c4a0 100644 --- a/src/views/t-post.vue +++ b/src/views/t-post.vue @@ -27,7 +27,12 @@ mdi-comment {{ postData?.stat?.reply_num }} -
+
mdi-thumb-up {{ postData?.stat?.like_num }}
@@ -97,17 +102,22 @@ import VpOverlayCollection from "@comp/viewPost/vp-overlay-collection.vue"; import Mys from "@Mys/index.js"; import { app, webviewWindow } from "@tauri-apps/api"; import { emit } from "@tauri-apps/api/event"; +import { storeToRefs } from "pinia"; import { onMounted, onUnmounted, ref, shallowRef } from "vue"; import { useRoute } from "vue-router"; import { useAppStore } from "@/store/modules/app.js"; +import { useUserStore } from "@/store/modules/user.js"; import TGBbs from "@/utils/TGBbs.js"; import TGLogger from "@/utils/TGLogger.js"; import { createTGWindow } from "@/utils/TGWindow.js"; +import apiHubReq from "@/web/request/apiHubReq.js"; +const { cookie } = storeToRefs(useUserStore()); const appVersion = ref(); const postId = Number(useRoute().params.post_id); const showCollection = ref(false); +const isLike = ref(false); const shareTime = ref(Math.floor(Date.now() / 1000)); const renderPost = shallowRef>([]); const postData = shallowRef(); @@ -131,7 +141,9 @@ onMounted(async () => { return; } await showLoading.update(`帖子ID: ${postId}`); - const resp = await Mys.Post.getPostFull(postId); + let ck: undefined | Record; + if (cookie.value) ck = { ltoken: cookie.value.ltoken, ltuid: cookie.value.ltuid }; + const resp = await Mys.Post.getPostFull(postId, ck); if ("retcode" in resp) { await showLoading.empty("数据加载失败", `[${resp.retcode}]${resp.message}`); showSnackbar.error(`[${resp.retcode}] ${resp.message}`); @@ -140,6 +152,7 @@ onMounted(async () => { return; } postData.value = resp; + isLike.value = postData.value.self_operation.upvote_type !== 0; await showLoading.update("正在渲染数据"); renderPost.value = await getRenderPost(postData.value); await webviewWindow @@ -242,6 +255,26 @@ async function createPostJson(postId: number): Promise { await createTGWindow(jsonPath, "Dev_JSON", jsonTitle, 960, 720, false, false); } +async function tryLike(): Promise { + if (!cookie.value) { + showSnackbar.error("请先登录"); + return; + } + if (!postData.value) { + showSnackbar.error("数据未加载"); + return; + } + const ck = { ltoken: cookie.value.ltoken, ltuid: cookie.value.ltuid }; + const resp = await apiHubReq.post.like(postData.value.post.post_id, ck, isLike.value); + if (resp.retcode !== 0) { + showSnackbar.error(`[${resp.retcode}] ${resp.message}`); + return; + } + isLike.value = !isLike.value; + postData.value.stat!.like_num += isLike.value ? 1 : -1; + showSnackbar.success(isLike.value ? "点赞成功" : "取消点赞成功"); +} + function toPost(): void { const channel = TGBbs.channels.find((item) => item.gid === postData.value?.post.game_id); if (channel) { @@ -380,6 +413,10 @@ onUnmounted(() => { margin-left: 10px; column-gap: 2px; opacity: 0.8; + + &.like { + color: var(--tgc-pink-1); + } } /* extra */ diff --git a/src/web/request/apiHubReq.ts b/src/web/request/apiHubReq.ts index 41d3ed22..761c7314 100644 --- a/src/web/request/apiHubReq.ts +++ b/src/web/request/apiHubReq.ts @@ -103,12 +103,38 @@ async function homeNew(gid: number = 2): Promise} cookie 用户 Cookie + * @param {boolean} cancel 是否取消点赞 + * @return {Promise} + */ +async function upVotePost( + id: string, + cookie: Record, + cancel: boolean = false, +): Promise { + const data = { is_cancel: cancel, post_id: id }; + const header = { + ...getRequestHeader(cookie, "POST", data, "K2", true), + "x-rpc-client_type": "2", + }; + return await TGHttp(`${Mahbu}api/upvotePost`, { + method: "POST", + headers: header, + body: JSON.stringify(data), + }); +} + const apiHubReq = { vote: { info: getVotes, result: getVoteResult }, home: homeNew, forum: getAllGamesForums, game: getGameList, mission: getMissions, + post: { like: upVotePost }, }; export default apiHubReq; diff --git a/src/web/utils/getRequestHeader.ts b/src/web/utils/getRequestHeader.ts index 06b2ace5..212acf25 100644 --- a/src/web/utils/getRequestHeader.ts +++ b/src/web/utils/getRequestHeader.ts @@ -1,7 +1,7 @@ /** * @file web/utils/getRequestHeader.ts * @description 获取请求头 - * @since Beta v0.6.8 + * @since Beta v0.6.10/v0.7.0 */ import Md5 from "js-md5"; @@ -24,12 +24,12 @@ const enum SaltType { /** * @description salt 值 - * @version 2.81.1 - * @since Beta v0.6.10 + * @version 2.82.0 + * @since Beta v0.6.10/v0.7.0 */ const Salt: Readonly> = { - K2: "QVu5OdwEWxkq9ygpYBgDprR5tI471HWQ", - LK2: "aquFmwOjyqev4CAL6GQ2v5mdkxpCVXCY", + K2: "RGcLwIWYOQwTQPJ8Qw41kioel738ch3Z", + LK2: "1M69A7AaPUhTFCdH0D2iMatZ0MTiLmPf", X4: "xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs", X6: "t0qEgfub6cvueAPgR5m9aQWWVciEer7v", PROD: "t0qEgfub6cvueAPgR5m9aQWWVciEer7v",