From ca9c5ca931ec9a2ccd8116f7a6b63c41cba50fa0 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Thu, 28 Dec 2023 00:15:08 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=B7=BB=E5=8A=A0=20TpVote?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * PostID:44118649 --- src/components/post/tp-parser.vue | 3 + src/components/post/tp-vote.vue | 143 +++++++++++++++++++++++++ src/plugins/Mys/index.ts | 5 + src/plugins/Mys/request/getVoteData.ts | 56 ++++++++++ src/plugins/Mys/types/Vote.d.ts | 83 ++++++++++++++ 5 files changed, 290 insertions(+) create mode 100644 src/components/post/tp-vote.vue create mode 100644 src/plugins/Mys/request/getVoteData.ts create mode 100644 src/plugins/Mys/types/Vote.d.ts diff --git a/src/components/post/tp-parser.vue b/src/components/post/tp-parser.vue index 0a0ce63f..6ae3f282 100644 --- a/src/components/post/tp-parser.vue +++ b/src/components/post/tp-parser.vue @@ -11,6 +11,7 @@ import TpText from "./tp-text.vue"; import TpUnknown from "./tp-unknown.vue"; import TpVillaCard from "./tp-villaCard.vue"; import TpVod from "./tp-vod.vue"; +import TpVote from "./tp-vote.vue"; interface TpParserProps { data: TGApp.Plugins.Mys.SctPost.Base[]; @@ -37,6 +38,8 @@ function getTpName(tp: TGApp.Plugins.Mys.SctPost.Base) { return TpMention; } else if ("villa_card" in tp.insert) { return TpVillaCard; + } else if ("vote" in tp.insert) { + return TpVote; } return TpUnknown; } diff --git a/src/components/post/tp-vote.vue b/src/components/post/tp-vote.vue new file mode 100644 index 00000000..94d444ac --- /dev/null +++ b/src/components/post/tp-vote.vue @@ -0,0 +1,143 @@ + + + diff --git a/src/plugins/Mys/index.ts b/src/plugins/Mys/index.ts index 8ce63c5c..c2305d8f 100644 --- a/src/plugins/Mys/index.ts +++ b/src/plugins/Mys/index.ts @@ -14,6 +14,7 @@ import getLotteryData from "./request/getLotteryData"; import getNewsList from "./request/getNewsList"; import getPositionData from "./request/getPositionData"; import getPostData from "./request/getPostData"; +import { getVoteInfo, getVoteResult } from "./request/getVoteData"; import getGachaCard from "./utils/getGachaCard"; import getLotteryCard from "./utils/getLotteryCard"; import { getActivityCard, getNewsCard, getNoticeCard } from "./utils/getNewsCard"; @@ -58,6 +59,10 @@ const Mys = { getQr: getLoginQr, getData: getLoginStatus, }, + Vote: { + get: getVoteInfo, + result: getVoteResult, + }, }; export default Mys; diff --git a/src/plugins/Mys/request/getVoteData.ts b/src/plugins/Mys/request/getVoteData.ts new file mode 100644 index 00000000..0bb03433 --- /dev/null +++ b/src/plugins/Mys/request/getVoteData.ts @@ -0,0 +1,56 @@ +/** + * @file plugins/Mys/request/getVoteData.ts + * @description Mys 插件投票请求 + * @since Beta v0.3.9 + */ + +import { http } from "@tauri-apps/api"; + +import MysApi from "../api"; + +/** + * @description 获取投票信息 + * @since Beta v0.3.9 + * @param {string} id 投票 ID + * @param {string} uid 用户 ID + * @return {Promise} + */ +export async function getVoteInfo(id: string, uid: string): Promise { + const url = `https://bbs-api.miyoushe.com/apihub/api/getVotes?owner_uid=${uid}&vote_ids=${id}`; + return await http + .fetch(url, { + method: "GET", + headers: { + "Content-Type": "application/json", + Referer: MysApi.Post.Referer, + }, + }) + .then((res) => { + return res.data.data.data[0]; + }); +} + +/** + * @description 获取投票结果 + * @since Beta v0.3.9 + * @param {string} id 投票 ID + * @param {string} uid 用户 ID + * @return {Promise} + */ +export async function getVoteResult( + id: string, + uid: string, +): Promise { + const url = `https://bbs-api.miyoushe.com/apihub/api/getVotesResult?owner_uid=${uid}&vote_ids=${id}`; + return await http + .fetch(url, { + method: "GET", + headers: { + "Content-Type": "application/json", + Referer: MysApi.Post.Referer, + }, + }) + .then((res) => { + return res.data.data.data[0]; + }); +} diff --git a/src/plugins/Mys/types/Vote.d.ts b/src/plugins/Mys/types/Vote.d.ts new file mode 100644 index 00000000..eb730de1 --- /dev/null +++ b/src/plugins/Mys/types/Vote.d.ts @@ -0,0 +1,83 @@ +/** + * @file plugins/Mys/types/Vote.d.ts + * @description Mys 插件投票类型定义文件 + * @since Beta v0.3.9 + */ + +/** + * @description Mys 插件投票类型 + * @since Beta v0.3.9 + * @namespace TGApp.Plugins.Mys.Vote + * @memberof TGApp.Plugins.Mys + */ +declare namespace TGApp.Plugins.Mys.Vote { + /** + * @description 投票信息返回 + * @since Beta v0.3.9 + * @interface InfoResponse + * @extends TGApp.BBS.Response.BaseWithData + * @property {Info[]} data.data 投票信息 + * @return InfoResponse + */ + interface InfoResponse extends TGApp.BBS.Response.BaseWithData { + data: { + data: Info[]; + }; + } + + /** + * @description 投票结果返回 + * @since Beta v0.3.9 + * @interface ResultResponse + * @extends TGApp.BBS.Response.BaseWithData + * @property {Result[]} data.data 投票结果 + * @return ResultResponse + */ + interface ResultResponse extends TGApp.BBS.Response.BaseWithData { + data: { + data: Result[]; + }; + } + + /** + * @description 投票信息 + * @since Beta v0.3.9 + * @interface Info + * @property {string} vote_id 投票 ID + * @property {string} uid 用户 ID + * @property {number} vote_limit 投票限制 + * @property {number} end_time 投票结束时间(秒级时间戳) + * @property {string} title 投票标题 + * @property {string[]} vote_option_indexes 投票选项索引 + * @property {string} created_at 投票创建时间(秒级时间戳) + * @return Info + */ + interface Info { + vote_id: string; + uid: string; + vote_limit: number; + end_time: number; + title: string; + vote_option_indexes: string[]; + created_at: string; + } + + /** + * @description 投票结果 + * @since Beta v0.3.9 + * @interface Result + * @property {string} vote_id 投票 ID + * @property {boolean} is_over 是否已结束 + * @property {Record} option_stats 投票选项统计 + * @property {number} user_cnt 投票人数 + * @property {unknown[]} vote_option_indexes 投票选项索引 + * @return Result + */ + interface Result { + vote_id: string; + is_over: boolean; + option_stats: Record; + user_cnt: number; + vote_option_indexes: unknown[]; + } +}