feat: release
This commit is contained in:
@@ -13,4 +13,11 @@ export const fetchTopicCategories = async (data) => {
|
|||||||
url: "/api/rating/topic/category/list",
|
url: "/api/rating/topic/category/list",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const fetchTopicList = async (categoryId, page = 1) => {
|
||||||
|
return request({
|
||||||
|
url: `/api/rating/topic/list/${categoryId}?page=${page}`,
|
||||||
|
method: "GET",
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -20,13 +20,13 @@
|
|||||||
<view class="tabs-wrapper">
|
<view class="tabs-wrapper">
|
||||||
<view
|
<view
|
||||||
class="tab-item"
|
class="tab-item"
|
||||||
:class="{ active: currentCategory === index }"
|
:class="{ active: currentCategoryId === category.id }"
|
||||||
v-for="(category, index) in categories"
|
v-for="category in categories"
|
||||||
:key="index"
|
:key="category.id"
|
||||||
@tap="switchCategory(index)"
|
@tap="switchCategory(category.id)"
|
||||||
>
|
>
|
||||||
<text class="tab-text">{{ category.name }}</text>
|
<text class="tab-text">{{ category.title }}</text>
|
||||||
<view class="tab-line" v-if="currentCategory === index"></view>
|
<view class="tab-line" v-if="currentCategoryId === category.id"></view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</scroll-view>
|
||||||
@@ -109,6 +109,7 @@ import {
|
|||||||
} from "@dcloudio/uni-app";
|
} from "@dcloudio/uni-app";
|
||||||
import { useUserStore } from "@/stores/user";
|
import { useUserStore } from "@/stores/user";
|
||||||
import { getShareReward } from "@/api/system";
|
import { getShareReward } from "@/api/system";
|
||||||
|
import { fetchTopicList, fetchTopicCategories } from "@/api/topic";
|
||||||
import { getShareToken, saveViewRequest } from "@/utils/common.js";
|
import { getShareToken, saveViewRequest } from "@/utils/common.js";
|
||||||
import LoginPopup from "@/components/LoginPopup/LoginPopup.vue";
|
import LoginPopup from "@/components/LoginPopup/LoginPopup.vue";
|
||||||
import adManager from "@/utils/adManager.js";
|
import adManager from "@/utils/adManager.js";
|
||||||
@@ -119,36 +120,68 @@ const userInfo = computed(() => userStore?.userInfo || {});
|
|||||||
|
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const hasMore = ref(true);
|
const hasMore = ref(true);
|
||||||
const currentCategory = ref(0);
|
const currentCategoryId = ref('');
|
||||||
|
const categories = ref([]);
|
||||||
|
const currentPage = ref(1);
|
||||||
|
|
||||||
const categories = ref([
|
const loadCategories = async () => {
|
||||||
{ id: 0, name: '全部' },
|
try {
|
||||||
{ id: 1, name: '历史' },
|
const res = await fetchTopicCategories();
|
||||||
{ id: 2, name: '皇帝' },
|
// 提取真实数据数组
|
||||||
{ id: 3, name: '数码' },
|
const list = res?.data?.list || res?.list || res || [];
|
||||||
{ id: 4, name: '手机' },
|
|
||||||
{ id: 5, name: '城市' },
|
// 增加一个“全部”的默认选项,id 置空
|
||||||
{ id: 6, name: '生活' },
|
categories.value = [{ id: '', title: '全部' }, ...list];
|
||||||
]);
|
|
||||||
|
// 初始化选中的ID为“全部”
|
||||||
|
if (!currentCategoryId.value && categories.value.length > 0) {
|
||||||
|
currentCategoryId.value = categories.value[0].id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载初始列表
|
||||||
|
loadTopicList(currentCategoryId.value, currentPage.value);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("获取分类失败:", error);
|
||||||
|
// 兜底数据
|
||||||
|
categories.value = [
|
||||||
|
{ id: '', title: '全部' },
|
||||||
|
{ id: 1, title: '历史' },
|
||||||
|
{ id: 2, title: '数码' },
|
||||||
|
];
|
||||||
|
// 使用兜底也尝试加载一次
|
||||||
|
loadTopicList(currentCategoryId.value, currentPage.value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const switchCategory = (index) => {
|
const loadTopicList = async (categoryId, page = 1) => {
|
||||||
if (currentCategory.value === index) return;
|
if (page === 1) {
|
||||||
currentCategory.value = index;
|
topicList.value = [];
|
||||||
// 切换分类时重新加载数据
|
}
|
||||||
topicList.value = [];
|
try {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
hasMore.value = true;
|
const res = await fetchTopicList(categoryId, page);
|
||||||
setTimeout(() => {
|
// 提取真实数据数组
|
||||||
// 模拟根据分类筛选数据
|
const list = res?.list || [];
|
||||||
const filteredData = mockData.filter(item => {
|
|
||||||
if (index === 0) return true;
|
// 合并数据
|
||||||
const categoryName = categories.value[index].name;
|
topicList.value = [...topicList.value, ...list];
|
||||||
return item.tags.includes(categoryName);
|
hasMore.value = list.length >= 5;
|
||||||
});
|
} catch (error) {
|
||||||
topicList.value = [...filteredData];
|
console.error("获取主题列表失败:", error);
|
||||||
|
hasMore.value = false;
|
||||||
|
} finally {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
hasMore.value = filteredData.length >= 10 ? true : false;
|
}
|
||||||
}, 500);
|
};
|
||||||
|
|
||||||
|
const switchCategory = (categoryId) => {
|
||||||
|
if (currentCategoryId.value === categoryId) return;
|
||||||
|
currentCategoryId.value = categoryId;
|
||||||
|
|
||||||
|
// 切换分类时重新加载数据
|
||||||
|
currentPage.value = 1;
|
||||||
|
hasMore.value = true;
|
||||||
|
loadTopicList(categoryId, currentPage.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockData = [
|
const mockData = [
|
||||||
@@ -213,7 +246,7 @@ const initData = () => {
|
|||||||
if (adManager.isAdShowing) return; // 防止广告页返回时立即重新渲染引发 insertTextView:fail
|
if (adManager.isAdShowing) return; // 防止广告页返回时立即重新渲染引发 insertTextView:fail
|
||||||
};
|
};
|
||||||
|
|
||||||
onLoad((options) => {
|
onLoad(async (options) => {
|
||||||
uni.$trackRecord({
|
uni.$trackRecord({
|
||||||
eventName: "index_page_visit",
|
eventName: "index_page_visit",
|
||||||
eventType: `visit`,
|
eventType: `visit`,
|
||||||
@@ -221,6 +254,8 @@ onLoad((options) => {
|
|||||||
if (options.shareToken) {
|
if (options.shareToken) {
|
||||||
saveViewRequest(options.shareToken, "index");
|
saveViewRequest(options.shareToken, "index");
|
||||||
}
|
}
|
||||||
|
await loadCategories(); // 初始化时加载分类
|
||||||
|
await loadTopicList(currentCategoryId.value); // 初始化时加载主题列表
|
||||||
initData();
|
initData();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -236,26 +271,18 @@ const handleLoginSuccess = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 下拉刷新
|
// 下拉刷新
|
||||||
onPullDownRefresh(() => {
|
onPullDownRefresh(async () => {
|
||||||
setTimeout(() => {
|
currentPage.value = 1;
|
||||||
topicList.value = [...mockData];
|
hasMore.value = true;
|
||||||
hasMore.value = true;
|
await loadTopicList(currentCategoryId.value, currentPage.value);
|
||||||
uni.stopPullDownRefresh();
|
uni.stopPullDownRefresh();
|
||||||
}, 1000);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 上拉加载更多
|
// 上拉加载更多
|
||||||
onReachBottom(() => {
|
onReachBottom(() => {
|
||||||
if (!hasMore.value || loading.value) return;
|
if (!hasMore.value || loading.value) return;
|
||||||
loading.value = true;
|
currentPage.value += 1;
|
||||||
setTimeout(() => {
|
loadTopicList(currentCategoryId.value, currentPage.value);
|
||||||
const newData = mockData.map(item => ({ ...item, id: item.id + topicList.value.length }));
|
|
||||||
topicList.value.push(...newData);
|
|
||||||
loading.value = false;
|
|
||||||
if (topicList.value.length >= 10) {
|
|
||||||
hasMore.value = false;
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
onShareAppMessage(async () => {
|
onShareAppMessage(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user