feat(list): 订单/通知/组局列表分页,生产 NODE_ENV 切换 production
- 仓储层 getOrders/getOrdersForUser/getActivities/getUserNotifications 支持 LIMIT/OFFSET,新增 countOrders/countOrdersForUser/countActivities/getUserNotificationTotal - 接口支持 page/pageSize/status/keyword/payType/creatorId/category,返回 list/total/hasMore;未传 page 保持旧数组格式,兼容后台与工作台 - 小程序订单/通知/组局三页触底加载,筛选与搜索下推服务端,避免只过滤当前页 - 新增 116 套件/758 用例,全绿;线上实测分页与筛选接口正常
这个提交包含在:
@@ -163,6 +163,13 @@
|
||||
清空搜索条件
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<view v-if="isLoadingMore" class="load-more-tip">
|
||||
<text>正在加载更多…</text>
|
||||
</view>
|
||||
<view v-else-if="!hasMore && filteredActivities.length > 0" class="load-more-tip">
|
||||
<text>没有更多了</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -172,8 +179,8 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted, onUnmounted } from 'vue';
|
||||
import { onShow, onLoad } from '@dcloudio/uni-app';
|
||||
import { ref, computed, watch, onMounted, onUnmounted } from 'vue';
|
||||
import { onShow, onLoad, onReachBottom } from '@dcloudio/uni-app';
|
||||
import AppTabBar from '@/components/CustomTabBar.vue';
|
||||
import SkeletonScreen from '@/components/SkeletonScreen.vue';
|
||||
import { getActivities, getNavCategories, normalizeUserId } from '@/common/api.js';
|
||||
@@ -184,6 +191,7 @@ import { getNavBarInfo } from '@/common/nav.js';
|
||||
const CURRENT_USER_ID = normalizeUserId();
|
||||
|
||||
const isLoading = ref(true);
|
||||
const isLoadingMore = ref(false);
|
||||
const activities = ref([]);
|
||||
const currentTab = ref('ALL');
|
||||
const currentCategory = ref('ALL');
|
||||
@@ -191,6 +199,11 @@ const dynamicCategories = ref([]);
|
||||
const currentThemeKey = ref(getCurrentThemeKey());
|
||||
const searchKeyword = ref('');
|
||||
const navInfo = ref(getNavBarInfo());
|
||||
const page = ref(1);
|
||||
const pageSize = 20;
|
||||
const hasMore = ref(false);
|
||||
let searchTimer = null;
|
||||
let requestSeq = 0;
|
||||
|
||||
const navStyle = computed(() => {
|
||||
return {
|
||||
@@ -206,7 +219,7 @@ const clearSearch = () => {
|
||||
|
||||
const loadInitialActivities = async () => {
|
||||
try {
|
||||
await fetchLiveActivities();
|
||||
await fetchLiveActivities(true);
|
||||
} finally {
|
||||
setTimeout(() => {
|
||||
isLoading.value = false;
|
||||
@@ -214,14 +227,43 @@ const loadInitialActivities = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const fetchLiveActivities = async () => {
|
||||
const fetchLiveActivities = async (reset = true) => {
|
||||
if (!reset && isLoadingMore.value) return;
|
||||
const seq = ++requestSeq;
|
||||
const targetPage = reset ? 1 : page.value + 1;
|
||||
isLoadingMore.value = true;
|
||||
try {
|
||||
const list = await getActivities();
|
||||
if (Array.isArray(list) && list.length > 0) {
|
||||
const categoryMeta = navCapsules.value.find((c) => c.code === currentCategory.value);
|
||||
const res = await getActivities({
|
||||
page: targetPage,
|
||||
pageSize,
|
||||
keyword: searchKeyword.value.trim(),
|
||||
payType: currentTab.value === 'AA' || currentTab.value === 'PROJECT' ? currentTab.value : '',
|
||||
creatorId: currentTab.value === 'MINE' ? CURRENT_USER_ID : 0,
|
||||
category: currentCategory.value === 'ALL' ? '' : currentCategory.value,
|
||||
categoryName: categoryMeta ? categoryMeta.name : ''
|
||||
});
|
||||
if (seq !== requestSeq) return;
|
||||
const list = Array.isArray(res) ? res : (res && Array.isArray(res.list) ? res.list : []);
|
||||
if (reset) {
|
||||
activities.value = list;
|
||||
hasMore.value = Array.isArray(res) ? false : Boolean(res && res.hasMore);
|
||||
} else {
|
||||
const seen = new Set(activities.value.map((a) => a.id));
|
||||
activities.value = activities.value.concat(list.filter((a) => !seen.has(a.id)));
|
||||
hasMore.value = Boolean(res && res.hasMore);
|
||||
}
|
||||
page.value = targetPage;
|
||||
} catch (err) {
|
||||
console.warn('[ActivityList] 获取线上数据异常,保持缓存:', err);
|
||||
if (seq === requestSeq && reset) {
|
||||
activities.value = [];
|
||||
hasMore.value = false;
|
||||
}
|
||||
} finally {
|
||||
if (seq === requestSeq) {
|
||||
isLoadingMore.value = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -301,6 +343,10 @@ onShow(() => {
|
||||
|
||||
onUnmounted(() => {
|
||||
uni.$off('theme-change', onThemeChanged);
|
||||
if (searchTimer) {
|
||||
clearTimeout(searchTimer);
|
||||
searchTimer = null;
|
||||
}
|
||||
});
|
||||
|
||||
const getCategoryTagClass = (game) => {
|
||||
@@ -318,61 +364,32 @@ const getStatusText = (status) => {
|
||||
return '招募中';
|
||||
};
|
||||
|
||||
const filteredActivities = computed(() => {
|
||||
const kw = (searchKeyword.value || '').trim().toLowerCase();
|
||||
|
||||
return activities.value.filter(a => {
|
||||
// 1. 关键词搜索筛选 (标题、商圈地点、品类、局长昵称)
|
||||
let matchKeyword = true;
|
||||
if (kw) {
|
||||
const titleMatch = (a.title || '').toLowerCase().includes(kw);
|
||||
const locationMatch = (a.location || '').toLowerCase().includes(kw);
|
||||
const gameMatch = (a.game || '').toLowerCase().includes(kw);
|
||||
const creatorMatch = (a.creatorNickname || '').toLowerCase().includes(kw);
|
||||
matchKeyword = titleMatch || locationMatch || gameMatch || creatorMatch;
|
||||
}
|
||||
|
||||
// 2. 支付模式或发单人筛选
|
||||
let matchTab = true;
|
||||
if (currentTab.value === 'MINE') {
|
||||
matchTab = Number(a.creatorId) === Number(CURRENT_USER_ID);
|
||||
} else if (currentTab.value !== 'ALL') {
|
||||
matchTab = a.payType === currentTab.value;
|
||||
}
|
||||
|
||||
// 3. 品类筛选 (支持动态匹配后台下发品类)
|
||||
let matchCat = true;
|
||||
if (currentCategory.value && currentCategory.value !== 'ALL') {
|
||||
const targetCatCode = currentCategory.value.toUpperCase();
|
||||
if (targetCatCode === 'MEAL') {
|
||||
matchCat = a.game === '美食陪吃' || (a.gameCategory || '').includes('MEAL');
|
||||
} else if (targetCatCode === 'SING') {
|
||||
matchCat = a.game === '同城陪唱' || (a.gameCategory || '').includes('SING');
|
||||
} else if (targetCatCode === 'DRINK' || targetCatCode === 'BAR') {
|
||||
matchCat = a.game === '下午茶陪喝' || a.game === '同城微醺' || (a.gameCategory || '').includes('DRINK');
|
||||
} else if (targetCatCode === 'ESPORTS') {
|
||||
matchCat = a.game.includes('电竞') || a.game.includes('游戏') || (a.gameCategory || '').includes('ESPORTS');
|
||||
} else {
|
||||
const found = navCapsules.value.find((c) => c.code === targetCatCode);
|
||||
if (found) {
|
||||
matchCat = a.game.includes(found.name) || found.name.includes(a.game);
|
||||
} else {
|
||||
matchCat = a.game.includes(currentCategory.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return matchKeyword && matchTab && matchCat;
|
||||
});
|
||||
});
|
||||
// 筛选与搜索已交由服务端分页完成,这里直接展示当前页数据
|
||||
const filteredActivities = computed(() => activities.value);
|
||||
|
||||
const switchTab = (tab) => {
|
||||
if (currentTab.value === tab) return;
|
||||
currentTab.value = tab;
|
||||
fetchLiveActivities(true);
|
||||
};
|
||||
|
||||
const switchCategory = (cat) => {
|
||||
if (currentCategory.value === cat) return;
|
||||
currentCategory.value = cat;
|
||||
fetchLiveActivities(true);
|
||||
};
|
||||
|
||||
onReachBottom(() => {
|
||||
if (hasMore.value && !isLoadingMore.value) {
|
||||
fetchLiveActivities(false);
|
||||
}
|
||||
});
|
||||
|
||||
watch(searchKeyword, () => {
|
||||
if (searchTimer) clearTimeout(searchTimer);
|
||||
searchTimer = setTimeout(() => fetchLiveActivities(true), 350);
|
||||
});
|
||||
|
||||
const goToDetail = (id) => {
|
||||
uni.navigateTo({
|
||||
url: `/pages/activity/detail?id=${id}`
|
||||
@@ -592,6 +609,13 @@ const createActivity = () => {
|
||||
flex-direction: column;
|
||||
gap: 24rpx;
|
||||
|
||||
.load-more-tip {
|
||||
text-align: center;
|
||||
padding: 20rpx 0;
|
||||
font-size: 24rpx;
|
||||
color: #64748B;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
text-align: center;
|
||||
padding: 60rpx 0;
|
||||
|
||||
在新工单中引用
屏蔽一个用户