|
@@ -122,7 +122,7 @@
|
|
|
import { ref, onMounted, onUnmounted } from 'vue';
|
|
import { ref, onMounted, onUnmounted } from 'vue';
|
|
|
import { onShow, onHide } from '@dcloudio/uni-app';
|
|
import { onShow, onHide } from '@dcloudio/uni-app';
|
|
|
import { pollDeviceStatus, pollRecognizeResult, pollOrderInfo } from '../../api/status';
|
|
import { pollDeviceStatus, pollRecognizeResult, pollOrderInfo } from '../../api/status';
|
|
|
-import type { RecognizeResultResponse } from '../../api/status';
|
|
|
|
|
|
|
+import type { RecognizeResultResponse, OrderInfoResponse } from '../../api/status';
|
|
|
|
|
|
|
|
import { logger } from '../../utils/logger';
|
|
import { logger } from '../../utils/logger';
|
|
|
import type { OrderProduct } from '../../api/order';
|
|
import type { OrderProduct } from '../../api/order';
|
|
@@ -228,34 +228,37 @@ const startStatusPolling = async () => {
|
|
|
if (!isComponentActive) {
|
|
if (!isComponentActive) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
// 轮询设备状态,等待关门
|
|
// 轮询设备状态,等待关门
|
|
|
const status = await pollDeviceStatus(currentDeviceId.value, 60000, 3000);
|
|
const status = await pollDeviceStatus(currentDeviceId.value, 60000, 3000);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 再次检查组件是否仍然活跃
|
|
// 再次检查组件是否仍然活跃
|
|
|
if (!isComponentActive) {
|
|
if (!isComponentActive) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
logger.log('设备状态更新:', status);
|
|
logger.log('设备状态更新:', status);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 检查门是否关闭
|
|
// 检查门是否关闭
|
|
|
if (status.doorStatus === 'close') {
|
|
if (status.doorStatus === 'close') {
|
|
|
// 门已关,显示购物完成
|
|
// 门已关,显示购物完成
|
|
|
doorStatus.value = 'closing';
|
|
doorStatus.value = 'closing';
|
|
|
currentActivityId.value = status.activityId;
|
|
currentActivityId.value = status.activityId;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
logger.log('门已关,购物完成,活动ID:', status.activityId);
|
|
logger.log('门已关,购物完成,活动ID:', status.activityId);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 停止选购倒计时
|
|
// 停止选购倒计时
|
|
|
if (countdownTimer) {
|
|
if (countdownTimer) {
|
|
|
clearInterval(countdownTimer);
|
|
clearInterval(countdownTimer);
|
|
|
countdownTimer = null;
|
|
countdownTimer = null;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 开始返回首页倒计时
|
|
// 开始返回首页倒计时
|
|
|
startReturnCountdown();
|
|
startReturnCountdown();
|
|
|
|
|
+
|
|
|
|
|
+ // 轮询订单信息,获取到后跳转到订单完成页
|
|
|
|
|
+ pollOrderAndNavigate();
|
|
|
} else {
|
|
} else {
|
|
|
// 继续等待关门,设置延迟后重新轮询
|
|
// 继续等待关门,设置延迟后重新轮询
|
|
|
if (isComponentActive && doorStatus.value === 'opened') {
|
|
if (isComponentActive && doorStatus.value === 'opened') {
|
|
@@ -268,12 +271,12 @@ const startStatusPolling = async () => {
|
|
|
}
|
|
}
|
|
|
} catch (error: any) {
|
|
} catch (error: any) {
|
|
|
logger.error('状态轮询失败:', error);
|
|
logger.error('状态轮询失败:', error);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 再次检查组件是否仍然活跃
|
|
// 再次检查组件是否仍然活跃
|
|
|
if (!isComponentActive) {
|
|
if (!isComponentActive) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 如果还在开门状态,继续轮询
|
|
// 如果还在开门状态,继续轮询
|
|
|
if (doorStatus.value === 'opened' || doorStatus.value === 'closing') {
|
|
if (doorStatus.value === 'opened' || doorStatus.value === 'closing') {
|
|
|
statusCheckTimer = setTimeout(() => {
|
|
statusCheckTimer = setTimeout(() => {
|
|
@@ -288,6 +291,42 @@ const startStatusPolling = async () => {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 轮询订单信息,获取成功后跳转到订单完成页
|
|
|
|
|
+ */
|
|
|
|
|
+const pollOrderAndNavigate = async () => {
|
|
|
|
|
+ if (!currentActivityId.value) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const orderInfo = await pollOrderInfo(currentActivityId.value, 60000, 2000);
|
|
|
|
|
+
|
|
|
|
|
+ if (!isComponentActive) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ logger.log('订单信息获取成功:', orderInfo);
|
|
|
|
|
+
|
|
|
|
|
+ // 存储订单号,跳转到订单完成页
|
|
|
|
|
+ if (orderInfo.orderId) {
|
|
|
|
|
+ // 清除返回首页倒计时
|
|
|
|
|
+ if (returnCountdownTimer) {
|
|
|
|
|
+ clearInterval(returnCountdownTimer);
|
|
|
|
|
+ returnCountdownTimer = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // TODO: 微信支付分官方页面,暂不跳转
|
|
|
|
|
+ // uni.redirectTo({
|
|
|
|
|
+ // url: '/pages/orderComplete/orderComplete?orderNo=' + orderInfo.orderId
|
|
|
|
|
+ // });
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error: any) {
|
|
|
|
|
+ logger.error('轮询订单信息失败:', error);
|
|
|
|
|
+ // 订单信息获取失败不影响用户,保持当前页面
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
const showProblem = () => {
|
|
const showProblem = () => {
|
|
|
uni.showActionSheet({
|
|
uni.showActionSheet({
|
|
|
itemList: ['辅助远程开门', '报修'],
|
|
itemList: ['辅助远程开门', '报修'],
|