♻️ 重构部分请求

This commit is contained in:
目棃
2025-03-01 14:26:59 +08:00
parent 7d0e0f187c
commit d0936a0a60
35 changed files with 540 additions and 854 deletions

View File

@@ -77,7 +77,21 @@ import { createPost } from "@/utils/TGWindow.js";
type TPostCardProps = { modelValue: TGApp.Plugins.Mys.Post.FullData; selectMode?: boolean };
type TPostCardEmits = (e: "onSelected", v: string) => void;
type TPostStatus = TGApp.Plugins.Mys.News.RenderStatus & { stat: ActStat };
type TPostStatus = RenderStatus & { stat: ActStat };
type RenderForum = { name: string; icon: string; id: number };
type RenderStatus = { stat: number; label: string; color: string };
type RenderData = { mark: number; forward: number; like: number; reply: number; view: number };
export type RenderCard = {
title: string;
cover: string;
postId: number;
subtitle: string;
user: TGApp.Plugins.Mys.User.Post | null;
forum: RenderForum | null;
data: RenderData | null;
status?: RenderStatus;
topics: Array<TGApp.BBS.Topic.Info>;
};
enum ActStat {
UNKNOWN,
@@ -94,7 +108,7 @@ const stats: Readonly<Array<TPostStatus>> = [
];
const props = withDefaults(defineProps<TPostCardProps>(), { selectMode: false });
const emits = defineEmits<TPostCardEmits>();
const card = shallowRef<TGApp.Plugins.Mys.News.RenderCard>();
const card = shallowRef<RenderCard>();
const cardBg = computed<string>(() => {
if (card.value && card.value.status) return card.value.status.color;
@@ -108,7 +122,7 @@ watch(
async () => (card.value = getPostCard(props.modelValue)),
);
function getActivityStatus(status: number): TGApp.Plugins.Mys.News.RenderStatus {
function getActivityStatus(status: number): RenderStatus {
if (status satisfies ActStat) {
const stat: ActStat = status;
return stats[stat];
@@ -126,15 +140,9 @@ function getPostCover(item: TGApp.Plugins.Mys.Post.FullData): string {
return `${cover}?x-oss-process=image/resize,m_fill,w_360,h_130,limit_0/format,png`;
}
/**
* @description 获取公共属性
* @since Beta v0.6.1
* @param {TGApp.Plugins.Mys.Post.FullData} item 咨讯列表项
* @returns {TGApp.Plugins.Mys.News.RenderCard} 渲染用咨讯列表项
*/
function getCommonCard(item: TGApp.Plugins.Mys.Post.FullData): TGApp.Plugins.Mys.News.RenderCard {
let forumData: TGApp.Plugins.Mys.News.RenderForum | null = null;
let statData: TGApp.Plugins.Mys.News.RenderData | null = null;
function getCommonCard(item: TGApp.Plugins.Mys.Post.FullData): RenderCard {
let forumData: RenderForum | null = null;
let statData: RenderData | null = null;
if (item.forum !== null) {
forumData = { name: item.forum.name, icon: item.forum.icon, id: item.forum.id };
}
@@ -159,7 +167,7 @@ function getCommonCard(item: TGApp.Plugins.Mys.Post.FullData): TGApp.Plugins.Mys
};
}
function getPostCard(item: TGApp.Plugins.Mys.Post.FullData): TGApp.Plugins.Mys.News.RenderCard {
function getPostCard(item: TGApp.Plugins.Mys.Post.FullData): RenderCard {
const commonCard = getCommonCard(item);
if (
item.news_meta !== undefined &&
@@ -186,12 +194,12 @@ async function shareCard(): Promise<void> {
await generateShareImg(fileName, shareDom, 2.5);
}
async function toTopic(topic: TGApp.Plugins.Mys.Topic.Info): Promise<void> {
async function toTopic(topic: TGApp.BBS.Topic.Info): Promise<void> {
const gid = props.modelValue.post.game_id;
await emit("active_deep_link", `router?path=/posts/topic/${gid}/${topic.id}`);
}
async function toForum(forum: TGApp.Plugins.Mys.News.RenderForum): Promise<void> {
async function toForum(forum: RenderForum): Promise<void> {
const gid = props.modelValue.post.game_id;
await emit("active_deep_link", `router?path=/posts/forum/${gid}/${forum.id}`);
}

View File

@@ -31,14 +31,14 @@
</template>
<script lang="ts" setup>
import showSnackbar from "@comp/func/snackbar.js";
import { getRecentForumPostList } from "@Mys/request/painterReq.js";
import { getPostFull } from "@Mys/request/postReq.js";
import { storeToRefs } from "pinia";
import { ref, shallowRef } from "vue";
import { useUserStore } from "@/store/modules/user.js";
import TGLogger from "@/utils/TGLogger.js";
import apiHubReq from "@/web/request/apiHubReq.js";
import painterReq from "@/web/request/painterReq.js";
import postReq from "@/web/request/postReq.js";
type ParseMission = {
id: number;
@@ -164,7 +164,7 @@ async function tryAuto(): Promise<void> {
const viewFind = postFilter.find((i) => i.key === "view_post_0");
if (viewFind) viewCnt = viewFind.process;
await TGLogger.Script("[米游币任务]获取帖子列表");
const listResp = await getRecentForumPostList(26, 2, 2, undefined, 20);
const listResp = await painterReq.forum.recent(26, 2, 2, undefined, 20);
for (const post of listResp.list) {
if (!isShare) {
await TGLogger.Script(`[米游币任务]正在分享帖子${post.post.post_id}`);
@@ -178,7 +178,7 @@ async function tryAuto(): Promise<void> {
}
if (likeCnt < 5 || viewCnt < 3) {
await TGLogger.Script(`[米游币任务]正在浏览帖子${post.post.post_id}`);
const detailResp = await getPostFull(Number(post.post.post_id), ckPost);
const detailResp = await postReq.post(post.post.post_id, ckPost);
if ("retcode" in detailResp) {
await TGLogger.Script(
`[米游币任务]获取帖子${post.post.post_id}失败:${detailResp.retcode} ${detailResp.message}`,

View File

@@ -62,7 +62,6 @@
</template>
<script lang="ts" setup>
import showSnackbar from "@comp/func/snackbar.js";
import Mys from "@Mys/index.js";
import { storeToRefs } from "pinia";
import { computed, ref, shallowRef, watch } from "vue";
@@ -70,6 +69,7 @@ import VpReplyDebug from "./vp-reply-debug.vue";
import VpReplyItem from "./vp-reply-item.vue";
import { useAppStore } from "@/store/modules/app.js";
import postReq from "@/web/request/postReq.js";
type TprMainProps = { gid: number; postId: string };
type SelectItem = { label: string; value: string };
@@ -90,7 +90,7 @@ const showOverlay = ref<boolean>(false);
const showDebug = ref<boolean>(false);
const onlyLz = ref<boolean>(false);
const orderType = ref<"hot" | "latest" | "oldest">("hot");
const reply = shallowRef<Array<TGApp.Plugins.Mys.Reply.ReplyFull>>([]);
const reply = shallowRef<Array<TGApp.BBS.Reply.ReplyFull>>([]);
const isHot = computed<boolean>(() => orderType.value === "hot");
const replyOrder = computed<1 | 2 | undefined>(() => {
if (orderType.value === "hot") return undefined;
@@ -121,7 +121,7 @@ async function reloadReply(): Promise<void> {
async function loadReply(): Promise<void> {
loading.value = true;
const resp = await Mys.Post.getPostReplies(
const resp = await postReq.reply.main(
props.postId,
props.gid,
isHot.value,

View File

@@ -48,11 +48,11 @@
<script lang="ts" setup>
import TOverlay from "@comp/app/t-overlay.vue";
import showSnackbar from "@comp/func/snackbar.js";
import Mys from "@Mys/index.js";
import { nextTick, onMounted, shallowRef, useTemplateRef, watch } from "vue";
import { useRouter } from "vue-router";
import { timestampToDate } from "@/utils/toolFunc.js";
import postReq from "@/web/request/postReq.js";
type TpoCollectionProps = { collection: TGApp.Plugins.Mys.Post.Collection };
type TpoCollectionItem = {
@@ -86,7 +86,7 @@ watch(
);
onMounted(async () => {
const collectionPosts = await Mys.Post.getPostFullInCollection(props.collection.collection_id);
const collectionPosts = await postReq.collection(props.collection.collection_id);
const tempArr: Array<TpoCollectionItem> = [];
for (const postItem of collectionPosts) {
const post: TpoCollectionItem = {
@@ -107,7 +107,7 @@ async function toPost(postId: string, index: number): Promise<void> {
showSnackbar.warn("已经在当前帖子");
return;
}
await router.push({ name: "帖子详情", params: { post_id: postId } });
router.push({ name: "帖子详情", params: { post_id: postId } });
}
</script>
<style lang="css" scoped>

View File

@@ -44,17 +44,32 @@
<script setup lang="ts">
import TOverlay from "@comp/app/t-overlay.vue";
import showSnackbar from "@comp/func/snackbar.js";
import Mys from "@Mys/index.js";
import { onUnmounted, ref, shallowRef, watch } from "vue";
import painterReq from "@/web/request/painterReq.js";
type TpoLotteryProps = { lottery: string | undefined };
type RenderCard = {
id: string;
upWay: string;
status: string;
creator: TGApp.Plugins.Mys.User.Post;
drawTime: string;
rewards: Array<RenderReward>;
};
type RenderReward = {
name: string;
win: number;
goal: number;
users: TGApp.Plugins.Mys.User.Post[];
};
const props = defineProps<TpoLotteryProps>();
const visible = defineModel<boolean>();
const timeStatus = ref<string>("未知");
const upWay = ref<string>("未知");
const card = shallowRef<TGApp.Plugins.Mys.Lottery.RenderCard>();
const jsonData = shallowRef<TGApp.Plugins.Mys.Lottery.FullData>();
const card = shallowRef<RenderCard>();
const jsonData = shallowRef<TGApp.BBS.Lottery.FullData>();
// eslint-disable-next-line no-undef
let timer: NodeJS.Timeout | undefined = undefined;
@@ -68,7 +83,7 @@ watch(
async function load(): Promise<void> {
if (!props.lottery) return;
if (card.value) return;
const cardGet = await Mys.Lottery.get(props.lottery);
const cardGet = await painterReq.lottery(props.lottery);
if ("retcode" in cardGet) {
showSnackbar.error(`[${cardGet.retcode}] ${cardGet.message}`);
return;
@@ -82,7 +97,7 @@ async function load(): Promise<void> {
}
timer = setInterval(flushTimeStatus, 1000);
}
card.value = Mys.Lottery.card(cardGet);
card.value = transLotteryCard(cardGet);
upWay.value = getUpWay(card.value?.upWay);
}
@@ -114,6 +129,26 @@ function flushTimeStatus(): void {
}
}
function transLotteryReward(lotteryReward: TGApp.BBS.Lottery.Reward): RenderReward {
return {
name: lotteryReward.reward_name,
win: lotteryReward.winner_number,
goal: lotteryReward.scheduled_winner_number,
users: lotteryReward.users,
};
}
function transLotteryCard(lotteryData: TGApp.BBS.Lottery.FullData): RenderCard {
return {
id: lotteryData.id,
upWay: lotteryData.participant_way,
status: lotteryData.status,
creator: lotteryData.creator,
drawTime: lotteryData.draw_time,
rewards: lotteryData.user_rewards.map(transLotteryReward),
};
}
onUnmounted(() => {
if (timer !== undefined) {
clearInterval(timer);

View File

@@ -24,10 +24,10 @@
import TOverlay from "@comp/app/t-overlay.vue";
import TPostCard from "@comp/app/t-postcard.vue";
import showSnackbar from "@comp/func/snackbar.js";
import Mys from "@Mys/index.js";
import { computed, onMounted, ref, shallowRef, watch } from "vue";
import TGBbs from "@/utils/TGBbs.js";
import postReq from "@/web/request/postReq.js";
type ToPostSearchProps = { gid: string; keyword?: string };
@@ -106,7 +106,7 @@ async function searchPosts(): Promise<void> {
load.value = false;
return;
}
const res = await Mys.Post.searchPosts(game.value, search.value, lastId.value);
const res = await postReq.search(game.value, search.value, lastId.value);
if (lastId.value === "") results.value = res.posts;
else results.value = results.value.concat(res.posts);
lastId.value = res.last_id;

View File

@@ -25,7 +25,7 @@ import TGLogger from "@/utils/TGLogger.js";
const visible = defineModel<boolean>();
const filePath = ref<string>("");
const replyData = shallowRef<TGApp.Plugins.Mys.Reply.ReplyFull | null>(null);
const replyData = shallowRef<TGApp.BBS.Reply.ReplyFull | null>(null);
async function selectFile(): Promise<void> {
const file = await open({

View File

@@ -103,7 +103,6 @@
<script lang="ts" setup>
import showDialog from "@comp/func/dialog.js";
import showSnackbar from "@comp/func/snackbar.js";
import Mys from "@Mys/index.js";
import { event, path } from "@tauri-apps/api";
import type { Event, UnlistenFn } from "@tauri-apps/api/event";
import { save } from "@tauri-apps/plugin-dialog";
@@ -114,10 +113,11 @@ import TpParser from "./tp-parser.vue";
import { generateShareImg } from "@/utils/TGShare.js";
import { timestampToDate } from "@/utils/toolFunc.js";
import postReq from "@/web/request/postReq.js";
type TprReplyProps =
| { mode: "sub"; modelValue: TGApp.Plugins.Mys.Reply.ReplyFull }
| { mode: "main"; modelValue: TGApp.Plugins.Mys.Reply.ReplyFull; pinId: string };
| { mode: "sub"; modelValue: TGApp.BBS.Reply.ReplyFull }
| { mode: "main"; modelValue: TGApp.BBS.Reply.ReplyFull; pinId: string };
const props = defineProps<TprReplyProps>();
const replyId = `reply_${props.modelValue.reply.post_id}_${props.modelValue.reply.floor_id}_${props.modelValue.reply.reply_id}`;
@@ -129,7 +129,7 @@ const showSub = ref<boolean>(false);
const lastId = ref<string>();
const isLast = ref<boolean>(false);
const loading = ref<boolean>(false);
const subReplies = shallowRef<Array<TGApp.Plugins.Mys.Reply.ReplyFull>>([]);
const subReplies = shallowRef<Array<TGApp.BBS.Reply.ReplyFull>>([]);
const levelColor = computed<string>(() => {
const level = props.modelValue.user.level_exp.level;
if (level < 5) return "var(--tgc-od-green)";
@@ -189,7 +189,7 @@ async function showReply(): Promise<void> {
async function loadSub(): Promise<void> {
loading.value = true;
const resp = await Mys.Post.getSubReplies(
const resp = await postReq.reply.sub(
props.modelValue.reply.floor_id,
props.modelValue.reply.game_id,
props.modelValue.reply.post_id,