mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-21 04:49:46 +08:00
🚸 防抖
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
label="服务器"
|
||||
width="200px"
|
||||
density="compact"
|
||||
:disabled="isReq"
|
||||
/>
|
||||
<v-select
|
||||
class="anno-select"
|
||||
@@ -26,6 +27,7 @@
|
||||
label="语言"
|
||||
width="200px"
|
||||
density="compact"
|
||||
:disabled="isReq"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -93,6 +95,7 @@ const router = useRouter();
|
||||
const tabValues: Readonly<Array<AnnoKey>> = ["activity", "game"];
|
||||
const tab = ref<AnnoKey>("activity");
|
||||
const annoCards = shallowRef<AnnoCard>({ activity: [], game: [] });
|
||||
const isReq = ref<boolean>(false);
|
||||
|
||||
watch(
|
||||
() => server.value,
|
||||
@@ -120,6 +123,8 @@ onMounted(async () => {
|
||||
});
|
||||
|
||||
async function loadData(): Promise<void> {
|
||||
if (isReq.value) return;
|
||||
isReq.value = true;
|
||||
await showLoading.start(
|
||||
"正在获取公告数据",
|
||||
`服务器:${getRegionName(server.value)},语言:${getLangName(lang.value)}`,
|
||||
@@ -139,6 +144,7 @@ async function loadData(): Promise<void> {
|
||||
game: listCards.filter((item) => item.typeLabel === AnnoType.game),
|
||||
};
|
||||
await showLoading.end();
|
||||
isReq.value = false;
|
||||
}
|
||||
|
||||
function getRegionName(value: AnnoServer): string {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
item-value="gid"
|
||||
variant="outlined"
|
||||
label="分区"
|
||||
:disabled="isReq"
|
||||
>
|
||||
<template #selection="{ item }">
|
||||
<div class="select-item main">
|
||||
@@ -52,6 +53,7 @@
|
||||
:items="getGameForums(curGid)"
|
||||
variant="outlined"
|
||||
label="版块"
|
||||
:disabled="isReq"
|
||||
>
|
||||
<template #selection="{ item }">
|
||||
<div class="select-item main">
|
||||
@@ -86,6 +88,7 @@
|
||||
item-value="value"
|
||||
variant="outlined"
|
||||
label="排序"
|
||||
:disabled="isReq"
|
||||
/>
|
||||
<v-text-field
|
||||
v-model="search"
|
||||
@@ -152,7 +155,8 @@ const curSortType = ref<number>(1);
|
||||
const search = ref<string>("");
|
||||
const showSearch = ref<boolean>(false);
|
||||
const firstLoad = ref<boolean>(false);
|
||||
const selectedForum = ref<SortSelect>();
|
||||
const isReq = ref<boolean>(false);
|
||||
const selectedForum = shallowRef<SortSelect>();
|
||||
const sortGameList = shallowRef<Array<SortSelectGame>>([]);
|
||||
const postRaw = shallowRef<PostRaw>({ isLast: false, lastId: "", total: 0 });
|
||||
const posts = shallowRef<Array<TGApp.Plugins.Mys.Post.FullData>>([]);
|
||||
@@ -271,12 +275,13 @@ async function getCurrentPosts(
|
||||
}
|
||||
|
||||
async function freshPostData(): Promise<void> {
|
||||
if (!selectedForum.value) return;
|
||||
if (!selectedForum.value || isReq.value) return;
|
||||
await router.push({
|
||||
name: "酒馆",
|
||||
params: route.params,
|
||||
query: { gid: curGid.value, forum: selectedForum.value.value },
|
||||
});
|
||||
isReq.value = true;
|
||||
await showLoading.start(`正在刷新${getGameLabel(curGid.value)}帖子`);
|
||||
const gameLabel = getGameLabel(curGid.value);
|
||||
const forumLabel = getForum(curGid.value, selectedForum.value.value).text;
|
||||
@@ -295,6 +300,7 @@ async function freshPostData(): Promise<void> {
|
||||
};
|
||||
showSnackbar.success(`刷新成功,共加载 ${postsGet.list.length} 条帖子`);
|
||||
await showLoading.end();
|
||||
isReq.value = false;
|
||||
}
|
||||
|
||||
async function loadMore(): Promise<void> {
|
||||
@@ -306,6 +312,8 @@ async function loadMore(): Promise<void> {
|
||||
showSnackbar.warn("没有更多帖子了");
|
||||
return;
|
||||
}
|
||||
if (isReq.value) return;
|
||||
isReq.value = true;
|
||||
await showLoading.start("正在加载更多帖子数据", `游戏:${getGameLabel(curGid.value)}`);
|
||||
const postsGet = await getCurrentPosts(true, selectedForum.value.value);
|
||||
await showLoading.update(
|
||||
@@ -319,6 +327,7 @@ async function loadMore(): Promise<void> {
|
||||
};
|
||||
showSnackbar.success(`加载成功,共加载 ${postsGet.list.length} 条帖子`);
|
||||
await showLoading.end();
|
||||
isReq.value = false;
|
||||
}
|
||||
|
||||
function searchPost(): void {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
:item-value="(item) => item"
|
||||
variant="outlined"
|
||||
label="分区"
|
||||
:disabled="isReq"
|
||||
>
|
||||
<template #selection="{ item }">
|
||||
<div class="select-item main">
|
||||
@@ -55,6 +56,7 @@
|
||||
item-value="value"
|
||||
variant="outlined"
|
||||
label="排序"
|
||||
:disabled="isReq"
|
||||
/>
|
||||
<v-text-field
|
||||
v-model="search"
|
||||
@@ -109,6 +111,7 @@ const curGid = ref<number>(0);
|
||||
const curSortType = ref<0 | 1 | 2>(0);
|
||||
const search = ref<string>("");
|
||||
const curTopic = ref<string>("");
|
||||
const isReq = ref<boolean>(false);
|
||||
const allGames = shallowRef<Array<TGApp.BBS.Game.Item>>([]);
|
||||
const postRaw = shallowRef<PostMiniData>({ isLast: false, lastId: "", total: 0 });
|
||||
const topicInfo = shallowRef<TGApp.BBS.Topic.InfoRes>();
|
||||
@@ -169,6 +172,8 @@ watch(
|
||||
);
|
||||
|
||||
async function firstLoad(): Promise<void> {
|
||||
if (isReq.value) return;
|
||||
isReq.value = true;
|
||||
await showLoading.start(`正在加载话题${topicInfo.value?.topic.name}信息`);
|
||||
await router.push({
|
||||
name: "话题",
|
||||
@@ -190,10 +195,13 @@ async function firstLoad(): Promise<void> {
|
||||
};
|
||||
posts.value = postList.posts;
|
||||
await showLoading.end();
|
||||
isReq.value = false;
|
||||
showSnackbar.success(`加载了 ${postList.posts.length} 条帖子`);
|
||||
}
|
||||
|
||||
async function freshPostData(): Promise<void> {
|
||||
if (isReq.value) return;
|
||||
isReq.value = true;
|
||||
if (postRaw.value.isLast) {
|
||||
showSnackbar.warn("已经到底了");
|
||||
return;
|
||||
@@ -201,27 +209,29 @@ async function freshPostData(): Promise<void> {
|
||||
await showLoading.start(`正在刷新${topicInfo.value?.topic.name}帖子列表`);
|
||||
const mod20 = postRaw.value.total % 20;
|
||||
const pageSize = mod20 === 0 ? 20 : 20 - mod20;
|
||||
const postList = await postReq.topic(
|
||||
const resp = await postReq.topic(
|
||||
curGid.value,
|
||||
curTopic.value,
|
||||
curSortType.value,
|
||||
postRaw.value.lastId,
|
||||
pageSize,
|
||||
);
|
||||
if ("retcode" in postList) {
|
||||
if ("retcode" in resp) {
|
||||
await showLoading.end();
|
||||
showSnackbar.error(`[${postList.retcode}] ${postList.message}`);
|
||||
isReq.value = false;
|
||||
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
|
||||
return;
|
||||
}
|
||||
await showLoading.update(`数量:${postList.posts.length},是否最后一页:${postList.is_last}`);
|
||||
await showLoading.update(`数量:${resp.posts.length},是否最后一页:${resp.is_last}`);
|
||||
postRaw.value = {
|
||||
isLast: postList.is_last,
|
||||
lastId: postList.last_id,
|
||||
total: postRaw.value.total + postList.posts.length,
|
||||
isLast: resp.is_last,
|
||||
lastId: resp.last_id,
|
||||
total: postRaw.value.total + resp.posts.length,
|
||||
};
|
||||
posts.value = posts.value.concat(postList.posts);
|
||||
posts.value = posts.value.concat(resp.posts);
|
||||
await showLoading.end();
|
||||
showSnackbar.success(`加载了 ${postList.posts.length} 条帖子`);
|
||||
isReq.value = false;
|
||||
showSnackbar.success(`加载了 ${resp.posts.length} 条帖子`);
|
||||
}
|
||||
|
||||
function searchPost(): void {
|
||||
|
||||
Reference in New Issue
Block a user