模拟了微信支付功能

This commit is contained in:
2025-08-08 19:21:04 +08:00
parent 85df7bfc4e
commit c1817b6255
14 changed files with 246 additions and 30 deletions

View File

@ -8,6 +8,7 @@ Page({
_secondsRemaining: 0, // 内部倒计时秒数
_hasShownTimeout: false, // 是否已弹过“超时未支付”弹窗
globalImgUrl,
isMaskVisible: false
},
onLoad(options) {
@ -15,7 +16,61 @@ Page({
this.setData({ orderId: options.id });
this.getOrderDetail();
},
showIsPayModal() {
const {orderId} = this.data
wx.showModal({
title: '下单成功',
content: '您确定要支付吗?',
cancelText: '取消',
confirmText: '确定',
success: (res) => {
if (res.confirm) {
this.payOrder(orderId);
} else if (res.cancel) {
this.setData({ isMaskVisible: false });
}
},
fail: () => {
wx.hideLoading();
wx.showToast({
title: '网络错误,下单失败',
icon: 'none'
});
}
});
},
payOrder(orderId) {
// 同样先显示遮罩
this.setData({ isMaskVisible: true });
wx.showLoading({ title: '支付中...'});
wx.request({
url: baseUrl + '/courseOrder/payment',
method: 'POST',
header: { Authorization: wx.getStorageSync('token') },
data: { id: orderId},
success: res => {
wx.hideLoading();
if (res.data.code === 1) {
// 支付成功,跳转详情页
wx.redirectTo({
url: `/pages/course/orderDetail/orderDetail?id=${orderId}`,
success: res => {
// 先把遮罩关掉
this.setData({ isMaskVisible: false });
}
});
} else {
this.setData({ isMaskVisible: false });
wx.showToast({ title: res.data.message || '支付失败', icon: 'none' });
}
},
fail: () => {
wx.hideLoading();
this.setData({ isMaskVisible: false });
wx.showToast({ title: '网络错误,支付失败', icon: 'none' });
}
});
},
onUnload() {
clearInterval(this._timer);
},
@ -48,7 +103,7 @@ Page({
// 将 "2025-07-13 12:38:17" → 时间戳
const createMs = new Date(createTime.replace(/-/g, '/')).getTime();
const now = Date.now();
let diff = Math.floor((createMs + 30 * 60 * 1000 - now) / 1000);
let diff = Math.floor((createMs + 15 * 60 * 1000 - now) / 1000);
if (diff <= 0) {
// 已超时