feat: 新增多个页面及功能,优化用户体验

在项目中新增了多个页面,包括押金页面、设备详情页面、反馈页面和帮助页面。同时,更新了订单支付和归还成功页面的逻辑,确保用户在支付和归还设备时能够获得清晰的反馈。优化了扫码和订单状态处理逻辑,提升了整体用户体验。
This commit is contained in:
8vd8
2025-04-21 14:54:00 +08:00
parent 41b409c327
commit 8431cdf2d6
12 changed files with 337 additions and 111 deletions
Binary file not shown.
+90 -18
View File
@@ -89,12 +89,16 @@ export default {
statusCheckTimer: null,
maxStatusChecks: 30, // 最多检查30次
currentStatusChecks: 0,
statusCheckInterval: 5000 // 5秒检查一次
statusCheckInterval: 5000, // 5秒检查一次
isPageActive: false // 跟踪页面是否活跃
}
},
onLoad(options) {
console.log('Return page loaded with options:', JSON.stringify(options))
// 标记页面为活跃状态
this.isPageActive = true
// 获取传递的参数
this.orderInfo.orderId = options.orderId || ''
this.deviceId = options.deviceNo || options.deviceId || ''
@@ -118,7 +122,10 @@ export default {
// 如果订单ID有效,将订单添加到全局监控服务
try {
if (this.$orderMonitor) {
this.$orderMonitor.addOrder({orderId: this.orderInfo.orderId})
// 先确保移除之前的监控(防止重复添加)
this.$orderMonitor.removeOrder({orderId: this.orderInfo.orderId})
// 添加到监控队列,明确指定为归还页面
this.$orderMonitor.addOrder({orderId: this.orderInfo.orderId}, 'return')
console.log('订单已添加到监控队列:', this.orderInfo.orderId)
} else {
console.warn('$orderMonitor 未定义,无法添加订单到监控队列')
@@ -142,14 +149,46 @@ export default {
// 注册全局订单完成事件监听器
uni.$on('orderCompleted', this.handleOrderCompleted)
},
// 添加onHide生命周期,处理页面隐藏时的清理工作
onHide() {
console.log('归还页面隐藏,清理计时器资源和监控服务')
// 标记页面为非活跃状态
this.isPageActive = false
// 清理所有计时器
this.clearTimer()
this.clearStatusCheckTimer()
// 从全局订单监控服务中移除当前订单
this.removeFromOrderMonitor()
},
onUnload() {
console.log('归还页面卸载,清理所有资源')
// 标记页面为非活跃状态
this.isPageActive = false
// 页面卸载时清除定时器
this.clearTimer()
this.clearStatusCheckTimer()
// 从全局订单监控服务中移除当前订单
this.removeFromOrderMonitor()
// 注销全局事件监听
uni.$off('orderCompleted', this.handleOrderCompleted)
},
methods: {
// 从订单监控服务中移除当前订单
removeFromOrderMonitor() {
if (this.orderInfo.orderId && this.$orderMonitor) {
try {
this.$orderMonitor.removeOrder({orderId: this.orderInfo.orderId})
console.log('订单已从监控队列移除:', this.orderInfo.orderId)
} catch (error) {
console.error('从监控队列移除订单失败:', error)
}
}
},
// 处理订单完成事件(可由任何地方触发)
handleOrderCompleted(orderData) {
console.log('收到订单完成事件:', orderData)
@@ -206,8 +245,14 @@ export default {
// 获取订单详情
async getOrderDetails() {
// 如果页面不再活跃,不执行API请求
if (!this.isPageActive) {
console.log('页面已不活跃,跳过订单详情请求')
return
}
try {
uni.showLoading({ title: '加载中' })
// uni.showLoading({ title: '加载中' })
if (!this.orderInfo.orderId) {
throw new Error('订单ID不能为空')
@@ -320,10 +365,22 @@ export default {
// 更新使用时长的定时器
startTimer() {
// 清除现有计时器,确保不重复
this.clearTimer()
// 每分钟更新一次使用时长
this.timer = setInterval(() => {
this.getOrderDetails()
// 只有当页面活跃时才执行更新
if (this.isPageActive) {
console.log('执行定时更新订单信息')
this.getOrderDetails()
} else {
console.log('页面已不活跃,停止计时器')
this.clearTimer()
}
}, 60000)
console.log('已启动使用时长更新计时器')
},
// 清除定时器
@@ -331,6 +388,7 @@ export default {
if (this.timer) {
clearInterval(this.timer)
this.timer = null
console.log('已清除使用时长更新计时器')
}
},
@@ -339,36 +397,47 @@ export default {
if (this.statusCheckTimer) {
clearInterval(this.statusCheckTimer)
this.statusCheckTimer = null
console.log('已清除归还状态检查计时器')
}
},
// 开始状态检查定时器
startStatusCheckTimer() {
this.currentStatusChecks = 0
// 确保之前的计时器被清除
this.clearStatusCheckTimer()
this.statusCheckTimer = setInterval(() => {
this.currentStatusChecks++
this.checkReturnStatus()
// 如果超过最大检查次数,停止定时器
if (this.currentStatusChecks >= this.maxStatusChecks) {
this.clearStatusCheckTimer()
// 只有当页面活跃时才执行检查
if (this.isPageActive) {
this.currentStatusChecks++
console.log(`执行归还状态检查 (${this.currentStatusChecks}/${this.maxStatusChecks})`)
this.checkReturnStatus()
// 提示用户手动刷新
uni.showToast({
title: '请手动刷新查看归还状态',
icon: 'none',
duration: 3000
})
// 如果超过最大检查次数,停止定时器
if (this.currentStatusChecks >= this.maxStatusChecks) {
this.clearStatusCheckTimer()
// 提示用户手动刷新
uni.showToast({
title: '请手动刷新查看归还状态',
icon: 'none',
duration: 3000
})
}
} else {
console.log('页面已不活跃,停止状态检查计时器')
this.clearStatusCheckTimer()
}
}, this.statusCheckInterval)
console.log('已启动归还状态检查计时器')
},
// 通过设备号查询使用中的订单
async getOrderByDevice() {
try {
uni.showLoading({ title: '加载中' })
// uni.showLoading({ title: '加载中' })
if (!this.deviceId) {
throw new Error('设备号不能为空')
@@ -432,7 +501,10 @@ export default {
// 检查归还状态
async checkReturnStatus() {
try {
await this.getOrderDetails()
// 只有页面活跃时才执行检查
if (this.isPageActive) {
await this.getOrderDetails()
}
} catch (error) {
console.error('检查归还状态失败:', error)
}