skyline před 2 měsíci
rodič
revize
4a55d32acf

+ 3 - 1
haha-mp/src/App.vue

@@ -42,9 +42,11 @@ const checkLoginStatus = () => {
   const currentPage = pages[pages.length - 1];
   const currentPath = currentPage ? currentPage.route : '';
   
+  console.log('[App] 检查登录状态 - token:', token ? '已存在' : '不存在', ', 当前页面:', currentPath);
+  
   // 如果没有token且不在登录页,跳转到登录页
   if (!token && currentPath !== 'pages/login/login') {
-    console.log('未登录,跳转到登录页');
+    console.log('[App] 未登录,跳转到登录页');
     uni.reLaunch({
       url: '/pages/login/login'
     });

+ 16 - 0
haha-mp/src/pages/index/index.vue

@@ -39,8 +39,24 @@
 <script setup lang="ts">
 import { ref } from 'vue'
 import { scanDoor } from '../../api/device'
+import { isLoggedIn } from '../../utils/auth'
 
 const scanCode = () => {
+  // 检查登录状态
+  if (!isLoggedIn()) {
+    uni.showModal({
+      title: '提示',
+      content: '请先登录后再扫码开门',
+      showCancel: false,
+      success: () => {
+        uni.reLaunch({
+          url: '/pages/login/login?redirect=/pages/index/index'
+        });
+      }
+    });
+    return;
+  }
+  
   // 调用摄像头扫码
   uni.scanCode({
     success: async function (res) {

+ 52 - 0
haha-mp/src/pages/my/my.vue

@@ -71,6 +71,11 @@
       </view>
     </view>
 
+    <!-- 退出登录按钮 -->
+    <view class="logout-section">
+      <button class="logout-btn" @click="handleLogout">退出登录</button>
+    </view>
+
     <!-- 版本信息 -->
     <view class="version-info">
       v1.62.11
@@ -81,6 +86,8 @@
 <script setup lang="ts">
 import { ref, onMounted } from 'vue';
 import { mockApi } from '../../utils/mock';
+import { logout as logoutApi } from '../../api/user';
+import { clearAuth } from '../../utils/auth';
 
 const userInfo = ref<any>(null);
 
@@ -155,6 +162,27 @@ const goToSettings = () => {
     icon: 'none'
   });
 };
+
+const handleLogout = () => {
+  uni.showModal({
+    title: '提示',
+    content: '确定要退出登录吗?',
+    success: async (res) => {
+      if (res.confirm) {
+        try {
+          await logoutApi();
+        } catch (e) {
+          console.log('退出登录接口调用失败', e);
+        } finally {
+          clearAuth();
+          uni.reLaunch({
+            url: '/pages/login/login'
+          });
+        }
+      }
+    }
+  });
+};
 </script>
 
 <style>
@@ -262,6 +290,30 @@ const goToSettings = () => {
   color: #666666;
 }
 
+/* 退出登录区域 */
+.logout-section {
+  padding: 60rpx 32rpx 20rpx;
+  background-color: #ffffff;
+  display: flex;
+  justify-content: center;
+}
+
+.logout-btn {
+  width: 60%;
+  height: 80rpx;
+  line-height: 80rpx;
+  background-color: #FFD700;
+  border: none;
+  border-radius: 40rpx;
+  color: #333333;
+  font-size: 28rpx;
+  font-weight: 500;
+}
+
+.logout-btn:active {
+  background-color: #E6C200;
+}
+
 /* 版本信息 */
 .version-info {
   padding: 40rpx 0;

+ 35 - 48
haha-mp/src/pages/shopping/shopping.vue

@@ -10,11 +10,13 @@
       <view class="problem-link" @click="showProblem">遇到问题?(如门没开)</view>
     </view>
     
-    <!-- 阶段二:结算中 (门已关) -->
+    <!-- 阶段二:购物完成 (门已关) -->
     <view v-else-if="doorStatus === 'closing'" class="shopping-section">
-      <view class="loading-icon">⏳</view>
-      <view class="status-title">AI正在识别商品,请稍候...</view>
-      <view class="status-tip">预计需要5-15秒</view>
+      <view class="success-icon">✅</view>
+      <view class="status-title">购物已完成</view>
+      <view class="status-tip">订单稍后自动扣款,如有疑问请联系客服</view>
+      <view class="countdown" v-if="returnCountdown > 0">{{ returnCountdown }}秒后返回首页</view>
+      <button class="home-button" @click="goHome">回到首页</button>
     </view>
     
     <!-- 阶段三:结算完成 -->
@@ -53,6 +55,7 @@ import type { RecognizeResultResponse } from '../../api/status';
 
 const doorStatus = ref<'opened' | 'closing' | 'closed' | 'error'>('opened');
 const countdown = ref(60);
+const returnCountdown = ref(5); // 返回首页倒计时
 const purchasedProducts = ref<any[]>([]);
 const totalPrice = ref(0);
 const errorMessage = ref('');
@@ -61,6 +64,7 @@ const currentActivityId = ref('');
 const currentOrderNo = ref('');
 
 let countdownTimer: number | null = null;
+let returnCountdownTimer: number | null = null; // 返回首页倒计时定时器
 let statusCheckTimer: number | null = null;
 let isComponentActive = true; // 组件活跃状态标志
 
@@ -70,6 +74,10 @@ const cleanupTimers = () => {
     clearInterval(countdownTimer);
     countdownTimer = null;
   }
+  if (returnCountdownTimer) {
+    clearInterval(returnCountdownTimer);
+    returnCountdownTimer = null;
+  }
   if (statusCheckTimer) {
     clearTimeout(statusCheckTimer);
     statusCheckTimer = null;
@@ -129,6 +137,20 @@ const startCountdown = () => {
   }, 1000);
 };
 
+// 开始返回首页倒计时
+const startReturnCountdown = () => {
+  returnCountdown.value = 5; // 重置为5秒
+  returnCountdownTimer = setInterval(() => {
+    if (returnCountdown.value > 0) {
+      returnCountdown.value--;
+      if (returnCountdown.value === 0) {
+        // 倒计时结束,自动返回首页
+        goHome();
+      }
+    }
+  }, 1000);
+};
+
 const startStatusPolling = async () => {
   // 检查组件是否仍然活跃
   if (!isComponentActive) {
@@ -148,55 +170,20 @@ const startStatusPolling = async () => {
     
     // 检查门是否关闭
     if (status.doorStatus === 'close') {
-      // 门已关,进入识别阶段
+      // 门已关,显示购物完成
       doorStatus.value = 'closing';
       currentActivityId.value = status.activityId;
       
-      // 开始轮询识别结果
-      const recognizeResult = await pollRecognizeResult(status.activityId, 60000, 1000);
+      console.log('门已关,购物完成,活动ID:', status.activityId);
       
-      // 再次检查组件是否仍然活跃
-      if (!isComponentActive) {
-        return;
+      // 停止选购倒计时
+      if (countdownTimer) {
+        clearInterval(countdownTimer);
+        countdownTimer = null;
       }
       
-      if (recognizeResult) {
-        console.log('识别结果:', recognizeResult);
-        
-        // 开始轮询订单信息
-        const orderInfo = await pollOrderInfo(currentActivityId.value, 30000, 1000);
-        
-        // 再次检查组件是否仍然活跃
-        if (!isComponentActive) {
-          return;
-        }
-        
-        if (orderInfo) {
-          console.log('订单信息:', orderInfo);
-          
-          // 解析商品列表
-          if (orderInfo.products) {
-            try {
-              purchasedProducts.value = JSON.parse(orderInfo.products);
-            } catch (e) {
-              console.error('解析商品列表失败:', e);
-              purchasedProducts.value = [];
-            }
-          }
-          
-          // 设置总价
-          totalPrice.value = parseFloat(orderInfo.totalAmount) || 0;
-          
-          // 进入结算完成阶段
-          doorStatus.value = 'closed';
-          
-          // 停止倒计时
-          if (countdownTimer) {
-            clearInterval(countdownTimer);
-            countdownTimer = null;
-          }
-        }
-      }
+      // 开始返回首页倒计时
+      startReturnCountdown();
     } else {
       // 继续等待关门,设置延迟后重新轮询
       if (isComponentActive && doorStatus.value === 'opened') {
@@ -382,7 +369,7 @@ const goHome = () => {
   color: #FF6B6B;
 }
 
-.view-order-button, .retry-button {
+.view-order-button, .retry-button, .home-button {
   background-color: #FFD700;
   color: #333;
   border: none;