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 用例,全绿;线上实测分页与筛选接口正常
这个提交包含在:
xcbyy
2026-10-22 10:52:40 +08:00
父节点 082ec1c385
当前提交 d876288394
共有 9 个文件被更改,包括 580 次插入 和 108 次删除

查看文件

@@ -51,16 +51,36 @@ export function formatActivityData(raw) {
/**
* 获取组局活动列表 (真实请求 MySQL,异常时返回空列表)
*/
export async function getActivities() {
export async function getActivities(options = {}) {
const paged = Number(options.page) > 0;
try {
const list = await http.get('/activities');
if (Array.isArray(list) && list.length > 0) {
return list.map(formatActivityData);
const qs = [];
if (paged) {
qs.push(`page=${Math.floor(Number(options.page))}`);
qs.push(`pageSize=${Math.floor(Number(options.pageSize) || 20)}`);
if (options.keyword) qs.push(`keyword=${encodeURIComponent(String(options.keyword).trim())}`);
if (options.payType) qs.push(`payType=${encodeURIComponent(options.payType)}`);
if (Number(options.creatorId) > 0) qs.push(`creatorId=${Math.floor(Number(options.creatorId))}`);
if (options.category) qs.push(`category=${encodeURIComponent(options.category)}`);
if (options.categoryName) qs.push(`categoryName=${encodeURIComponent(options.categoryName)}`);
}
const res = await http.get(`/activities${qs.length ? `?${qs.join('&')}` : ''}`);
if (Array.isArray(res)) {
return res.map(formatActivityData);
}
if (res && Array.isArray(res.list)) {
return {
list: res.list.map(formatActivityData),
total: Number(res.total || 0),
page: Number(res.page || 1),
pageSize: Number(res.pageSize || 20),
hasMore: Boolean(res.hasMore)
};
}
} catch (err) {
console.warn('[API] 获取后端活动列表异常:', err.message);
}
return [];
return paged ? { list: [], total: 0, page: 1, pageSize: 20, hasMore: false } : [];
}
/**
@@ -302,16 +322,33 @@ export function formatOrderData(raw) {
/**
* 获取订单列表 (真实读取 MySQL)
*/
export async function getOrders() {
export async function getOrders(options = {}) {
const paged = Number(options.page) > 0;
try {
const list = await http.get(`/orders?userId=${normalizeUserId()}`);
if (Array.isArray(list) && list.length > 0) {
return list.map(formatOrderData);
const qs = [];
if (options.status) qs.push(`status=${encodeURIComponent(options.status)}`);
if (paged) {
qs.push(`page=${Math.floor(Number(options.page))}`);
qs.push(`pageSize=${Math.floor(Number(options.pageSize) || 20)}`);
}
const suffix = qs.length ? `&${qs.join('&')}` : '';
const res = await http.get(`/orders?userId=${normalizeUserId()}${suffix}`);
if (Array.isArray(res)) {
return res.map(formatOrderData);
}
if (res && Array.isArray(res.list)) {
return {
list: res.list.map(formatOrderData),
total: Number(res.total || 0),
page: Number(res.page || 1),
pageSize: Number(res.pageSize || 20),
hasMore: Boolean(res.hasMore)
};
}
} catch (err) {
console.warn('[API] 获取订单列表异常:', err.message);
}
return [];
return paged ? { list: [], total: 0, page: 1, pageSize: 20, hasMore: false } : [];
}
/**
@@ -1368,10 +1405,17 @@ export async function getSubscribeTemplates() {
/**
* 获取站内消息通知列表与未读数
*/
export async function getNotifications(userId, limit = 50) {
export async function getNotifications(userId, limit = 50, extra = {}) {
const uid = normalizeUserId(userId);
try {
const res = await http.get(`/notifications?userId=${uid}&limit=${Number(limit) || 50}`);
const qs = [`userId=${uid}`];
if (Number(extra.page) > 0) {
qs.push(`page=${Math.floor(Number(extra.page))}`);
qs.push(`pageSize=${Math.floor(Number(extra.pageSize) || 20)}`);
} else {
qs.push(`limit=${Number(limit) || 50}`);
}
const res = await http.get(`/notifications?${qs.join('&')}`);
return res || { list: [], unread: 0 };
} catch (err) {
throw err;

查看文件

@@ -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;

查看文件

@@ -106,11 +106,22 @@
</view>
</view>
<view v-if="filteredOrders.length === 0" class="empty-state">
<view v-if="isLoading" class="load-more-tip">
<text>加载中…</text>
</view>
<view v-else-if="filteredOrders.length === 0" class="empty-state">
<image class="empty-svg" :src="ICONS.orderList" mode="aspectFit" />
<text class="empty-text">暂无此类订单</text>
<button class="empty-btn btn-active" @click="goToExplore">前往发现大厅寻找大神</button>
</view>
<view v-else-if="isLoadingMore" class="load-more-tip">
<text>正在加载更多…</text>
</view>
<view v-else-if="!hasMore" class="load-more-tip">
<text>没有更多了</text>
</view>
</view>
</view>
@@ -350,7 +361,7 @@
<script setup>
import { ref, computed, onMounted, onUnmounted } from 'vue';
import { onShow } from '@dcloudio/uni-app';
import { onShow, onReachBottom } from '@dcloudio/uni-app';
import {
getOrders,
cancelOrder as cancelOrderApi,
@@ -411,18 +422,56 @@ const onThemeChanged = (key) => {
};
const orders = ref([]);
const page = ref(1);
const pageSize = 20;
const hasMore = ref(false);
const isLoading = ref(true);
const isLoadingMore = ref(false);
let requestSeq = 0;
const loadLiveOrders = async () => {
const loadLiveOrders = async (reset = true) => {
if (!reset && isLoadingMore.value) return;
const seq = ++requestSeq;
const targetPage = reset ? 1 : page.value + 1;
isLoadingMore.value = true;
if (reset) isLoading.value = true;
try {
const list = await getOrders();
if (Array.isArray(list)) {
const res = await getOrders({
page: targetPage,
pageSize,
status: currentTab.value === 'ALL' ? '' : currentTab.value
});
if (seq !== requestSeq) return;
const list = Array.isArray(res) ? res : (res && Array.isArray(res.list) ? res.list : []);
if (reset) {
orders.value = list;
hasMore.value = Array.isArray(res) ? false : Boolean(res && res.hasMore);
} else {
const seen = new Set(orders.value.map(o => o.id));
orders.value = orders.value.concat(list.filter(o => !seen.has(o.id)));
hasMore.value = Boolean(res && res.hasMore);
}
page.value = targetPage;
} catch (err) {
console.warn('[OrderList] 获取订单列表失败:', err);
if (seq === requestSeq && reset) {
orders.value = [];
hasMore.value = false;
}
} finally {
if (seq === requestSeq) {
isLoading.value = false;
isLoadingMore.value = false;
}
}
};
onReachBottom(() => {
if (hasMore.value && !isLoadingMore.value) {
loadLiveOrders(false);
}
});
onMounted(() => {
navInfo.value = getNavBarInfo();
currentThemeKey.value = getCurrentThemeKey();
@@ -463,13 +512,14 @@ const tabs = [
const currentTab = ref('ALL');
const filteredOrders = computed(() => {
if (currentTab.value === 'ALL') return orders.value;
return orders.value.filter(o => o.status === currentTab.value);
});
// 状态筛选已由服务端分页完成,这里直接展示当前页数据
const filteredOrders = computed(() => orders.value);
const switchTab = (tabKey) => {
if (currentTab.value === tabKey) return;
currentTab.value = tabKey;
orders.value = [];
loadLiveOrders(true);
};
const goToExplore = () => {
@@ -963,6 +1013,13 @@ const submitReview = async () => {
flex: 1;
}
.load-more-tip {
text-align: center;
padding: 24rpx 0;
font-size: 24rpx;
color: #64748B;
}
.tab-header {
display: flex;
background-color: #151D30;

查看文件

@@ -22,6 +22,7 @@
refresher-enabled
:refresher-triggered="isRefreshing"
@refresherrefresh="onRefresh"
@scrolltolower="loadMore"
>
<view class="notif-body">
<view class="notif-summary">
@@ -56,6 +57,13 @@
</view>
</view>
</view>
<view v-if="isLoadingMore" class="load-more-tip">
<text>正在加载更多…</text>
</view>
<view v-else-if="!hasMore && list.length > 0" class="load-more-tip">
<text>没有更多了</text>
</view>
</view>
</scroll-view>
</view>
@@ -73,8 +81,13 @@ const currentThemeKey = ref(getCurrentThemeKey());
const navInfo = ref(getNavBarInfo());
const isLoading = ref(true);
const isRefreshing = ref(false);
const isLoadingMore = ref(false);
const list = ref([]);
const unreadCount = ref(0);
const page = ref(1);
const pageSize = 20;
const hasMore = ref(false);
let requestSeq = 0;
const navStyle = computed(() => ({
'--safe-header-gap': `${navInfo.value.totalHeaderHeight}px`,
@@ -90,28 +103,55 @@ const formatTime = (v) => {
return s.length >= 16 ? s.slice(0, 16) : s;
};
const loadData = async () => {
const loadData = async (reset = true) => {
if (!reset && isLoadingMore.value) return;
const uid = currentUserId();
if (!uid) {
isLoading.value = false;
return;
}
const seq = ++requestSeq;
const targetPage = reset ? 1 : page.value + 1;
isLoadingMore.value = true;
if (reset) isLoading.value = true;
try {
const res = await getNotifications(uid, 50);
list.value = Array.isArray(res?.list) ? res.list : [];
const res = await getNotifications(uid, 50, { page: targetPage, pageSize });
if (seq !== requestSeq) return;
const incoming = Array.isArray(res?.list) ? res.list : [];
if (reset) {
list.value = incoming;
hasMore.value = Boolean(res?.hasMore);
} else {
const seen = new Set(list.value.map((x) => x.id));
list.value = list.value.concat(incoming.filter((x) => !seen.has(x.id)));
hasMore.value = Boolean(res?.hasMore);
}
unreadCount.value = Number(res?.unread || 0);
page.value = targetPage;
} catch (_) {
list.value = [];
unreadCount.value = 0;
if (seq === requestSeq && reset) {
list.value = [];
unreadCount.value = 0;
hasMore.value = false;
}
} finally {
isLoading.value = false;
isRefreshing.value = false;
if (seq === requestSeq) {
isLoading.value = false;
isLoadingMore.value = false;
isRefreshing.value = false;
}
}
};
const loadMore = () => {
if (hasMore.value && !isLoadingMore.value) {
loadData(false);
}
};
const onRefresh = () => {
isRefreshing.value = true;
loadData();
loadData(true);
};
const handleReadAll = async () => {
@@ -286,6 +326,12 @@ onShow(() => {
flex-direction: column;
gap: 10px;
}
.load-more-tip {
padding: 18px 0 8px;
text-align: center;
color: var(--text-muted, #6d7997);
font-size: 12px;
}
.notif-card {
position: relative;
padding: 14px 14px 14px 18px;