♻️ 重构部分请求

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

@@ -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,