Skip to content

Commit

Permalink
♻️ 请求重构,合并postWapi跟apiHub相关请求
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Oct 24, 2024
1 parent 41db04b commit 2604194
Show file tree
Hide file tree
Showing 31 changed files with 399 additions and 594 deletions.
4 changes: 2 additions & 2 deletions src/components/home/t-pool.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ interface TPoolEmits {
const emits = defineEmits<TPoolEmits>();
function poolLastInterval(postId: number): TGApp.Plugins.Mys.Gacha.RenderCard {
function poolLastInterval(postId: number): TGApp.Plugins.Mys.Gacha.RenderCard | undefined {
const pool = poolCards.value.find((pool) => pool.postId === postId);
if (!pool) return;
if (poolTimeGet.value[postId] === "未开始") {
Expand Down Expand Up @@ -162,7 +162,7 @@ function checkCover(data: TGApp.Plugins.Mys.Gacha.Data[]): boolean {
return false;
}
const cover = homeStore.poolCover;
if (cover === undefined) return false;
if (cover.value === undefined) return false;
let checkList = data.length;
Object.entries(cover).forEach(([key, value]: [string, unknown]) => {
const pool = data.find((item: TGApp.Plugins.Mys.Gacha.Data) => item.id.toString() === key);
Expand Down
2 changes: 1 addition & 1 deletion src/components/main/t-gamenav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ watch(
);
async function loadNav(): Promise<void> {
nav.value = await Mys.Posts.nav(props.modelValue);
nav.value = await Mys.ApiHub.homeNew(props.modelValue);
}
async function tryGetCode(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/components/post/to-postSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async function searchPosts() {
load.value = false;
return;
}
const res = await Mys.Posts.search(game.value, search.value, lastId.value);
const res = await Mys.Post.searchPosts(game.value, search.value, lastId.value);
if (lastId.value === "") {
results.value = res.posts;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/components/post/tp-vote.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ const votes = ref<TpVoteInfo>();
onMounted(async () => {
const vote = props.data.insert.vote;
const voteInfo = await Mys.Vote.get(vote.id, vote.uid);
const voteResult = await Mys.Vote.result(vote.id, vote.uid);
const voteInfo = await Mys.ApiHub.getVotes(vote.id, vote.uid);
const voteResult = await Mys.ApiHub.getVoteResult(vote.id, vote.uid);
votes.value = {
title: voteInfo.title,
count: voteResult.user_cnt,
Expand Down
2 changes: 1 addition & 1 deletion src/components/post/tpo-collection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ watch(
);
onMounted(async () => {
const collectionPosts = await Mys.PostCollect(props.collection.collection_id);
const collectionPosts = await Mys.Post.getPostFullInCollection(props.collection.collection_id);
const tempArr: TpoCollectionItem[] = [];
for (const postItem of collectionPosts) {
const post: TpoCollectionItem = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/postReply/tpr-main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async function reloadReply(): Promise<void> {
async function loadReply(): Promise<void> {
loading.value = true;
const resp = await Mys.Post.reply(
const resp = await Mys.Post.getPostReplies(
props.postId,
props.gid,
isHot.value,
Expand Down
14 changes: 3 additions & 11 deletions src/components/postReply/tpr-reply.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,30 +207,22 @@ async function showReply(): Promise<void> {
async function loadSub(): Promise<void> {
loading.value = true;
const resp = await Mys.Post.replySub(
const resp = await Mys.Post.getSubReplies(
props.modelValue.reply.floor_id,
props.modelValue.reply.game_id,
props.modelValue.reply.post_id,
lastId.value,
);
if ("retcode" in resp) {
showSnackbar({
text: `[${resp.retcode}] ${resp.message}`,
color: "error",
});
showSnackbar({ text: `[${resp.retcode}] ${resp.message}`, color: "error" });
loading.value = false;
return;
}
isLast.value = resp.is_last;
lastId.value = resp.last_id;
subReplies.value = subReplies.value.concat(resp.list);
loading.value = false;
if (isLast.value) {
showSnackbar({
text: "没有更多了",
color: "info",
});
}
if (isLast.value) showSnackbar({ text: "没有更多了", color: "info" });
}
async function exportData(): Promise<void> {
Expand Down
50 changes: 15 additions & 35 deletions src/components/wiki/twc-character.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
v-for="(item, index) in data?.talks"
:key="index"
>
<template #title
><span class="twc-text-item-title">{{ item.Title }}</span></template
>
<template #title>
<span class="twc-text-item-title">{{ item.Title }}</span>
</template>
<template #text>
<span class="twc-text-item-content" v-html="parseHtmlText(item.Context)" />
</template>
Expand All @@ -82,12 +82,12 @@
v-for="(item, index) in data.stories"
:key="index"
>
<template #title
><span class="twc-text-item-title">{{ item.Title }}</span></template
>
<template #text
><span class="twc-text-item-content">{{ item.Context }}</span></template
>
<template #title>
<span class="twc-text-item-title">{{ item.Title }}</span>
</template>
<template #text>
<span class="twc-text-item-content">{{ item.Context }}</span>
</template>
</v-expansion-panel>
</v-expansion-panels>
</template>
Expand All @@ -101,8 +101,7 @@ import { computed, onMounted, ref, watch } from "vue";
import { useRouter } from "vue-router";
import { WikiCharacterData, AppNameCardsData, AppCharacterData } from "../../data/index.js";
import Mys from "../../plugins/Mys/index.js";
import { createTGWindow } from "../../utils/TGWindow.js";
import { createObc } from "../../utils/TGWindow.js";
import { parseHtmlText } from "../../utils/toolFunc.js";
import showSnackbar from "../func/snackbar.js";
import TItembox, { TItemBoxData } from "../main/t-itembox.vue";
Expand Down Expand Up @@ -143,10 +142,7 @@ const nameCard = ref<TGApp.App.NameCard.Item>();
async function loadData(): Promise<void> {
const res = WikiCharacterData.find((item) => item.id === props.item.id);
if (res === undefined) {
showSnackbar({
text: `未获取到角色 ${props.item.name} 的 Wiki 数据`,
color: "error",
});
showSnackbar({ text: `未获取到角色 ${props.item.name} 的 Wiki 数据`, color: "error" });
return;
}
data.value = res;
Expand All @@ -157,38 +153,22 @@ async function loadData(): Promise<void> {
} else {
hasNc.value = false;
}
showSnackbar({
text: `成功获取角色 ${props.item.name} 的 Wiki 数据`,
color: "success",
});
showSnackbar({ text: `成功获取角色 ${props.item.name} 的 Wiki 数据` });
}
watch(
() => props.item,
async () => {
await loadData();
},
async () => await loadData(),
);
onMounted(async () => await loadData());
async function toWiki(): Promise<void> {
if (props.item.contentId === 0) {
showSnackbar({
text: `角色 ${props.item.name} 暂无详情`,
color: "warn",
});
showSnackbar({ text: `角色 ${props.item.name} 暂无详情`, color: "warn" });
return;
}
const url = Mys.Api.Obc.replace("{contentId}", props.item.contentId.toString());
await createTGWindow(
url,
"Sub_window",
`Content_${props.item.contentId} ${props.item.name}`,
1200,
800,
true,
);
await createObc(props.item.contentId, props.item.name);
}
async function toBirth(date: string): Promise<void> {
Expand Down
28 changes: 5 additions & 23 deletions src/components/wiki/twc-weapon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@
import { computed, onMounted, ref, watch } from "vue";
import { WikiWeaponData } from "../../data/index.js";
import Mys from "../../plugins/Mys/index.js";
import { createTGWindow } from "../../utils/TGWindow.js";
import { createObc } from "../../utils/TGWindow.js";
import { parseHtmlText } from "../../utils/toolFunc.js";
import showSnackbar from "../func/snackbar.js";
import TItembox, { TItemBoxData } from "../main/t-itembox.vue";
Expand Down Expand Up @@ -88,17 +87,11 @@ const selectItems = ref<number[]>([]);
async function loadData(): Promise<void> {
const res = WikiWeaponData.find((item) => item.id === props.item.id);
if (res === undefined) {
showSnackbar({
text: `未获取到武器 ${props.item.name} 的 Wiki 数据`,
color: "error",
});
showSnackbar({ text: `未获取到武器 ${props.item.name} 的 Wiki 数据`, color: "error" });
return;
}
data.value = res;
showSnackbar({
text: `成功获取武器 ${props.item.name} 的 Wiki 数据`,
color: "success",
});
showSnackbar({ text: `成功获取武器 ${props.item.name} 的 Wiki 数据` });
if (data.value?.affix === undefined) return;
selectItems.value = data.value?.affix.Descriptions.map((item) => item.Level) ?? [];
}
Expand All @@ -112,21 +105,10 @@ onMounted(async () => await loadData());
async function toWiki(): Promise<void> {
if (props.item.contentId === 0) {
showSnackbar({
text: `武器 ${props.item.name} 暂无详情`,
color: "warn",
});
showSnackbar({ text: `武器 ${props.item.name} 暂无详情`, color: "warn" });
return;
}
const url = Mys.Api.Obc.replace("{contentId}", props.item.contentId.toString());
await createTGWindow(
url,
"Sub_window",
`Content_${props.item.contentId} ${props.item.name}`,
1200,
800,
true,
);
await createObc(props.item.contentId, props.item.name);
}
</script>
<style lang="css" scoped>
Expand Down
52 changes: 14 additions & 38 deletions src/pages/WIKI/Character.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import TwcCharacter from "../../components/wiki/twc-character.vue";
import TwcListItem from "../../components/wiki/twc-list-item.vue";
import TwoSelectC, { SelectedCValue } from "../../components/wiki/two-select-c.vue";
import { AppCharacterData } from "../../data/index.js";
import Mys from "../../plugins/Mys/index.js";
import { createTGWindow } from "../../utils/TGWindow.js";
import { createObc } from "../../utils/TGWindow.js";
const id = useRoute().params.id.toString() ?? "0";
const showSelect = ref(false);
Expand All @@ -55,18 +54,15 @@ const curItem = ref<TGApp.App.Character.WikiBriefInfo>({
onBeforeMount(() => {
if (id === "0") {
curItem.value = cardsInfo.value[0];
} else {
const item = cardsInfo.value.find((item) => item.id.toString() === id);
if (item) {
curItem.value = item;
} else {
showSnackbar({
text: `角色 ${id} 不存在`,
color: "warn",
});
curItem.value = cardsInfo.value[0];
}
return;
}
const item = cardsInfo.value.find((item) => item.id.toString() === id);
if (item) {
curItem.value = item;
return;
}
showSnackbar({ text: `角色 ${id} 不存在`, color: "warn" });
curItem.value = cardsInfo.value[0];
});
watch(resetSelect, (val) => {
Expand All @@ -82,16 +78,10 @@ function handleSelect(val: SelectedCValue) {
return val.area.includes(item.area);
});
if (filterC.length === 0) {
showSnackbar({
text: "未找到符合条件的角色",
color: "warn",
});
showSnackbar({ text: "未找到符合条件的角色", color: "warn" });
return;
}
showSnackbar({
text: `筛选出符合条件的角色 ${filterC.length} 个`,
color: "success",
});
showSnackbar({ text: `筛选出符合条件的角色 ${filterC.length} 个` });
cardsInfo.value = filterC;
}
Expand All @@ -106,32 +96,18 @@ async function switchC(item: TGApp.App.Character.WikiBriefInfo): Promise<void> {
async function toOuter(item?: TGApp.App.Character.WikiBriefInfo): Promise<void> {
if (!item) return;
if (item.contentId === 0) {
showSnackbar({
text: `角色 ${item.name} 暂无观测枢页面`,
color: "warn",
});
showSnackbar({ text: `角色 ${item.name} 暂无观测枢页面`, color: "warn" });
return;
}
const confirm = await showConfirm({
title: `角色 ${item.name} 暂无数据`,
text: "是否打开观测枢页面?",
});
if (!confirm) {
showSnackbar({
text: "已取消",
color: "cancel",
});
showSnackbar({ text: "已取消", color: "cancel" });
return;
}
const url = Mys.Api.Obc.replace("{contentId}", item.contentId.toString());
await createTGWindow(
url,
"Sub_window",
`Content_${item.contentId} ${item.name}`,
1200,
800,
true,
);
await createObc(item.contentId, item.name);
}
</script>
<style scoped>
Expand Down
Loading

0 comments on commit 2604194

Please sign in to comment.