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