Jelajahi Sumber

未登录允许查看柜类商品

skyline 1 bulan lalu
induk
melakukan
4b993c2888

+ 2 - 1
haha-miniapp/src/main/java/com/haha/miniapp/config/SaTokenConfig.java

@@ -30,7 +30,8 @@ public class SaTokenConfig implements WebMvcConfigurer {
         .excludePathPatterns(
             "/login/**",           // 登录接口
             "/health/**",          // 健康检查接口
-            "/callback/**"         // 第三方回调接口
+            "/callback/**",        // 第三方回调接口
+            "/device/products/**"  // 设备商品陈列查询(允许未登录查看)
         );
     }
     

+ 1 - 6
haha-miniapp/src/main/java/com/haha/miniapp/controller/DeviceController.java

@@ -89,10 +89,7 @@ public class DeviceController {
     @GetMapping("/products/{deviceId}")
     public Result<Map<String, Object>> getDeviceProducts(@PathVariable String deviceId) {
         try {
-            // 1. 登录校验
-            StpUtil.getLoginIdAsLong();
-
-            // 2. 查询设备层模板
+            // 查询设备层模板(无需登录,允许未登录用户查看柜内商品)
             LayerTemplate template = layerTemplateService.getByDeviceId(deviceId);
             if (template == null) {
                 return Result.error(404, "该设备暂无商品信息");
@@ -135,8 +132,6 @@ public class DeviceController {
 
             return Result.success("查询成功", result);
 
-        } catch (cn.dev33.satoken.exception.NotLoginException e) {
-            return Result.error(401, "登录已失效,请重新登录");
         } catch (Exception e) {
             log.error("查询设备商品信息异常, deviceId={}", deviceId, e);
             return Result.error(500, "查询失败,请稍后重试");

+ 59 - 33
haha-mp/src/pages/products/products.vue

@@ -15,15 +15,6 @@
 
     <!-- 商品内容 -->
     <view v-else class="content">
-      <!-- 顶部设备信息 -->
-      <view class="device-header">
-        <view class="device-name">{{ templateName || '智能零售柜' }}</view>
-        <view class="device-info">
-          <text class="info-tag">{{ deviceTypeText }}</text>
-          <text class="info-tag">共{{ shelfNum }}层</text>
-        </view>
-      </view>
-
       <!-- 双门柜Tab切换 -->
       <view v-if="hasRightDoor" class="door-tabs">
         <view
@@ -120,6 +111,8 @@
 import { ref, computed } from 'vue';
 import { onLoad } from '@dcloudio/uni-app';
 import { getDeviceProducts, scanDoor } from '@/api/device';
+import { checkPayscoreEnabled } from '@/api/payscore';
+import { isLoggedIn } from '@/utils/auth';
 import type { FloorConfig } from '@/api/device';
 
 // 页面参数
@@ -156,8 +149,30 @@ const currentFloors = computed(() => {
 
 // 页面加载
 onLoad((options: any) => {
+  let id = '';
+
   if (options?.deviceId) {
-    deviceId.value = options.deviceId;
+    // 普通页面跳转传参
+    id = options.deviceId;
+  } else if (options?.q) {
+    // 微信扫码调起小程序,链接通过 q 参数传入(URL编码)
+    // 链接格式: https://dev-haha.kuaiyuman.cn/B150534
+    try {
+      const url = decodeURIComponent(options.q);
+      console.log('扫码链接:', url);
+      // 从 URL 路径中提取设备ID
+      const match = url.match(/\/([A-Za-z0-9]+)(?:\?|$)/);
+      if (match && match[1]) {
+        id = match[1];
+      }
+    } catch (e) {
+      console.error('解析扫码链接失败:', e);
+    }
+  }
+
+  if (id) {
+    console.log('设备ID:', id);
+    deviceId.value = id;
     loadProducts();
   } else {
     errorMsg.value = '缺少设备ID参数';
@@ -188,6 +203,40 @@ const loadProducts = async () => {
 // 开门购物
 const handleOpenDoor = async () => {
   if (opening.value) return;
+
+  // 1. 登录校验
+  if (!isLoggedIn()) {
+    uni.showModal({
+      title: '提示',
+      content: '请先登录后再开门购物',
+      showCancel: false,
+      success: () => {
+        uni.reLaunch({
+          url: '/pages/login/login?redirect=/pages/products/products?deviceId=' + deviceId.value
+        });
+      }
+    });
+    return;
+  }
+
+  // 2. 支付分校验
+  try {
+    const payscoreResult = await checkPayscoreEnabled();
+    if (!payscoreResult.enabled) {
+      uni.navigateTo({
+        url: '/pages/payscore/enable'
+      });
+      return;
+    }
+  } catch (error: any) {
+    console.error('检查支付分状态失败:', error);
+    uni.navigateTo({
+      url: '/pages/payscore/enable'
+    });
+    return;
+  }
+
+  // 3. 执行开门
   opening.value = true;
 
   uni.showLoading({
@@ -300,29 +349,6 @@ const goBack = () => {
   font-weight: bold;
 }
 
-/* 设备信息头部 */
-.device-header {
-  background: linear-gradient(135deg, #FFD700, #FFA500);
-  padding: 30rpx;
-  color: #333;
-}
-.device-name {
-  font-size: 36rpx;
-  font-weight: bold;
-}
-.device-info {
-  display: flex;
-  gap: 16rpx;
-  margin-top: 12rpx;
-}
-.info-tag {
-  font-size: 24rpx;
-  background: rgba(255,255,255,0.5);
-  padding: 4rpx 16rpx;
-  border-radius: 20rpx;
-  color: #555;
-}
-
 /* 门Tab切换 */
 .door-tabs {
   display: flex;