feat: 新增多个页面及功能,优化用户体验
在项目中新增了多个页面,包括押金页面、设备详情页面、反馈页面和帮助页面。同时,更新了订单支付和归还成功页面的逻辑,确保用户在支付和归还设备时能够获得清晰的反馈。优化了扫码和订单状态处理逻辑,提升了整体用户体验。
This commit is contained in:
+134
@@ -0,0 +1,134 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../common/vendor.js");
|
||||
const config_user = require("../config/user.js");
|
||||
class OrderMonitor {
|
||||
constructor() {
|
||||
this.activeOrders = /* @__PURE__ */ new Map();
|
||||
this.timer = null;
|
||||
this.checkInterval = 1e4;
|
||||
this.isRunning = false;
|
||||
}
|
||||
/**
|
||||
* 添加订单到监控队列
|
||||
* @param {Object} orderData 订单数据对象,必须包含orderId字段
|
||||
*/
|
||||
addOrder(orderData) {
|
||||
if (!orderData || !orderData.orderId) {
|
||||
common_vendor.index.__f__("error", "at utils/orderMonitor.js:21", "添加订单监控失败:无效的订单数据");
|
||||
return;
|
||||
}
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:25", "添加订单到监控队列:", orderData.orderId);
|
||||
this.activeOrders.set(orderData.orderId, orderData);
|
||||
if (!this.isRunning) {
|
||||
this.start();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 移除订单的监控
|
||||
* @param {String} orderId 订单ID
|
||||
*/
|
||||
removeOrder(orderId) {
|
||||
if (this.activeOrders.has(orderId)) {
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:40", "从监控队列移除订单:", orderId);
|
||||
this.activeOrders.delete(orderId);
|
||||
if (this.activeOrders.size === 0) {
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 启动监控服务
|
||||
*/
|
||||
start() {
|
||||
if (this.isRunning)
|
||||
return;
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:56", "启动订单监控服务");
|
||||
this.isRunning = true;
|
||||
this.checkOrders();
|
||||
this.timer = setInterval(() => {
|
||||
this.checkOrders();
|
||||
}, this.checkInterval);
|
||||
}
|
||||
/**
|
||||
* 停止监控服务
|
||||
*/
|
||||
stop() {
|
||||
if (!this.isRunning)
|
||||
return;
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:71", "停止订单监控服务");
|
||||
this.isRunning = false;
|
||||
if (this.timer) {
|
||||
clearInterval(this.timer);
|
||||
this.timer = null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 检查所有活跃订单的状态
|
||||
*/
|
||||
async checkOrders() {
|
||||
if (this.activeOrders.size === 0)
|
||||
return;
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:86", `检查 ${this.activeOrders.size} 个活跃订单状态`);
|
||||
for (const [orderId, orderData] of this.activeOrders.entries()) {
|
||||
try {
|
||||
await this.checkOrderStatus(orderId);
|
||||
} catch (error) {
|
||||
common_vendor.index.__f__("error", "at utils/orderMonitor.js:92", `检查订单状态失败: ${orderId}`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 检查单个订单的状态
|
||||
* @param {String} orderId 订单ID
|
||||
*/
|
||||
async checkOrderStatus(orderId) {
|
||||
try {
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:103", `检查订单 ${orderId} 的状态`);
|
||||
const result = await config_user.queryById(orderId);
|
||||
if (result.code === 200 && result.data) {
|
||||
const orderData = result.data;
|
||||
this.activeOrders.set(orderId, orderData);
|
||||
if (orderData.orderStatus === "used_done" || orderData.orderStatus === "used_down") {
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:114", `订单 ${orderId} 已完成!`);
|
||||
common_vendor.index.$emit("orderCompleted", orderData);
|
||||
common_vendor.index.showToast({
|
||||
title: "充电宝归还成功",
|
||||
icon: "success",
|
||||
duration: 2e3
|
||||
});
|
||||
const innerAudioContext = common_vendor.index.createInnerAudioContext();
|
||||
innerAudioContext.src = "/static/audio/return_success.mp3";
|
||||
innerAudioContext.play();
|
||||
this.removeOrder(orderId);
|
||||
setTimeout(() => {
|
||||
common_vendor.index.showModal({
|
||||
title: "归还成功",
|
||||
content: "充电宝已归还成功,剩余押金将退还到您的账户",
|
||||
confirmText: "查看详情",
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
common_vendor.index.redirectTo({
|
||||
url: `/pages/order/return-success?orderId=${orderId}`
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
common_vendor.index.__f__("error", "at utils/orderMonitor.js:153", `检查订单 ${orderId} 状态出错:`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
const orderMonitor = new OrderMonitor();
|
||||
const initOrderMonitor = () => {
|
||||
const lastActiveOrderId = common_vendor.index.getStorageSync("activeOrderId");
|
||||
if (lastActiveOrderId) {
|
||||
const lastOrderData = { orderId: lastActiveOrderId };
|
||||
orderMonitor.addOrder(lastOrderData);
|
||||
}
|
||||
};
|
||||
initOrderMonitor();
|
||||
exports.orderMonitor = orderMonitor;
|
||||
//# sourceMappingURL=../../.sourcemap/mp-weixin/utils/orderMonitor.js.map
|
||||
Reference in New Issue
Block a user