fix: 修复微信小程序appid及URL配置错误

修复了微信小程序的appid配置错误,将appid从"wxabe9cc4db1005fcb"更新为"wx3ae63fb09936b379"。同时,将URL从生产环境切换为本地开发环境,修改为"http://127.0.0.1:8080"。此外,优化了http请求的错误处理逻辑,增加了对响应状态码和业务状态码的检查,确保请求失败时能够正确捕获并处理错误。
This commit is contained in:
fuck
2025-04-07 17:18:09 +08:00
parent 60bb924d5c
commit 40f523595b
207 changed files with 2896 additions and 47650 deletions
+21 -22
View File
@@ -84,7 +84,8 @@
<script>
import {
getDeviceInfo
getDeviceInfo,
rentPowerBank
} from '@/config/user.js'
export default {
data() {
@@ -218,34 +219,32 @@
title: '处理中'
})
const selectedPkg = this.packages[this.selectedPackage]
// 添加手机号到请求参数
const result = await this.$api.createOrder({
deviceId: this.deviceId,
packageId: this.selectedPackage,
duration: selectedPkg.time,
amount: selectedPkg.price,
phone: this.phoneNumber
})
// 调用设备租借接口
const rentResult = await rentPowerBank(this.deviceId, this.phoneNumber)
if (rentResult.code !== 200) {
throw new Error(rentResult.msg || '设备租借失败')
}
// 获取后端返回的订单信息
const order = rentResult.data
uni.hideLoading()
if (result.success) {
uni.showToast({
title: '租借成功',
icon: 'success'
uni.showToast({
title: '租借成功',
icon: 'success'
})
// 跳转到订单页面
setTimeout(() => {
uni.redirectTo({
url: `/pages/order/index?orderId=${order.orderId}`
})
// 跳转到使用中页面
setTimeout(() => {
uni.redirectTo({
url: `/pages/return/index?deviceId=${this.deviceId}&orderId=${result.orderId}`
})
}, 1500)
}
}, 1500)
} catch (error) {
uni.hideLoading()
uni.showToast({
title: '租借失败,请重试',
title: error.message || '租借失败,请重试',
icon: 'none'
})
}
+89 -32
View File
@@ -9,13 +9,13 @@
<view class="device-info">
<text class="device-name">共享风扇</text>
<text class="device-id">设备号{{ deviceId }}</text>
<text class="device-id">设备号{{ deviceNo }}</text>
</view>
<view class="time-info">
<view class="time-item">
<text class="label">开始时间</text>
<text class="value">{{ orderInfo.startTime }}</text>
<text class="value">{{ orderInfo.createTime }}</text>
</view>
<view class="time-item">
<text class="label">已使用时长</text>
@@ -50,17 +50,19 @@
<!-- 底部操作栏 -->
<view class="bottom-bar">
<button class="unlock-btn" @click="handleUnlock" :disabled="unlocking">
{{ unlocking ? '开锁中...' : '开锁归还' }}
{{ unlocking ? '归还中...' : '归还设备' }}
</button>
</view>
</view>
</template>
<script>
import { queryHasOrder, overOrderById } from '@/config/user.js'
export default {
data() {
return {
deviceId: '',
deviceNo: '',
orderInfo: {
orderId: '',
startTime: '',
@@ -72,7 +74,7 @@ export default {
}
},
onLoad(options) {
this.deviceId = options.deviceId
this.deviceNo = options.deviceNo
this.getActiveOrder()
},
onUnload() {
@@ -83,14 +85,15 @@ export default {
async getActiveOrder() {
try {
uni.showLoading({ title: '加载中' })
const result = await this.$api.getActiveOrder()
const result = await queryHasOrder(this.deviceNo)
if (result.success) {
if (result.code === 200 && result.data && result.data.length > 0) {
const orderData = result.data[0]
this.orderInfo = {
orderId: result.data.orderId,
startTime: result.data.startTime,
usedTime: result.data.usedTime,
currentFee: result.data.currentFee
orderId: orderData.orderId,
startTime: this.formatTime(orderData.createTime),
usedTime: this.calculateUsedTime(orderData.createTime),
currentFee: orderData.amount || '0.00'
}
this.startTimer()
} else {
@@ -106,6 +109,7 @@ export default {
}, 1500)
}
} catch (error) {
console.error('获取订单信息失败:', error)
uni.showToast({
title: '获取订单信息失败',
icon: 'none'
@@ -115,32 +119,34 @@ export default {
}
},
// 处理开锁请求
// 处理归还请求
async handleUnlock() {
if (this.unlocking) return
try {
this.unlocking = true
uni.showLoading({ title: '开锁中' })
uni.showLoading({ title: '归还中' })
// 发送开锁请求
const result = await this.$api.unlockDevice({
deviceId: this.deviceId,
orderId: this.orderInfo.orderId
})
// 发送结束订单请求
const result = await overOrderById(this.orderInfo.orderId)
if (result.success) {
if (result.code === 200) {
uni.showToast({
title: '开锁成功',
title: '归还成功',
icon: 'success'
})
// 开锁成功后,可以添加其他逻辑,比如显示归还确认按钮等
// 归还成功后,跳转到订单页面
setTimeout(() => {
uni.redirectTo({
url: '/pages/order/index'
})
}, 1500)
} else {
throw new Error(result.message || '开锁失败')
throw new Error(result.msg || '归还失败')
}
} catch (error) {
uni.showToast({
title: error.message || '开锁失败,请重试',
title: error.message || '归还失败,请重试',
icon: 'none'
})
} finally {
@@ -149,17 +155,68 @@ export default {
}
},
// 格式化时间
formatTime(date) {
// 检查是否是字符串格式的日期(如 "Mon Apr 07 16:36:35 CST 2025"
if (typeof date === 'string' && date.match(/\w{3}\s\w{3}\s\d{2}\s\d{2}:\d{2}:\d{2}\s\w{3}\s\d{4}/)) {
// 直接使用字符串创建Date对象,JS会自动解析这种标准格式
date = new Date(date);
} else if (!(date instanceof Date)) {
// 如果不是Date对象,尝试创建一个
date = new Date(date);
}
// 检查日期是否有效
if (isNaN(date.getTime())) {
console.error('无效的日期格式:', date);
return '无效日期';
}
const year = date.getFullYear()
const month = (date.getMonth() + 1).toString().padStart(2, '0')
const day = date.getDate().toString().padStart(2, '0')
const hour = date.getHours().toString().padStart(2, '0')
const minute = date.getMinutes().toString().padStart(2, '0')
return `${year}-${month}-${day} ${hour}:${minute}`
},
// 计算使用时长
calculateUsedTime(startTime) {
// 检查是否是字符串格式的日期(如 "Mon Apr 07 16:36:35 CST 2025"
let start;
if (typeof startTime === 'string') {
// 尝试直接创建Date对象,JS会自动解析标准格式
start = new Date(startTime);
// 检查日期是否有效
if (isNaN(start.getTime())) {
console.error('无效的日期格式:', startTime);
return '0小时0分钟';
}
} else if (startTime instanceof Date) {
start = startTime;
} else {
console.error('无效的日期类型:', startTime);
return '0小时0分钟';
}
const now = new Date()
const diffMs = now - start
const diffHours = Math.floor(diffMs / (1000 * 60 * 60))
const diffMinutes = Math.floor((diffMs % (1000 * 60 * 60)) / (1000 * 60))
return `${diffHours}小时${diffMinutes}分钟`
},
// 更新使用时长
startTimer() {
this.timer = setInterval(async () => {
try {
const result = await this.$api.getOrderStatus(this.orderInfo.orderId)
if (result.success) {
this.orderInfo.usedTime = result.data.usedTime
this.orderInfo.currentFee = result.data.currentFee
}
} catch (error) {
console.error('更新订单状态失败:', error)
this.timer = setInterval(() => {
// 更新使用时长
if (this.orderInfo.orderId) {
// 直接使用原始的createTime计算使用时长
this.orderInfo.usedTime = this.calculateUsedTime(this.orderInfo.startTime)
}
}, 60000) // 每分钟更新一次
},