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
+13 -6
View File
@@ -76,6 +76,7 @@ const _sfc_main = {
formattedTime = this.formatTime(/* @__PURE__ */ new Date());
}
} catch (e) {
common_vendor.index.__f__("error", "at pages/order/payment.vue:158", "时间格式化错误:", e);
formattedTime = this.formatTime(/* @__PURE__ */ new Date());
}
this.orderInfo = {
@@ -84,12 +85,12 @@ const _sfc_main = {
createTime: formattedTime,
phone: orderData.phone,
deposit: this.passedDepositAmount || orderData.depositAmount || "99.00",
amount: orderData.packagePrice || this.packageInfo.price || "0.00"
// 优先使用传递的押金,然后是订单中的押金,最后默认99元
amount: orderData.amount || this.packageInfo.price || "0.00"
};
if (orderData.packageTime) {
this.packageInfo.time = `${orderData.packageTime / 60}小时`;
this.packageInfo.price = orderData.packagePrice || "0.00";
} else if (this.packageInfo.time) {
if (!orderData.packageTime && this.packageInfo.time) {
this.orderInfo.packageTime = this.packageInfo.time;
this.orderInfo.packagePrice = this.packageInfo.price;
}
} else {
throw new Error("获取订单信息失败");
@@ -126,6 +127,11 @@ const _sfc_main = {
title: "支付成功",
icon: "success"
});
try {
await config_user.updateUserBalance(this.orderId);
} catch (error) {
common_vendor.index.__f__("warn", "at pages/order/payment.vue:223", "更新用户余额失败:", error);
}
setTimeout(() => {
common_vendor.index.redirectTo({
url: `/pages/order/index?orderId=${this.orderId}`
@@ -133,6 +139,7 @@ const _sfc_main = {
}, 1500);
},
fail: (err) => {
common_vendor.index.__f__("error", "at pages/order/payment.vue:234", "支付失败:", err);
throw new Error("支付失败,请重试");
}
});
@@ -229,7 +236,7 @@ const _sfc_main = {
throw new Error("查询订单状态失败");
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/order/payment.vue:332", "查询订单状态错误:", error);
common_vendor.index.__f__("error", "at pages/order/payment.vue:342", "查询订单状态错误:", error);
return null;
}
}
+84 -37
View File
@@ -21,15 +21,18 @@ const _sfc_main = {
maxStatusChecks: 30,
// 最多检查30次
currentStatusChecks: 0,
statusCheckInterval: 5e3
statusCheckInterval: 5e3,
// 5秒检查一次
isPageActive: false
// 跟踪页面是否活跃
};
},
onLoad(options) {
common_vendor.index.__f__("log", "at pages/return/index.vue:96", "Return page loaded with options:", JSON.stringify(options));
common_vendor.index.__f__("log", "at pages/return/index.vue:97", "Return page loaded with options:", JSON.stringify(options));
this.isPageActive = true;
this.orderInfo.orderId = options.orderId || "";
this.deviceId = options.deviceNo || options.deviceId || "";
common_vendor.index.__f__("log", "at pages/return/index.vue:102", `初始化参数: orderId=${this.orderInfo.orderId}, deviceId=${this.deviceId}`);
common_vendor.index.__f__("log", "at pages/return/index.vue:106", `初始化参数: orderId=${this.orderInfo.orderId}, deviceId=${this.deviceId}`);
if (!this.orderInfo.orderId && this.deviceId) {
this.getOrderByDevice();
} else if (this.orderInfo.orderId) {
@@ -39,13 +42,14 @@ const _sfc_main = {
common_vendor.index.setStorageSync("activeOrderId", this.orderInfo.orderId);
try {
if (this.$orderMonitor) {
this.$orderMonitor.addOrder({ orderId: this.orderInfo.orderId });
common_vendor.index.__f__("log", "at pages/return/index.vue:122", "订单已添加到监控队列:", this.orderInfo.orderId);
this.$orderMonitor.removeOrder({ orderId: this.orderInfo.orderId });
this.$orderMonitor.addOrder({ orderId: this.orderInfo.orderId }, "return");
common_vendor.index.__f__("log", "at pages/return/index.vue:129", "订单已添加到监控队列:", this.orderInfo.orderId);
} else {
common_vendor.index.__f__("warn", "at pages/return/index.vue:124", "$orderMonitor 未定义,无法添加订单到监控队列");
common_vendor.index.__f__("warn", "at pages/return/index.vue:131", "$orderMonitor 未定义,无法添加订单到监控队列");
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/return/index.vue:127", "添加订单到监控队列失败:", error);
common_vendor.index.__f__("error", "at pages/return/index.vue:134", "添加订单到监控队列失败:", error);
}
} else {
common_vendor.index.showToast({
@@ -58,15 +62,37 @@ const _sfc_main = {
}
common_vendor.index.$on("orderCompleted", this.handleOrderCompleted);
},
onUnload() {
// 添加onHide生命周期,处理页面隐藏时的清理工作
onHide() {
common_vendor.index.__f__("log", "at pages/return/index.vue:154", "归还页面隐藏,清理计时器资源和监控服务");
this.isPageActive = false;
this.clearTimer();
this.clearStatusCheckTimer();
this.removeFromOrderMonitor();
},
onUnload() {
common_vendor.index.__f__("log", "at pages/return/index.vue:166", "归还页面卸载,清理所有资源");
this.isPageActive = false;
this.clearTimer();
this.clearStatusCheckTimer();
this.removeFromOrderMonitor();
common_vendor.index.$off("orderCompleted", this.handleOrderCompleted);
},
methods: {
// 从订单监控服务中移除当前订单
removeFromOrderMonitor() {
if (this.orderInfo.orderId && this.$orderMonitor) {
try {
this.$orderMonitor.removeOrder({ orderId: this.orderInfo.orderId });
common_vendor.index.__f__("log", "at pages/return/index.vue:186", "订单已从监控队列移除:", this.orderInfo.orderId);
} catch (error) {
common_vendor.index.__f__("error", "at pages/return/index.vue:188", "从监控队列移除订单失败:", error);
}
}
},
// 处理订单完成事件(可由任何地方触发)
handleOrderCompleted(orderData) {
common_vendor.index.__f__("log", "at pages/return/index.vue:155", "收到订单完成事件:", orderData);
common_vendor.index.__f__("log", "at pages/return/index.vue:194", "收到订单完成事件:", orderData);
if (orderData.orderId === this.orderInfo.orderId || orderData.orderNo === this.orderInfo.orderNo) {
this.showReturnSuccessModal(orderData);
}
@@ -108,18 +134,21 @@ const _sfc_main = {
},
// 获取订单详情
async getOrderDetails() {
if (!this.isPageActive) {
common_vendor.index.__f__("log", "at pages/return/index.vue:250", "页面已不活跃,跳过订单详情请求");
return;
}
try {
common_vendor.index.showLoading({ title: "加载中" });
if (!this.orderInfo.orderId) {
throw new Error("订单ID不能为空");
}
common_vendor.index.__f__("log", "at pages/return/index.vue:216", "请求订单详情, orderId:", this.orderInfo.orderId);
common_vendor.index.__f__("log", "at pages/return/index.vue:261", "请求订单详情, orderId:", this.orderInfo.orderId);
const result = await config_user.queryById(this.orderInfo.orderId);
common_vendor.index.__f__("log", "at pages/return/index.vue:218", "订单详情结果:", JSON.stringify(result));
common_vendor.index.__f__("log", "at pages/return/index.vue:263", "订单详情结果:", JSON.stringify(result));
if (result.code === 200 && result.data) {
const orderData = result.data;
common_vendor.index.__f__("log", "at pages/return/index.vue:222", "订单原始数据:", orderData);
common_vendor.index.__f__("log", "at pages/return/index.vue:223", "开始时间字段:", orderData.startTime, typeof orderData.startTime);
common_vendor.index.__f__("log", "at pages/return/index.vue:267", "订单原始数据:", orderData);
common_vendor.index.__f__("log", "at pages/return/index.vue:268", "开始时间字段:", orderData.startTime, typeof orderData.startTime);
if (orderData.orderStatus) {
this.orderInfo.orderStatus = orderData.orderStatus;
}
@@ -129,12 +158,12 @@ const _sfc_main = {
return;
}
this.updateOrderInfo(orderData);
common_vendor.index.__f__("log", "at pages/return/index.vue:245", "更新后的开始时间:", this.orderInfo.startTime);
common_vendor.index.__f__("log", "at pages/return/index.vue:290", "更新后的开始时间:", this.orderInfo.startTime);
} else {
throw new Error(result.msg || "获取订单详情失败");
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/return/index.vue:250", "获取订单详情错误:", error);
common_vendor.index.__f__("error", "at pages/return/index.vue:295", "获取订单详情错误:", error);
common_vendor.index.showToast({
title: error.message || "获取订单信息失败",
icon: "none"
@@ -157,7 +186,7 @@ const _sfc_main = {
},
// 使用后端返回的使用时长和费用数据
updateOrderInfo(orderData) {
common_vendor.index.__f__("log", "at pages/return/index.vue:278", "更新订单信息:", JSON.stringify(orderData));
common_vendor.index.__f__("log", "at pages/return/index.vue:323", "更新订单信息:", JSON.stringify(orderData));
this.orderInfo.usedTime = orderData.usedTime || "0分钟";
this.orderInfo.currentFee = orderData.currentFee || orderData.actualDeviceAmount || orderData.payAmount || "0.00";
if (orderData.orderStatus) {
@@ -166,16 +195,16 @@ const _sfc_main = {
this.orderInfo._rawStartTime = orderData.startTime;
if (orderData.startTime) {
try {
common_vendor.index.__f__("log", "at pages/return/index.vue:297", "API返回的开始时间:", orderData.startTime);
common_vendor.index.__f__("log", "at pages/return/index.vue:342", "API返回的开始时间:", orderData.startTime);
this.orderInfo.startTime = orderData.startTime;
} catch (e) {
common_vendor.index.__f__("error", "at pages/return/index.vue:301", "更新开始时间错误:", e);
common_vendor.index.__f__("error", "at pages/return/index.vue:346", "更新开始时间错误:", e);
this.orderInfo.startTime = "未知";
}
} else {
common_vendor.index.__f__("warn", "at pages/return/index.vue:305", "API返回的订单数据中没有startTime字段");
common_vendor.index.__f__("warn", "at pages/return/index.vue:350", "API返回的订单数据中没有startTime字段");
if (orderData.createTime) {
common_vendor.index.__f__("log", "at pages/return/index.vue:308", "使用createTime作为备选:", orderData.createTime);
common_vendor.index.__f__("log", "at pages/return/index.vue:353", "使用createTime作为备选:", orderData.createTime);
this.orderInfo.startTime = orderData.createTime;
} else {
this.orderInfo.startTime = "未知";
@@ -187,15 +216,24 @@ const _sfc_main = {
},
// 更新使用时长的定时器
startTimer() {
this.clearTimer();
this.timer = setInterval(() => {
this.getOrderDetails();
if (this.isPageActive) {
common_vendor.index.__f__("log", "at pages/return/index.vue:375", "执行定时更新订单信息");
this.getOrderDetails();
} else {
common_vendor.index.__f__("log", "at pages/return/index.vue:378", "页面已不活跃,停止计时器");
this.clearTimer();
}
}, 6e4);
common_vendor.index.__f__("log", "at pages/return/index.vue:383", "已启动使用时长更新计时器");
},
// 清除定时器
clearTimer() {
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
common_vendor.index.__f__("log", "at pages/return/index.vue:391", "已清除使用时长更新计时器");
}
},
// 清除状态检查定时器
@@ -203,6 +241,7 @@ const _sfc_main = {
if (this.statusCheckTimer) {
clearInterval(this.statusCheckTimer);
this.statusCheckTimer = null;
common_vendor.index.__f__("log", "at pages/return/index.vue:400", "已清除归还状态检查计时器");
}
},
// 开始状态检查定时器
@@ -210,22 +249,28 @@ const _sfc_main = {
this.currentStatusChecks = 0;
this.clearStatusCheckTimer();
this.statusCheckTimer = setInterval(() => {
this.currentStatusChecks++;
this.checkReturnStatus();
if (this.currentStatusChecks >= this.maxStatusChecks) {
if (this.isPageActive) {
this.currentStatusChecks++;
common_vendor.index.__f__("log", "at pages/return/index.vue:414", `执行归还状态检查 (${this.currentStatusChecks}/${this.maxStatusChecks})`);
this.checkReturnStatus();
if (this.currentStatusChecks >= this.maxStatusChecks) {
this.clearStatusCheckTimer();
common_vendor.index.showToast({
title: "请手动刷新查看归还状态",
icon: "none",
duration: 3e3
});
}
} else {
common_vendor.index.__f__("log", "at pages/return/index.vue:429", "页面已不活跃,停止状态检查计时器");
this.clearStatusCheckTimer();
common_vendor.index.showToast({
title: "请手动刷新查看归还状态",
icon: "none",
duration: 3e3
});
}
}, this.statusCheckInterval);
common_vendor.index.__f__("log", "at pages/return/index.vue:434", "已启动归还状态检查计时器");
},
// 通过设备号查询使用中的订单
async getOrderByDevice() {
try {
common_vendor.index.showLoading({ title: "加载中" });
if (!this.deviceId) {
throw new Error("设备号不能为空");
}
@@ -237,16 +282,16 @@ const _sfc_main = {
"Clientid": common_vendor.index.getStorageSync("client_id")
}
});
common_vendor.index.__f__("log", "at pages/return/index.vue:387", "通过设备号查询订单结果:", JSON.stringify(inUseRes));
common_vendor.index.__f__("log", "at pages/return/index.vue:456", "通过设备号查询订单结果:", JSON.stringify(inUseRes));
if (inUseRes.statusCode === 200 && inUseRes.data.code === 200 && inUseRes.data.data) {
const inUseOrder = inUseRes.data.data;
common_vendor.index.__f__("log", "at pages/return/index.vue:391", "使用中的订单:", inUseOrder);
common_vendor.index.__f__("log", "at pages/return/index.vue:460", "使用中的订单:", inUseOrder);
this.orderInfo.orderId = inUseOrder.orderId;
if (inUseOrder.orderStatus) {
this.orderInfo.orderStatus = inUseOrder.orderStatus;
}
if (inUseOrder.startTime) {
common_vendor.index.__f__("log", "at pages/return/index.vue:403", "inUse API返回的开始时间:", inUseOrder.startTime);
common_vendor.index.__f__("log", "at pages/return/index.vue:472", "inUse API返回的开始时间:", inUseOrder.startTime);
this.orderInfo.startTime = inUseOrder.startTime;
}
this.getOrderDetails();
@@ -256,7 +301,7 @@ const _sfc_main = {
throw new Error("未找到使用中的订单");
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/return/index.vue:417", "通过设备号查询订单失败:", error);
common_vendor.index.__f__("error", "at pages/return/index.vue:486", "通过设备号查询订单失败:", error);
common_vendor.index.showToast({
title: error.message || "获取订单信息失败",
icon: "none"
@@ -271,9 +316,11 @@ const _sfc_main = {
// 检查归还状态
async checkReturnStatus() {
try {
await this.getOrderDetails();
if (this.isPageActive) {
await this.getOrderDetails();
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/return/index.vue:437", "检查归还状态失败:", error);
common_vendor.index.__f__("error", "at pages/return/index.vue:509", "检查归还状态失败:", error);
}
},
// 返回首页