diff --git a/config/url.js b/config/url.js
index cccf35a..6c5808c 100644
--- a/config/url.js
+++ b/config/url.js
@@ -1,5 +1,5 @@
-// export const URL = "https://my.gxfs123.com/api" //正式服务器
-export const URL = "https://fansdev.gxfs123.com/api" //测试服务器
+export const URL = "https://my.gxfs123.com/api" //正式服务器
+// export const URL = "https://fansdev.gxfs123.com/api" //测试服务器
// export const URL = "http://192.168.5.120:8080" //本地调试
// export const URL = "http://127.0.0.1:8080" //本地调试
diff --git a/pages/device/detail.vue b/pages/device/detail.vue
index 5842369..cccf83d 100644
--- a/pages/device/detail.vue
+++ b/pages/device/detail.vue
@@ -549,12 +549,12 @@
// 调用微信支付分小程序
const payResult = await initiateWeChatScorePayment(res);
console.log('支付分调用结果', payResult);
- // 成功则跳转等待页,轮询在等待页处理
+ // 成功则跳转到等待页面
if (payResult.errCode == '0' && payResult.extraData && Object.keys(payResult.extraData).length > 0) {
- console.log('支付分授权成功,准备跳转,时间:', new Date().toLocaleTimeString());
- // 直接跳转(订阅消息已经在前面完成了)
+ console.log('支付分授权成功,准备跳转到等待页,时间:', new Date().toLocaleTimeString());
+ // 跳转到等待页面(订阅消息已经在前面完成了)
uni.redirectTo({
- url: `/pages/waiting/index?orderNo=${order.orderNo}&deviceId=${deviceId.value}`
+ url: `/pages/waiting/index?orderNo=${order.orderNo}&orderId=${order.orderId}&deviceId=${deviceId.value}`
});
return;
} else {
diff --git a/pages/index/index.vue b/pages/index/index.vue
index e4cb78d..504c9b5 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -3,7 +3,8 @@
- {{ $t('home.title') }}
+
+ 风电者共享风扇
diff --git a/pages/order/detail.vue b/pages/order/detail.vue
index 14e90a0..f59a427 100644
--- a/pages/order/detail.vue
+++ b/pages/order/detail.vue
@@ -154,10 +154,11 @@
},
timer: null,
statusCheckTimer: null,
- maxStatusChecks: 30,
+ maxStatusChecks: 60,
currentStatusChecks: 0,
- statusCheckInterval: 5000,
+ statusCheckInterval: 3000,
isPageActive: false,
+ isLoadingOrder: false,
expressThresholdSeconds: 180,
countdownRemaining: 0,
showExpressAction: false,
@@ -552,11 +553,18 @@
return
}
+ // 防止并发请求
+ if (this.isLoadingOrder) {
+ console.log('正在加载订单,跳过重复请求')
+ return
+ }
+
try {
if (!this.orderInfo.orderId) {
throw new Error(this.$t('order.orderIdRequired'))
}
+ this.isLoadingOrder = true
const result = await queryById(this.orderInfo.orderId)
if (result.code === 200 && result.data) {
@@ -602,12 +610,15 @@
this.goToHome()
}, 1500)
} finally {
+ this.isLoadingOrder = false
uni.hideLoading()
}
},
// 更新订单信息
updateOrderInfo(orderData) {
+ const oldStatus = this.orderInfo.orderStatus
+
this.orderInfo.usedTime = orderData.usedTime || '0分钟'
this.orderInfo.currentFee = orderData.currentFee || orderData.actualDeviceAmount || orderData.payAmount || '0.00'
this.orderInfo.orderStatus = orderData.orderStatus || ''
@@ -638,21 +649,43 @@
if (orderData.deviceNo && !this.deviceId) {
this.deviceId = orderData.deviceNo
}
+
+ // 如果订单状态从 'in_used' 变为其他状态,清理所有定时器
+ if (oldStatus === 'in_used' && this.orderInfo.orderStatus !== 'in_used') {
+ console.log('订单状态已从使用中变为:', this.orderInfo.orderStatus, ',清理所有定时器')
+ this.clearTimer()
+ this.clearStatusCheckTimer()
+ this.clearExpressCountdown()
+ this.removeFromOrderMonitor()
+
+ // 显示订单完成提示
+ if (this.orderInfo.orderStatus === 'used_done' || this.orderInfo.orderStatus === 'used_down') {
+ uni.showToast({
+ title: '订单已完成',
+ icon: 'success'
+ })
+ }
+ }
},
- // 更新使用时长的定时器
+ // 更新使用时长的定时器(每30秒更新一次)
startTimer() {
this.clearTimer()
this.timer = setInterval(() => {
- if (this.isPageActive) {
- console.log('执行定时更新订单信息')
- this.getOrderDetails()
- } else {
+ if (!this.isPageActive) {
console.log('页面已不活跃,停止计时器')
this.clearTimer()
+ return
}
- }, 60000)
- console.log('已启动使用时长更新计时器')
+ if (this.orderInfo.orderStatus !== 'in_used') {
+ console.log('订单状态已变更,停止计时器')
+ this.clearTimer()
+ return
+ }
+ console.log('执行定时更新订单信息')
+ this.getOrderDetails()
+ }, 30000) // 改为30秒更新一次
+ console.log('已启动使用时长更新计时器(30秒间隔)')
},
// 清除定时器
@@ -673,32 +706,39 @@
}
},
- // 开始状态检查定时器
+ // 开始状态检查定时器(优化版)
startStatusCheckTimer() {
this.currentStatusChecks = 0
this.clearStatusCheckTimer()
this.statusCheckTimer = setInterval(() => {
- if (this.isPageActive) {
- this.currentStatusChecks++
- console.log(`执行归还状态检查 (${this.currentStatusChecks}/${this.maxStatusChecks})`)
- this.checkReturnStatus()
-
- if (this.currentStatusChecks >= this.maxStatusChecks) {
- this.clearStatusCheckTimer()
- uni.showToast({
- title: '请手动刷新查看归还状态',
- icon: 'none',
- duration: 3000
- })
- }
- } else {
+ if (!this.isPageActive) {
console.log('页面已不活跃,停止状态检查计时器')
this.clearStatusCheckTimer()
+ return
+ }
+
+ if (this.orderInfo.orderStatus !== 'in_used') {
+ console.log('订单状态已变更,停止状态检查计时器')
+ this.clearStatusCheckTimer()
+ return
+ }
+
+ this.currentStatusChecks++
+ console.log(`执行归还状态检查 (${this.currentStatusChecks}/${this.maxStatusChecks})`)
+ this.checkReturnStatus()
+
+ if (this.currentStatusChecks >= this.maxStatusChecks) {
+ this.clearStatusCheckTimer()
+ uni.showToast({
+ title: '请手动刷新查看归还状态',
+ icon: 'none',
+ duration: 3000
+ })
}
}, this.statusCheckInterval)
- console.log('已启动归还状态检查计时器')
+ console.log('已启动归还状态检查计时器(3秒间隔)')
},
// 通过设备号查询使用中的订单
diff --git a/pages/waiting/index.vue b/pages/waiting/index.vue
index cf3fe09..20c01b0 100644
--- a/pages/waiting/index.vue
+++ b/pages/waiting/index.vue
@@ -32,6 +32,8 @@
const leftRotateDeg = ref(0)
const rightRotateDeg = ref(0)
const orderNo = ref('')
+ const orderId = ref('')
+ const deviceId = ref('')
let progressTimer = null
let pollTimer = null
let timeoutTimer = null
@@ -76,7 +78,10 @@
progress.value = 100
updateRotate(progress.value)
setTimeout(() => {
- uni.redirectTo({ url: '/pages/order/index' })
+ // 跳转到订单详情页面,传递 orderId 和 deviceId
+ const url = `/pages/order/detail?orderId=${orderId.value || orderNo.value}&deviceId=${deviceId.value}`
+ console.log('等待完成,跳转到订单详情:', url)
+ uni.redirectTo({ url })
}, 400)
}
@@ -98,6 +103,16 @@
if (!orderNo.value) return
const res = await getOrderByOrderNoScorePayStatus(orderNo.value)
if (res && res.data) {
+ // 如果还没有 orderId,从返回数据中获取
+ if (!orderId.value && res.data.orderId) {
+ orderId.value = res.data.orderId
+ console.log('从订单状态中获取 orderId:', orderId.value)
+ }
+ if (!deviceId.value && res.data.deviceNo) {
+ deviceId.value = res.data.deviceNo
+ console.log('从订单状态中获取 deviceId:', deviceId.value)
+ }
+
if (res.data.orderStatus == 'in_used') {
stopAllTimers()
handleSuccess()
@@ -125,8 +140,17 @@
uni.setNavigationBarTitle({
title: $t('waiting.title')
})
- if (query && query.orderNo) {
- orderNo.value = query.orderNo
+ if (query) {
+ if (query.orderNo) {
+ orderNo.value = query.orderNo
+ }
+ if (query.orderId) {
+ orderId.value = query.orderId
+ }
+ if (query.deviceId) {
+ deviceId.value = query.deviceId
+ }
+ console.log('等待页面参数:', { orderNo: orderNo.value, orderId: orderId.value, deviceId: deviceId.value })
}
startProgress()
startPolling()
diff --git a/utils/orderMonitor.js b/utils/orderMonitor.js
index 058a8f5..011cd55 100644
--- a/utils/orderMonitor.js
+++ b/utils/orderMonitor.js
@@ -8,7 +8,7 @@ class OrderMonitor {
constructor() {
this.activeOrders = new Map() // 存储活跃订单 Map
this.timer = null
- this.checkInterval = 10000 // 10秒检查一次
+ this.checkInterval = 5000 // 5秒检查一次,更及时地发现订单完成
this.isRunning = false
this.currentPage = null // 当前活跃页面
}
@@ -16,9 +16,9 @@ class OrderMonitor {
/**
* 添加订单到监控队列
* @param {Object} orderData 订单数据对象,必须包含orderId字段
- * @param {String} pageName 关联的页面名称,默认为'return'
+ * @param {String} pageName 关联的页面名称,默认为'detail'(订单详情页)
*/
- addOrder(orderData, pageName = 'return') {
+ addOrder(orderData, pageName = 'detail') {
if (!orderData || !orderData.orderId) {
console.error('添加订单监控失败:无效的订单数据')
return
@@ -111,19 +111,15 @@ class OrderMonitor {
console.log(`检查 ${this.activeOrders.size} 个活跃订单状态, 当前页面: ${this.currentPage}`)
- // 只检查当前活跃页面关联的订单,或无页面关联的订单
+ // 检查所有活跃订单,不限制页面
+ // 主要监控订单详情页(detail)和其他相关页面
for (const [orderId, data] of this.activeOrders.entries()) {
try {
- // 只在归还页面(或页面未指定时)才执行轮询
- if (!data.pageName || data.pageName === 'return') {
- if (this.currentPage === 'return' || this.currentPage === null) {
- await this.checkOrderStatus(orderId)
- } else {
- // console.log(`跳过订单状态检查: ${orderId}, 当前不在归还页面`)
- }
- }
+ // 检查所有使用中的订单状态
+ // 不限制页面,因为用户可能在任何页面时订单完成归还
+ await this.checkOrderStatus(orderId)
} catch (error) {
- // console.error(`检查订单状态失败: ${orderId}`, error)
+ console.error(`检查订单状态失败: ${orderId}`, error)
}
}
}
@@ -168,7 +164,7 @@ class OrderMonitor {
}
if (shouldNotify) {
- // 触发全局事件
+ // 触发全局事件(订单详情页会监听此事件自动刷新)
uni.$emit('orderCompleted', orderData)
// 显示全局通知
@@ -183,21 +179,27 @@ class OrderMonitor {
// innerAudioContext.src = '/static/audio/return_success.mp3'
// innerAudioContext.play()
- // 如果用户不在归还页面,则显示归还成功弹窗
+ // 如果用户不在订单详情页,则显示归还成功弹窗
+ // 如果在订单详情页,页面自己会处理状态变化
setTimeout(() => {
- uni.showModal({
- title: '归还成功',
- content: '风扇已归还成功,剩余押金将退还到您的账户',
- confirmText: '查看详情',
- success: (res) => {
- if (res.confirm) {
- // 跳转到统一订单详情页面查看详情
- uni.redirectTo({
- url: `/pages/order/detail?orderId=${orderId}`
- })
+ if (this.currentPage !== 'detail') {
+ uni.showModal({
+ title: '归还成功',
+ content: '风扇已归还成功,剩余押金将退还到您的账户',
+ confirmText: '查看详情',
+ cancelText: '我知道了',
+ success: (res) => {
+ if (res.confirm) {
+ // 跳转到订单详情页面查看详情
+ uni.navigateTo({
+ url: `/pages/order/detail?orderId=${orderId}`
+ })
+ }
}
- }
- })
+ })
+ } else {
+ console.log('当前在订单详情页,不显示弹窗,页面会自动刷新')
+ }
}, 500)
}
@@ -231,7 +233,8 @@ const initOrderMonitor = () => {
const lastActiveOrderId = uni.getStorageSync('activeOrderId')
if (lastActiveOrderId) {
const lastOrderData = { orderId: lastActiveOrderId }
- orderMonitor.addOrder(lastOrderData, 'return')
+ orderMonitor.addOrder(lastOrderData, 'detail')
+ console.log('恢复监控上次活跃订单:', lastActiveOrderId)
}
}