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) // 每分钟更新一次
},
+1 -1
View File
@@ -55,7 +55,7 @@
uni.scanCode({
success: (res) => {
let deviceNo = getQueryString(res.path,'deviceNo')
// console.log(res.path);
console.log(res.path);
uni.navigateTo({
url: `/pages/serve/bagCheck/index?deviceNo=${deviceNo}`
})
+1 -1
View File
@@ -7,7 +7,7 @@
<view class="avatar-wrap">
<image class="avatar" :src="userInfo.avatar || '/static/user.png'" mode="aspectFill" />
</view>
<view class="info-content" v-if="userInfo.nickName">
<view class="info-content" v-if="userInfo">
<view class="text-group">
<text class="nickname">{{ userInfo.nickName }}</text>
<text class="phone">{{ userInfo.phone || "" }}</text>
+63 -5
View File
@@ -51,7 +51,7 @@
</template>
<script>
import {getOrderList} from '../../config/user.js'
import {getOrderList, queryById} from '../../config/user.js'
export default {
data() {
return {
@@ -79,11 +79,69 @@ export default {
]
}
},
async onLoad() {
const res= await getOrderList()
console.log(res);
async onLoad(options) {
// 如果有传入orderId参数,说明是从设备租借页面跳转过来的
if (options && options.orderId) {
try {
// 获取特定订单信息
const res = await queryById(options.orderId);
if (res.code === 200 && res.data) {
// 将获取到的订单添加到列表中
const orderData = res.data;
// 格式化订单数据
const formattedOrder = {
orderNo: orderData.orderId,
status: orderData.orderStatus === 2 ? 'using' : 'finished',
statusText: orderData.orderStatus === 2 ? '使用中' : '已完成',
deviceId: orderData.deviceNo,
startTime: this.formatTime(new Date(orderData.createTime)),
endTime: orderData.endTime ? this.formatTime(new Date(orderData.endTime)) : '',
amount: orderData.amount || '0.00'
};
// 将订单添加到列表开头
this.orderList = [formattedOrder, ...this.orderList];
// 如果是使用中的订单,切换到使用中标签
if (orderData.orderStatus === 2) {
this.switchTab(1); // 切换到"使用中"
}
}
} catch (error) {
console.error('获取订单详情失败:', error);
}
}
// 获取订单列表
try {
const res = await getOrderList();
console.log(res);
if (res.code === 200 && res.data && res.data.records) {
// 处理订单列表数据
this.orderList = res.data.records.map(item => ({
orderNo: item.orderId,
status: item.orderStatus === 2 ? 'using' : 'finished',
statusText: item.orderStatus === 2 ? '使用中' : '已完成',
deviceId: item.deviceNo,
startTime: item.startTime,
endTime: item.endTime ? this.formatTime(new Date(item.endTime)) : '',
amount: item.amount || '0.00'
}));
}
} catch (error) {
console.error('获取订单列表失败:', error);
}
},
methods: {
formatTime(date) {
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}`
},
switchTab(index) {
this.currentTab = index
// TODO: 根据状态获取订单列表
@@ -228,4 +286,4 @@ export default {
}
}
}
</style>
</style>
+386
View File
@@ -0,0 +1,386 @@
<template>
<view class="return-container">
<!-- 订单信息卡片 -->
<view class="order-card">
<view class="order-header">
<text class="title">使用中</text>
<text class="order-no">订单号{{ orderInfo.orderId }}</text>
</view>
<view class="device-info">
<text class="device-name">共享风扇</text>
<text class="device-id">设备号{{ deviceId }}</text>
</view>
<view class="time-info">
<view class="time-item">
<text class="label">开始时间</text>
<text class="value">{{ orderInfo.startTime }}</text>
</view>
<view class="time-item">
<text class="label">已使用时长</text>
<text class="value highlight">{{ orderInfo.usedTime }}</text>
</view>
<view class="time-item">
<text class="label">当前费用</text>
<text class="value">{{ orderInfo.currentFee }}</text>
</view>
</view>
</view>
<!-- 归还说明 -->
<view class="notice-card">
<view class="notice-title">归还说明</view>
<view class="notice-list">
<view class="notice-item">
<view class="dot"></view>
<text>请确保设备完好无损</text>
</view>
<view class="notice-item">
<view class="dot"></view>
<text>请在指定区域内归还设备</text>
</view>
<view class="notice-item">
<view class="dot"></view>
<text>归还后押金将自动退还</text>
</view>
</view>
</view>
<!-- 底部操作栏 -->
<view class="bottom-bar">
<button class="unlock-btn" @click="handleUnlock" :disabled="unlocking">
{{ unlocking ? '开锁中...' : '开锁归还' }}
</button>
</view>
</view>
</template>
<script>
import { queryById, overOrderById } from '@/config/user.js'
export default {
data() {
return {
deviceId: '',
orderInfo: {
orderId: '',
startTime: '',
usedTime: '0分钟',
currentFee: '0.00'
},
unlocking: false,
timer: null
}
},
onLoad(options) {
// 获取传递的参数
this.deviceId = options.deviceId || ''
this.orderInfo.orderId = options.orderId || ''
// 获取订单详情
this.getOrderDetails()
// 启动定时器更新使用时长
this.startTimer()
},
onUnload() {
// 页面卸载时清除定时器
this.clearTimer()
},
methods: {
// 获取订单详情
async getOrderDetails() {
try {
uni.showLoading({ title: '加载中' })
if (!this.orderInfo.orderId) {
throw new Error('订单ID不能为空')
}
const result = await queryById(this.orderInfo.orderId)
if (result.code === 200 && result.data) {
const orderData = result.data
// 格式化开始时间
this.orderInfo.startTime = this.formatTime(new Date(orderData.createTime))
// 计算使用时长
this.calculateUsedTime(orderData.createTime)
// 设置当前费用
this.orderInfo.currentFee = orderData.amount || '0.00'
} else {
throw new Error('获取订单详情失败')
}
} catch (error) {
uni.showToast({
title: error.message || '获取订单信息失败',
icon: 'none'
})
// 如果获取订单失败,返回首页
setTimeout(() => {
uni.reLaunch({
url: '/pages/index/index'
})
}, 1500)
} finally {
uni.hideLoading()
}
},
// 格式化时间
formatTime(date) {
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) {
const start = new Date(startTime)
const now = new Date()
const diffMs = now - start
// 计算分钟数
const minutes = Math.floor(diffMs / (1000 * 60))
if (minutes < 60) {
this.orderInfo.usedTime = `${minutes}分钟`
} else {
const hours = Math.floor(minutes / 60)
const remainMinutes = minutes % 60
this.orderInfo.usedTime = `${hours}小时${remainMinutes}分钟`
}
},
// 更新使用时长的定时器
startTimer() {
// 每分钟更新一次使用时长
this.timer = setInterval(() => {
this.getOrderDetails()
}, 60000)
},
// 清除定时器
clearTimer() {
if (this.timer) {
clearInterval(this.timer)
this.timer = null
}
},
// 处理开锁归还
async handleUnlock() {
if (this.unlocking) return
try {
this.unlocking = true
uni.showLoading({ title: '开锁中' })
// 确认是否归还
const confirmResult = await new Promise((resolve) => {
uni.showModal({
title: '确认归还',
content: '确定要归还设备吗?',
success: (res) => {
resolve(res.confirm)
}
})
})
if (!confirmResult) {
this.unlocking = false
uni.hideLoading()
return
}
// 调用结束订单接口
const result = await overOrderById(this.orderInfo.orderId)
if (result.code === 200) {
uni.showToast({
title: '归还成功',
icon: 'success'
})
// 归还成功后,返回首页
setTimeout(() => {
uni.reLaunch({
url: '/pages/index/index'
})
}, 1500)
} else {
throw new Error(result.msg || '归还失败')
}
} catch (error) {
uni.showToast({
title: error.message || '归还失败,请重试',
icon: 'none'
})
} finally {
this.unlocking = false
uni.hideLoading()
}
}
}
}
</script>
<style lang="scss" scoped>
.return-container {
min-height: 100vh;
background: #f8f8f8;
padding: 30rpx;
padding-bottom: 180rpx;
box-sizing: border-box;
.order-card {
background: #fff;
border-radius: 24rpx;
padding: 30rpx;
margin-bottom: 30rpx;
box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.04);
.order-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30rpx;
.title {
font-size: 36rpx;
font-weight: 600;
color: #1976D2;
}
.order-no {
font-size: 24rpx;
color: #999;
}
}
.device-info {
margin-bottom: 20rpx;
.device-name {
font-size: 32rpx;
font-weight: 500;
color: #333;
margin-right: 20rpx;
}
.device-id {
font-size: 24rpx;
color: #666;
}
}
.time-info {
.time-item {
display: flex;
justify-content: space-between;
margin-bottom: 16rpx;
&:last-child {
margin-bottom: 0;
}
.label {
font-size: 28rpx;
color: #666;
}
.value {
font-size: 28rpx;
color: #333;
&.highlight {
color: #1976D2;
font-weight: 500;
}
}
}
}
}
.notice-card {
background: #fff;
border-radius: 24rpx;
padding: 30rpx;
margin-bottom: 30rpx;
box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.04);
.notice-title {
font-size: 32rpx;
font-weight: 600;
color: #333;
margin-bottom: 24rpx;
}
.notice-list {
.notice-item {
display: flex;
align-items: center;
margin-bottom: 16rpx;
&:last-child {
margin-bottom: 0;
}
.dot {
width: 12rpx;
height: 12rpx;
background: #1976D2;
border-radius: 50%;
margin-right: 16rpx;
}
text {
font-size: 28rpx;
color: #666;
line-height: 1.5;
}
}
}
}
.bottom-bar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
background: #fff;
padding: 20rpx 30rpx;
padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 -4rpx 16rpx rgba(0,0,0,0.04);
.unlock-btn {
width: 100%;
height: 88rpx;
border-radius: 44rpx;
background: linear-gradient(135deg, #FF9800, #FFB74D);
color: #fff;
font-size: 32rpx;
font-weight: 600;
display: flex;
align-items: center;
justify-content: center;
border: none;
&:active {
transform: scale(0.98);
}
&:disabled {
opacity: 0.7;
}
}
}
}
</style>
+34 -13
View File
@@ -20,21 +20,42 @@
}
},
async onLoad(option) {
try {
uni.showLoading({
title: '加载中...'
});
if (!uni.getStorageSync('token')) {
const res = await wxLogin();
console.log(333, res);
}
if (!uni.getStorageSync('token')) {
await wxLogin();
}
const reuslt = await queryHasOrder(111)
if (reuslt.data.length != 0) {
uni.reLaunch({
url: `/pages/device/return?deviceNo=${option.deviceNo}`
})
} else {
uni.reLaunch({
url: `/pages/device/detail?deviceNo=${option.deviceNo}`
})
const result = await queryHasOrder(option.deviceNo);
uni.hideLoading();
if (!option.deviceNo) {
uni.showToast({
title: '设备编号不能为空',
icon: 'none'
});
return;
}
if (result.data.length != 0) {
uni.redirectTo({
url: `/pages/device/return?deviceNo=${option.deviceNo}`
});
} else {
uni.redirectTo({
url: `/pages/device/detail?deviceNo=${option.deviceNo}`
});
}
} catch (error) {
uni.hideLoading();
uni.showToast({
title: '页面加载失败,请重试',
icon: 'none'
});
console.error('bagCheck onLoad error:', error);
}
},
methods: {