feat: 新增多个页面及功能,优化用户体验
在项目中新增了多个页面,包括押金页面、设备详情页面、反馈页面和帮助页面。同时,更新了订单支付和归还成功页面的逻辑,确保用户在支付和归还设备时能够获得清晰的反馈。优化了扫码和订单状态处理逻辑,提升了整体用户体验。
This commit is contained in:
+63
-23
@@ -7,34 +7,56 @@ class OrderMonitor {
|
||||
this.timer = null;
|
||||
this.checkInterval = 1e4;
|
||||
this.isRunning = false;
|
||||
this.currentPage = null;
|
||||
}
|
||||
/**
|
||||
* 添加订单到监控队列
|
||||
* @param {Object} orderData 订单数据对象,必须包含orderId字段
|
||||
* @param {String} pageName 关联的页面名称,默认为'return'
|
||||
*/
|
||||
addOrder(orderData) {
|
||||
addOrder(orderData, pageName = "return") {
|
||||
if (!orderData || !orderData.orderId) {
|
||||
common_vendor.index.__f__("error", "at utils/orderMonitor.js:21", "添加订单监控失败:无效的订单数据");
|
||||
common_vendor.index.__f__("error", "at utils/orderMonitor.js:23", "添加订单监控失败:无效的订单数据");
|
||||
return;
|
||||
}
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:25", "添加订单到监控队列:", orderData.orderId);
|
||||
this.activeOrders.set(orderData.orderId, orderData);
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:27", `添加订单到监控队列: ${orderData.orderId}, 页面: ${pageName}`);
|
||||
this.activeOrders.set(orderData.orderId, {
|
||||
...orderData,
|
||||
pageName
|
||||
});
|
||||
if (!this.isRunning) {
|
||||
this.start();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 移除订单的监控
|
||||
* @param {String} orderId 订单ID
|
||||
* @param {Object} params 包含orderId或pageName的对象
|
||||
*/
|
||||
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();
|
||||
removeOrder(params) {
|
||||
if (!params)
|
||||
return;
|
||||
if (params.orderId && this.activeOrders.has(params.orderId)) {
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:48", "从监控队列移除订单:", params.orderId);
|
||||
this.activeOrders.delete(params.orderId);
|
||||
} else if (params.pageName) {
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:53", "从监控队列移除页面相关订单:", params.pageName);
|
||||
for (const [orderId, data] of this.activeOrders.entries()) {
|
||||
if (data.pageName === params.pageName) {
|
||||
this.activeOrders.delete(orderId);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.activeOrders.size === 0) {
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 设置当前活跃页面
|
||||
* @param {String} pageName 页面名称
|
||||
*/
|
||||
setActivePage(pageName) {
|
||||
this.currentPage = pageName;
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:73", "设置当前活跃页面:", pageName);
|
||||
}
|
||||
/**
|
||||
* 启动监控服务
|
||||
@@ -42,7 +64,7 @@ class OrderMonitor {
|
||||
start() {
|
||||
if (this.isRunning)
|
||||
return;
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:56", "启动订单监控服务");
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:82", "启动订单监控服务");
|
||||
this.isRunning = true;
|
||||
this.checkOrders();
|
||||
this.timer = setInterval(() => {
|
||||
@@ -55,7 +77,7 @@ class OrderMonitor {
|
||||
stop() {
|
||||
if (!this.isRunning)
|
||||
return;
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:71", "停止订单监控服务");
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:97", "停止订单监控服务");
|
||||
this.isRunning = false;
|
||||
if (this.timer) {
|
||||
clearInterval(this.timer);
|
||||
@@ -68,12 +90,18 @@ class OrderMonitor {
|
||||
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()) {
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:112", `检查 ${this.activeOrders.size} 个活跃订单状态, 当前页面: ${this.currentPage}`);
|
||||
for (const [orderId, data] of this.activeOrders.entries()) {
|
||||
try {
|
||||
await this.checkOrderStatus(orderId);
|
||||
if (!data.pageName || data.pageName === "return") {
|
||||
if (this.currentPage === "return" || this.currentPage === null) {
|
||||
await this.checkOrderStatus(orderId);
|
||||
} else {
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:122", `跳过订单状态检查: ${orderId}, 当前不在归还页面`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
common_vendor.index.__f__("error", "at utils/orderMonitor.js:92", `检查订单状态失败: ${orderId}`, error);
|
||||
common_vendor.index.__f__("error", "at utils/orderMonitor.js:126", `检查订单状态失败: ${orderId}`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,13 +111,18 @@ class OrderMonitor {
|
||||
*/
|
||||
async checkOrderStatus(orderId) {
|
||||
try {
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:103", `检查订单 ${orderId} 的状态`);
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:137", `检查订单 ${orderId} 的状态`);
|
||||
const result = await config_user.queryById(orderId);
|
||||
if (result.code === 200 && result.data) {
|
||||
const orderData = result.data;
|
||||
this.activeOrders.set(orderId, orderData);
|
||||
const existingData = this.activeOrders.get(orderId);
|
||||
const pageName = existingData ? existingData.pageName : null;
|
||||
this.activeOrders.set(orderId, {
|
||||
...orderData,
|
||||
pageName
|
||||
});
|
||||
if (orderData.orderStatus === "used_done" || orderData.orderStatus === "used_down") {
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:114", `订单 ${orderId} 已完成!`);
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:153", `订单 ${orderId} 已完成!`);
|
||||
common_vendor.index.$emit("orderCompleted", orderData);
|
||||
common_vendor.index.showToast({
|
||||
title: "充电宝归还成功",
|
||||
@@ -99,7 +132,7 @@ class OrderMonitor {
|
||||
const innerAudioContext = common_vendor.index.createInnerAudioContext();
|
||||
innerAudioContext.src = "/static/audio/return_success.mp3";
|
||||
innerAudioContext.play();
|
||||
this.removeOrder(orderId);
|
||||
this.removeOrder({ orderId });
|
||||
setTimeout(() => {
|
||||
common_vendor.index.showModal({
|
||||
title: "归还成功",
|
||||
@@ -117,16 +150,23 @@ class OrderMonitor {
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
common_vendor.index.__f__("error", "at utils/orderMonitor.js:153", `检查订单 ${orderId} 状态出错:`, error);
|
||||
common_vendor.index.__f__("error", "at utils/orderMonitor.js:192", `检查订单 ${orderId} 状态出错:`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
const orderMonitor = new OrderMonitor();
|
||||
common_vendor.index.onAppRoute((route) => {
|
||||
const pagePath = route.path || "";
|
||||
const pageSegments = pagePath.split("/");
|
||||
const pageName = pageSegments[pageSegments.length - 1];
|
||||
orderMonitor.setActivePage(pageName || null);
|
||||
common_vendor.index.__f__("log", "at utils/orderMonitor.js:209", "页面切换:", pagePath, "当前活跃页面:", pageName);
|
||||
});
|
||||
const initOrderMonitor = () => {
|
||||
const lastActiveOrderId = common_vendor.index.getStorageSync("activeOrderId");
|
||||
if (lastActiveOrderId) {
|
||||
const lastOrderData = { orderId: lastActiveOrderId };
|
||||
orderMonitor.addOrder(lastOrderData);
|
||||
orderMonitor.addOrder(lastOrderData, "return");
|
||||
}
|
||||
};
|
||||
initOrderMonitor();
|
||||
|
||||
Reference in New Issue
Block a user