fix:修复bug

This commit is contained in:
2026-01-22 10:52:58 +08:00
parent b0daa7b59b
commit 6a1dff4b94
46 changed files with 3779 additions and 2522 deletions
+50 -46
View File
@@ -131,7 +131,9 @@
import {
getOrderByOrderNoScore,
getOrderByOrderNo,
cancelOrder
cancelOrder,
getInUseOrder,
getUnpaidOrder
} from '@/config/api/order.js'
import {
initiateWeChatScorePayment,
@@ -143,7 +145,7 @@
} from '@/utils/i18n.js'
const {
t: $t
t
} = useI18n()
// 响应式状态
@@ -154,7 +156,7 @@
const deviceLocation = ref('一号教学楼大厅')
const hasActiveOrder = ref(false)
const deviceStatus = reactive({
text: $t('device.available'),
text: t('device.available'),
class: 'available'
})
const isLoggedIn = ref(true)
@@ -175,7 +177,7 @@
onMounted(async () => {
uni.setNavigationBarTitle({
title: $t('device.deviceInfo')
title: t('device.deviceInfo')
})
await checkUserPhone()
await fetchDeviceInfo()
@@ -219,7 +221,7 @@
// 用户拒绝授权的情况
if (e.detail.errMsg && e.detail.errMsg.includes('deny')) {
uni.showToast({
title: $t('auth.phoneRequired'),
title: t('auth.phoneRequired'),
icon: 'none'
})
return
@@ -228,7 +230,7 @@
// 获取到授权code
if (e.detail.code) {
uni.showLoading({
title: $t('auth.getting')
title: t('auth.getting')
})
console.log('获取到的授权code:', e.detail.code)
@@ -260,15 +262,15 @@
showPhoneAuthPopup.value = false
uni.showToast({
title: $t('auth.phoneSuccess'),
title: t('auth.phoneSuccess'),
icon: 'success'
})
} else {
// 记录详细信息,不抛出错误
console.warn('获取手机号响应异常:', res.msg || '未知错误')
uni.showModal({
title: $t('auth.phoneError'),
content: `${$t('common.statusCode')}: ${res.code}, ${$t('common.message')}: ${res.msg || $t('common.none')}`,
title: t('auth.phoneError'),
content: `${t('common.statusCode')}: ${res.code}, ${t('common.message')}: ${res.msg || t('common.none')}`,
showCancel: false
})
}
@@ -280,8 +282,8 @@
// 显示更详细的错误信息
let errMsg = err.message || err.toString()
uni.showModal({
title: $t('auth.phoneGetFailed'),
content: $t('common.errorInfo') + ': ' + errMsg,
title: t('auth.phoneGetFailed'),
content: t('common.errorInfo') + ': ' + errMsg,
showCancel: false
})
})
@@ -289,14 +291,14 @@
uni.hideLoading()
console.error('获取手机号外部错误:', outerError)
uni.showModal({
title: $t('common.unexpectedError'),
content: $t('common.processException') + ': ' + (outerError.message || outerError),
title: t('common.unexpectedError'),
content: t('common.processException') + ': ' + (outerError.message || outerError),
showCancel: false
})
}
} else {
uni.showToast({
title: $t('auth.authCodeFailed'),
title: t('auth.authCodeFailed'),
icon: 'none'
})
}
@@ -325,10 +327,10 @@
// 更新设备状态
if (deviceInfo.value.status) {
if (deviceInfo.value.status === 'online') {
deviceStatus.text = $t('device.available')
deviceStatus.text = t('device.available')
deviceStatus.class = 'available'
} else if (deviceInfo.value.status === 'offline') {
deviceStatus.text = $t('device.offline')
deviceStatus.text = t('device.offline')
deviceStatus.class = 'offline'
}
}
@@ -349,9 +351,9 @@
// 显示登录提示
const showLoginTip = () => {
uni.showModal({
title: $t('common.tips'),
content: $t('common.loginRequired'),
confirmText: $t('auth.goToLogin'),
title: t('common.tips'),
content: t('common.loginRequired'),
confirmText: t('auth.goToLogin'),
success: (res) => {
if (res.confirm) {
uni.navigateTo({
@@ -374,27 +376,29 @@
const checkOrderStatus = async () => {
try {
// 调用接口检查是否有进行中的订单
const result = await uni.$api.checkActiveOrder()
const inUseRes = await getInUseOrder()
if (inUseRes && inUseRes.code === 200 && inUseRes.data) {
const order = inUseRes.data
// 如果有正在进行的订单,跳转到归还页面,带上设备ID
uni.redirectTo({
url: `/pages/device/return?deviceId=${deviceId.value}`
})
return
}
if (result.hasOrder) {
const order = result.order // 假设后端返回 order 对象
// 检查订单状态
if (order.status === 'waiting_for_payment') {
// 跳转支付页面,带上订单ID
uni.redirectTo({
url: `/pages/order/payment?orderId=${order.orderId}&deviceId=${deviceId.value}`
})
} else if (order.status === 'in_used') {
// 如果有正在进行的订单,跳转到归还页面,带上设备ID
uni.redirectTo({
url: `/pages/device/return?deviceId=${deviceId.value}`
})
}
// 检查是否有待支付的订单
const unpaidRes = await getUnpaidOrder()
if (unpaidRes && unpaidRes.code === 200 && unpaidRes.data) {
const order = unpaidRes.data
// 跳转支付页面,带上订单ID
uni.redirectTo({
url: `/pages/order/payment?orderId=${order.orderId}&deviceId=${deviceId.value}`
})
}
} catch (error) {
console.error('检查订单状态失败:', error)
uni.showToast({
title: $t('order.getOrderStatusFailed'),
title: t('order.getOrderStatusFailed'),
icon: 'none'
})
}
@@ -427,7 +431,7 @@
return '30分钟'
}
// 按小时计费(默认)
return $t('time.hour')
return t('time.hour')
}
// 计算计费单位时间(分钟)
@@ -499,7 +503,7 @@
const submitRentOrder = async (payWay) => {
try {
uni.showLoading({
title: $t('common.processing')
title: t('common.processing')
})
// --- 第一步:先请求订阅消息(必须在用户点击的同步上下文中)---
if (payWay === 'wx-score-pay') {
@@ -532,7 +536,7 @@
// 调用设备租借接口
const rentResult = await rentPowerBank(deviceId.value, phoneNumber.value)
if (rentResult.code !== 200) {
throw new Error(rentResult.msg || $t('device.rentFailed'))
throw new Error(rentResult.msg || t('device.rentFailed'))
}
// 获取后端返回的订单信息
@@ -587,7 +591,7 @@
// 用户取消授权,需要取消订单
try {
uni.showLoading({
title: $t('order.cancelling')
title: t('order.cancelling')
});
const cancelRes = await cancelOrder({
orderId: order.orderNo
@@ -596,7 +600,7 @@
uni.hideLoading();
uni.showToast({
title: $t('order.orderCancelled'),
title: t('order.orderCancelled'),
icon: 'none',
duration: 2000
});
@@ -611,7 +615,7 @@
console.error('取消订单失败:', cancelError);
uni.hideLoading();
uni.showToast({
title: $t('order.cancelFailedContactService'),
title: t('order.cancelFailedContactService'),
icon: 'none'
});
}
@@ -622,7 +626,7 @@
// 支付分调用异常,也需要取消订单
try {
uni.showLoading({
title: $t('order.cancelling')
title: t('order.cancelling')
});
const cancelRes = await cancelOrder({
orderId: order.orderNo
@@ -635,7 +639,7 @@
}
uni.showToast({
title: $t('device.payScoreFailedCancelled'),
title: t('device.payScoreFailedCancelled'),
icon: 'none'
});
@@ -647,7 +651,7 @@
}
} else {
uni.showToast({
title: res?.msg || $t('device.getPayParamsFailed'),
title: res?.msg || t('device.getPayParamsFailed'),
icon: 'none'
});
}
@@ -655,7 +659,7 @@
} catch (error) {
uni.hideLoading()
uni.showToast({
title: error.message || $t('device.rentFailedRetry'),
title: error.message || t('device.rentFailedRetry'),
icon: 'none'
})
}