直播更新

This commit is contained in:
陈誉午
2026-08-03 11:05:19 +08:00
parent 994b267f5c
commit d0776f9676
12 changed files with 288 additions and 177 deletions
@@ -86,25 +86,52 @@ Page({
const { id, outrewardsid } = e.currentTarget.dataset;
const params: Record<string, any> = {
appId: appId,
outRewardsId: outrewardsid,
openId: wx.getStorageSync("openId"),
};
if (outrewardsid) params.outRewardsId = outrewardsid;
if (id) params.redId = id;
try {
await receiveRedPacket(
params,
'/app/general/receive-red',
appId
);
// 领取成功,刷新当前列表
this.fetchRecords(1, false, this.data.tabs[this.data.activeTab].type);
// 乐观更新:先立即更新本地数据,避免后端状态同步延迟导致展示不友好
const { list, summary, activeTab, tabs } = this.data;
const targetItem = list.find((item: any) => item.id === id);
if (targetItem) {
const amount = targetItem.amount || 0;
const amountYuan = amount / 100;
const updatedList = list.map((item: any) =>
item.id === id
? { ...item, state: 40, stateText: getStateText(40), canReceive: false, isRetry: false }
: item
);
const updatedSummary = {
...summary,
pendingAmount: Math.max(0, parseFloat(summary.pendingAmount) - amountYuan).toFixed(2),
receivedAmount: (parseFloat(summary.receivedAmount) + amountYuan).toFixed(2),
};
this.setData({ list: updatedList, summary: updatedSummary });
}
// 确保后端有足够时间同步,直接刷新
setTimeout(() => {
this.fetchRecords(1, false, tabs[activeTab].type);
}, 3000);
} catch (err) {
console.error('领取红包失败:', err);
}
},
async fetchRecords(page: number, append = false, type: number) {
const app = getApp<IAppOption>();
const openId = wx.getStorageSync("openId");
this.setData({