🌱 点赞

This commit is contained in:
目棃
2025-02-24 14:39:08 +08:00
parent 0f278ad25e
commit 2bafb6d491
5 changed files with 78 additions and 10 deletions

View File

@@ -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<string> = "2.81.1";
const BBS_VERSION: Readonly<string> = "2.82.0";
const BBS_UA_MOBILE: Readonly<string> = `Mozilla/5.0 (Linux; Android 12) Mobile miHoYoBBS/${BBS_VERSION}`;
/**

View File

@@ -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<boolean>(false);
const jsonData = shallowRef<TGApp.Plugins.Mys.Post.FullData>();
@@ -29,7 +32,9 @@ onMounted(async () => {
await showLoading.empty("未获取到PostID");
return;
}
const resp = await Mys.Post.getPostFull(postId);
let ck: Record<string, string> | 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}`);

View File

@@ -27,7 +27,12 @@
<v-icon>mdi-comment</v-icon>
<span>{{ postData?.stat?.reply_num }}</span>
</div>
<div class="mpm-item" :title="`点赞数:${postData?.stat?.like_num}`">
<div
class="mpm-item"
:title="`点赞数:${postData?.stat?.like_num}`"
@click="tryLike()"
:class="{ like: isLike }"
>
<v-icon>mdi-thumb-up</v-icon>
<span>{{ postData?.stat?.like_num }}</span>
</div>
@@ -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<string>();
const postId = Number(useRoute().params.post_id);
const showCollection = ref<boolean>(false);
const isLike = ref<boolean>(false);
const shareTime = ref<number>(Math.floor(Date.now() / 1000));
const renderPost = shallowRef<Array<TGApp.Plugins.Mys.SctPost.Base>>([]);
const postData = shallowRef<TGApp.Plugins.Mys.Post.FullData>();
@@ -131,7 +141,9 @@ onMounted(async () => {
return;
}
await showLoading.update(`帖子ID: ${postId}`);
const resp = await Mys.Post.getPostFull(postId);
let ck: undefined | Record<string, string>;
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<void> {
await createTGWindow(jsonPath, "Dev_JSON", jsonTitle, 960, 720, false, false);
}
async function tryLike(): Promise<void> {
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 */

View File

@@ -103,12 +103,38 @@ async function homeNew(gid: number = 2): Promise<TGApp.BBS.Navigator.Navigator[]
).data.navigator;
}
/**
* @description 点赞
* @since Beta v0.6.10/v0.7.0
* @param {string} id 帖子 ID
* @param {Record<string,string>} cookie 用户 Cookie
* @param {boolean} cancel 是否取消点赞
* @return {Promise<TGApp.BBS.Response.Base>}
*/
async function upVotePost(
id: string,
cookie: Record<string, string>,
cancel: boolean = false,
): Promise<TGApp.BBS.Response.Base> {
const data = { is_cancel: cancel, post_id: id };
const header = {
...getRequestHeader(cookie, "POST", data, "K2", true),
"x-rpc-client_type": "2",
};
return await TGHttp<TGApp.BBS.Response.Base>(`${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;

View File

@@ -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<Record<keyof typeof SaltType, string>> = {
K2: "QVu5OdwEWxkq9ygpYBgDprR5tI471HWQ",
LK2: "aquFmwOjyqev4CAL6GQ2v5mdkxpCVXCY",
K2: "RGcLwIWYOQwTQPJ8Qw41kioel738ch3Z",
LK2: "1M69A7AaPUhTFCdH0D2iMatZ0MTiLmPf",
X4: "xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs",
X6: "t0qEgfub6cvueAPgR5m9aQWWVciEer7v",
PROD: "t0qEgfub6cvueAPgR5m9aQWWVciEer7v",