diff --git a/src/pages/common/PostForum.vue b/src/pages/common/PostForum.vue
index dc7444e8..6e6c91b9 100644
--- a/src/pages/common/PostForum.vue
+++ b/src/pages/common/PostForum.vue
@@ -61,7 +61,8 @@
- 已加载:{{ posts.length }},加载更多
+ 已加载:{{ posts.length }},
+ {{ postRaw.isLast ? "已加载完毕" : "加载更多" }}
@@ -81,6 +82,7 @@ import { createPost } from "@/utils/TGWindow.js";
type SortSelect = { text: string; value: number };
type SortSelectGame = { gid: number; forum: Array; text: string };
+type PostRaw = { isLast: boolean; lastId: string; total: number };
const sortOrderList: Array = [
{ text: "最新回复", value: 1 },
@@ -147,11 +149,10 @@ const curGid = ref(2);
const curSortType = ref(1);
const curForum = ref(26);
const curForumLabel = ref("");
-const lastId = ref("");
-const isLast = ref(false);
const search = ref("");
const showSearch = ref(false);
const firstLoad = ref(false);
+const postRaw = shallowRef({ isLast: false, lastId: "", total: 0 });
const posts = shallowRef>([]);
onMounted(async () => {
@@ -221,9 +222,16 @@ function getSortLabel(value: number): string {
async function getCurrentPosts(
loadMore: boolean = false,
): Promise {
+ const mod20 = postRaw.value.total % 20;
+ const pageSize = mod20 === 0 ? 20 : 20 - mod20;
if (curSortType.value === 3) {
if (loadMore) {
- return await Mys.Painter.getHotForumPostList(curForum.value, curGid.value, lastId.value);
+ return await Mys.Painter.getHotForumPostList(
+ curForum.value,
+ curGid.value,
+ postRaw.value.lastId,
+ pageSize,
+ );
}
return await Mys.Painter.getHotForumPostList(curForum.value, curGid.value);
}
@@ -232,7 +240,8 @@ async function getCurrentPosts(
curForum.value,
curGid.value,
curSortType.value,
- lastId.value,
+ postRaw.value.lastId,
+ pageSize,
);
}
return await Mys.Painter.getRecentForumPostList(curForum.value, curGid.value, curSortType.value);
@@ -250,14 +259,17 @@ async function freshPostData(): Promise {
document.documentElement.scrollTo({ top: 0, behavior: "smooth" });
const postsGet = await getCurrentPosts();
posts.value = postsGet.list;
- lastId.value = postsGet.last_id;
- isLast.value = postsGet.is_last;
+ postRaw.value = {
+ isLast: postsGet.is_last,
+ lastId: postsGet.last_id,
+ total: postsGet.list.length,
+ };
showSnackbar.success(`刷新成功,共加载 ${postsGet.list.length} 条帖子`);
await showLoading.end();
}
async function loadMore(): Promise {
- if (isLast.value) {
+ if (postRaw.value.isLast) {
showSnackbar.warn("没有更多帖子了");
return;
}
@@ -267,8 +279,11 @@ async function loadMore(): Promise {
`版块:${curForumLabel.value},排序:${getSortLabel(curSortType.value)},数量:${postsGet.list.length}`,
);
posts.value = posts.value.concat(postsGet.list);
- lastId.value = postsGet.last_id;
- isLast.value = postsGet.is_last;
+ postRaw.value = {
+ isLast: postsGet.is_last,
+ lastId: postsGet.last_id,
+ total: postRaw.value.total + postsGet.list.length,
+ };
showSnackbar.success(`加载成功,共加载 ${postsGet.list.length} 条帖子`);
await showLoading.end();
}
diff --git a/src/pages/common/PostNews.vue b/src/pages/common/PostNews.vue
index 952f2904..793d4e48 100644
--- a/src/pages/common/PostNews.vue
+++ b/src/pages/common/PostNews.vue
@@ -46,7 +46,8 @@
- 已加载:{{ rawData[value].lastId }},加载更多
+ 已加载:{{ rawData[value].lastId }},
+ {{ rawData[value].isLast ? "已加载完毕" : "加载更多" }}
@@ -62,7 +63,8 @@ import ToChannel from "@comp/pageNews/to-channel.vue";
import VpOverlaySearch from "@comp/viewPost/vp-overlay-search.vue";
import Mys from "@Mys/index.js";
import { storeToRefs } from "pinia";
-import { computed, onMounted, ref, shallowRef, triggerRef } from "vue";
+import type { Ref } from "vue";
+import { computed, onMounted, reactive, ref, shallowRef } from "vue";
import { useRoute, useRouter } from "vue-router";
import { type NewsType, NewsTypeEnum, useAppStore } from "@/store/modules/app.js";
@@ -70,8 +72,9 @@ import TGLogger from "@/utils/TGLogger.js";
import { createPost } from "@/utils/TGWindow.js";
import { getGameName } from "@/utils/toolFunc.js";
-type PostData = { [key in NewsType]: Array };
-type RawData = { [key in NewsType]: { isLast: boolean; name: string; lastId: number } };
+type PostData = { [key in NewsType]: Ref> };
+type RawItem = { isLast: boolean; name: string; lastId: number };
+type RawData = { [key in NewsType]: Ref };
const router = useRouter();
const { recentNewsType } = storeToRefs(useAppStore());
@@ -82,11 +85,15 @@ const loading = ref(false);
const showList = ref(false);
const showSearch = ref(false);
const search = ref("");
-const postData = shallowRef({ notice: [], activity: [], news: [] });
-const rawData = shallowRef({
- notice: { isLast: false, name: "公告", lastId: 0 },
- activity: { isLast: false, name: "活动", lastId: 0 },
- news: { isLast: false, name: "咨讯", lastId: 0 },
+const postData = reactive({
+ notice: shallowRef>([]),
+ activity: shallowRef>([]),
+ news: shallowRef>([]),
+});
+const rawData = reactive({
+ notice: shallowRef({ isLast: false, name: "公告", lastId: 0 }),
+ activity: shallowRef({ isLast: false, name: "活动", lastId: 0 }),
+ news: shallowRef({ isLast: false, name: "咨讯", lastId: 0 }),
});
const tab = computed({
get: () => ((recentNewsType.value satisfies NewsType) ? recentNewsType.value : "notice"),
@@ -96,25 +103,20 @@ const tab = computed({
onMounted(async () => await firstLoad(tab.value));
async function firstLoad(key: NewsType, refresh: boolean = false): Promise {
- if (rawData.value[key].lastId !== 0) {
+ if (rawData[key].lastId !== 0) {
if (!refresh) return;
- postData.value[key] = [];
- rawData.value[key].lastId = 0;
+ postData[key] = [];
+ rawData[key].lastId = 0;
}
- await showLoading.start(`正在获取${gameName}${rawData.value[key].name}数据`);
+ await showLoading.start(`正在获取${gameName}${rawData[key].name}数据`);
document.documentElement.scrollTo({ top: 0, behavior: "smooth" });
const getData = await Mys.Painter.getNewsList(gid, NewsTypeEnum[key]);
await showLoading.update(`数量:${getData.list.length},是否最后一页:${getData.is_last}`);
- rawData.value[key].isLast = getData.is_last;
- rawData.value[key].lastId = getData.list.length;
- postData.value[key] = getData.list;
- triggerRef(postData);
- triggerRef(rawData);
+ rawData[key] = { isLast: getData.is_last, name: rawData[key].name, lastId: getData.list.length };
+ postData[key] = getData.list;
await showLoading.end();
- await TGLogger.Info(`[News][${gid}][firstLoad] 获取${rawData.value[key].name}数据成功`);
- showSnackbar.success(
- `获取${gameName}${rawData.value[key].name}数据成功,共 ${getData.list.length} 条`,
- );
+ await TGLogger.Info(`[News][${gid}][firstLoad] 获取${rawData[key].name}数据成功`);
+ showSnackbar.success(`获取${gameName}${rawData[key].name}数据成功,共 ${getData.list.length} 条`);
}
async function switchAnno(): Promise {
@@ -125,25 +127,25 @@ async function switchAnno(): Promise {
// 加载更多
async function loadMore(key: NewsType): Promise {
loading.value = true;
- if (rawData.value[key].isLast) {
+ if (rawData[key].isLast) {
showSnackbar.warn("已经是最后一页了");
loading.value = false;
return;
}
- await showLoading.start(`正在获取${gameName}${rawData.value[key].name}数据`);
+ await showLoading.start(`正在获取${gameName}${rawData[key].name}数据`);
+ const mod = rawData[key].lastId % 20;
+ const pageSize = mod === 0 ? 20 : 20 - mod;
const getData = await Mys.Painter.getNewsList(
gid,
NewsTypeEnum[key],
- 20,
- rawData.value[key].lastId,
+ pageSize,
+ rawData[key].lastId,
);
await showLoading.update(`数量:${getData.list.length},是否最后一页:${getData.is_last}`);
- rawData.value[key].lastId = rawData.value[key].lastId + getData.list.length;
- rawData.value[key].isLast = getData.is_last;
- postData.value[key] = postData.value[key].concat(getData.list);
- triggerRef(postData);
- triggerRef(rawData);
- if (rawData.value[key].isLast) {
+ rawData[key].lastId = rawData[key].lastId + getData.list.length;
+ rawData[key].isLast = getData.is_last;
+ postData[key] = postData[key].concat(getData.list);
+ if (rawData[key].isLast) {
await showLoading.end();
showSnackbar.warn("已经是最后一页了");
loading.value = false;
diff --git a/src/pages/common/PostTopic.vue b/src/pages/common/PostTopic.vue
index cde20742..ef761436 100644
--- a/src/pages/common/PostTopic.vue
+++ b/src/pages/common/PostTopic.vue
@@ -52,7 +52,8 @@
- 已加载:{{ posts.length }},加载更多
+ 已加载:{{ posts.length }},
+ {{ postRaw.isLast ? "已加载完毕" : "加载更多" }}
@@ -70,14 +71,14 @@ import { useRoute } from "vue-router";
import { createPost } from "@/utils/TGWindow.js";
type SortSelect = { text: string; value: number };
+type PostMiniData = { isLast: boolean; lastId: string; total: number };
const { gid, topic } = <{ gid: string; topic: string }>useRoute().params;
const showSearch = ref(false);
const curGid = ref(Number(gid));
const curSortType = ref<0 | 1 | 2>(0);
const search = ref("");
-const lastPostId = ref();
-const isLastPage = ref(false);
+const postRaw = shallowRef({ isLast: false, lastId: "", total: 0 });
const topicInfo = shallowRef();
const posts = shallowRef>([]);
const curGame = shallowRef();
@@ -134,24 +135,30 @@ async function firstLoad(): Promise {
return;
}
await showLoading.update(`数量:${postList.posts.length},是否最后一页:${postList.is_last}`);
- isLastPage.value = postList.is_last;
- lastPostId.value = postList.last_id;
+ postRaw.value = {
+ isLast: postList.is_last,
+ lastId: postList.last_id,
+ total: postList.posts.length,
+ };
posts.value = postList.posts;
await showLoading.end();
showSnackbar.success(`加载了 ${postList.posts.length} 条帖子`);
}
async function freshPostData(): Promise {
- if (isLastPage.value) {
+ if (postRaw.value.isLast) {
showSnackbar.warn("已经到底了");
return;
}
await showLoading.start(`正在刷新${topicInfo.value?.topic.name}帖子列表`);
+ const mod20 = postRaw.value.total % 20;
+ const pageSize = mod20 === 0 ? 20 : 20 - mod20;
const postList = await Mys.Post.getTopicPostList(
curGid.value,
topic,
curSortType.value,
- lastPostId.value,
+ postRaw.value.lastId,
+ pageSize,
);
if ("retcode" in postList) {
await showLoading.end();
@@ -159,8 +166,11 @@ async function freshPostData(): Promise {
return;
}
await showLoading.update(`数量:${postList.posts.length},是否最后一页:${postList.is_last}`);
- isLastPage.value = postList.is_last;
- lastPostId.value = postList.last_id;
+ postRaw.value = {
+ isLast: postList.is_last,
+ lastId: postList.last_id,
+ total: postRaw.value.total + postList.posts.length,
+ };
posts.value = posts.value.concat(postList.posts);
await showLoading.end();
showSnackbar.success(`加载了 ${postList.posts.length} 条帖子`);