♻️ 请求重构,合并postWapi跟apiHub相关请求

This commit is contained in:
目棃
2024-10-24 23:08:34 +08:00
parent 41db04b7a2
commit 26041948ef
31 changed files with 399 additions and 594 deletions

View File

@@ -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);
@@ -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) => {
@@ -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;
}
@@ -106,10 +96,7 @@ 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({
@@ -117,21 +104,10 @@ async function toOuter(item?: TGApp.App.Character.WikiBriefInfo): Promise<void>
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>

View File

@@ -35,8 +35,7 @@ import TwcListItem from "../../components/wiki/twc-list-item.vue";
import TwcWeapon from "../../components/wiki/twc-weapon.vue";
import TwoSelectW, { SelectedWValue } from "../../components/wiki/two-select-w.vue";
import { AppWeaponData } 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);
@@ -55,18 +54,15 @@ const curItem = ref<TGApp.App.Weapon.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];
});
function handleSelectW(val: SelectedWValue) {
@@ -79,15 +75,10 @@ function handleSelectW(val: SelectedWValue) {
return val.weapon.includes(match[1]);
});
if (filterW.length === 0) {
showSnackbar({
text: "未找到符合条件的武器",
color: "warn",
});
showSnackbar({ text: "未找到符合条件的武器", color: "warn" });
return;
}
showSnackbar({
text: `找到 ${filterW.length} 件符合条件的武器`,
});
showSnackbar({ text: `找到 ${filterW.length} 件符合条件的武器` });
cardsInfo.value = filterW;
}
@@ -98,10 +89,7 @@ async function switchW(item: TGApp.App.Weapon.WikiBriefInfo): Promise<void> {
async function toOuter(item?: TGApp.App.Weapon.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({
@@ -109,21 +97,10 @@ async function toOuter(item?: TGApp.App.Weapon.WikiBriefInfo): Promise<void> {
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>

View File

@@ -151,7 +151,7 @@ async function firstLoad(key: NewsKey, refresh: boolean = false): Promise<void>
}
loadingTitle.value = `正在获取${rawData.value[key].name}数据...`;
loading.value = true;
const getData = await Mys.News(gid, NewsType[key]);
const getData = await Mys.Post.getNewsList(gid, NewsType[key]);
rawData.value[key].isLast = getData.is_last;
rawData.value[key].lastId = getData.list.length;
postData.value[key] = getData.list;

View File

@@ -1,6 +1,13 @@
<template>
<ToLoading v-model="loading" :title="loadingTitle" />
<div class="posts-box">
<v-app-bar>
<template #prepend>
<div class="posts-top">
<img src="/source/UI/posts.png" alt="posts" />
<span>帖子</span>
<!-- todo 提供话题入口 -->
</div>
</template>
<div class="posts-switch">
<v-select
v-model="curGid"
@@ -45,11 +52,13 @@
<span>刷新</span>
</v-btn>
</div>
<TGameNav :model-value="curGid" />
<div class="posts-grid">
<div v-for="post in posts" :key="post.post.post_id">
<TPostCard :model-value="post" v-if="post" />
</div>
<template #extension>
<TGameNav :model-value="curGid" />
</template>
</v-app-bar>
<div class="posts-grid">
<div v-for="post in posts" :key="post.post.post_id">
<TPostCard :model-value="post" v-if="post" />
</div>
</div>
<ToPostSearch :gid="curGid.toString()" v-model="showSearch" :keyword="search" />
@@ -212,12 +221,8 @@ const search = ref<string>("");
const showSearch = ref<boolean>(false);
onBeforeMount(async () => {
if (gid && typeof gid === "string") {
curGid.value = Number(gid);
}
if (forum && typeof forum === "string") {
curForum.value = Number(forum);
}
if (gid && typeof gid === "string") curGid.value = Number(gid);
if (forum && typeof forum === "string") curForum.value = Number(forum);
});
onMounted(async () => {
@@ -247,7 +252,6 @@ watch(
});
},
);
watch(
() => curForum.value,
async () => {
@@ -262,8 +266,6 @@ watch(
}
},
);
// 监听排序变化
watch(
() => curSortType.value,
async (newVal) => {
@@ -285,7 +287,7 @@ async function freshPostData(): Promise<void> {
);
loading.value = true;
loadingTitle.value = `正在加载 ${gameLabel}-${forumLabel}-${sortLabel} 数据`;
const postsGet = await Mys.Posts.get(curForum.value, curSortType.value, 12);
const postsGet = await Mys.Post.getForumPostList(curForum.value, curSortType.value, 12);
posts.value = postsGet.list;
await nextTick();
loading.value = false;
@@ -309,22 +311,34 @@ function searchPost(): void {
}
</script>
<style lang="css" scoped>
.posts-box {
.posts-top {
display: flex;
flex-direction: column;
row-gap: 10px;
align-items: center;
justify-content: center;
gap: 10px;
img {
width: 32px;
height: 32px;
}
span {
color: var(--common-text-title);
font-family: var(--font-title);
font-size: 20px;
}
}
.posts-switch {
display: flex;
align-items: flex-end;
justify-content: flex-start;
padding: 5px;
column-gap: 10px;
justify-content: center;
margin: 0 10px;
gap: 10px;
}
.post-switch-item {
width: fit-content;
width: 250px;
height: 50px;
}