소스 검색

fix 微信扫一扫

wzh 9 시간 전
부모
커밋
beac34403a
1개의 변경된 파일81개의 추가작업 그리고 17개의 파일을 삭제
  1. 81 17
      pages/hexiao/ywy/scan_code.vue

+ 81 - 17
pages/hexiao/ywy/scan_code.vue

@@ -6,10 +6,15 @@
 
     <view class="scan-result-card">
       <view class="card-header">
-        <uni-icons type="scan" size="20" color="#333"></uni-icons>
-        <text class="header-title">已扫二维码</text>
-        <view class="count-badge">
-          <text>总数:{{ totalCount }}个</text>
+        <view class="header-left">
+          <uni-icons type="scan" size="20" color="#333"></uni-icons>
+          <text class="header-title">已扫二维码</text>
+        </view>
+        <view class="header-actions">
+          <view class="count-badge">
+            <text>总数:{{ totalCount }}个</text>
+          </view>
+          <button class="wx-scan-btn" @click="scanWithWeChat">微信扫一扫</button>
         </view>
       </view>
 
@@ -114,19 +119,7 @@ export default {
     },
     // 3. 处理相机扫码成功的事件
     onScanCodeSuccess(e) {
-      let code = e.detail.result;
-      console.log('扫描到的内容:', code);
-      if(code.length != "https://e.dnzc.vip/abce563011c5347f".length){
-        uni.showToast({
-          title: '二维码有误',
-          icon: 'none'
-        });
-        return;
-      }
-      let index = code.lastIndexOf("/");
-      code = code.substr(index+1);
-      this.getCodeNumber(code)
-
+      this.processScanResult(e.detail.result);
     },
 
     // 相机初始化失败
@@ -203,6 +196,53 @@ export default {
           }
         })
       }
+    },
+    processScanResult(rawCode) {
+      const content = (rawCode || '').trim();
+      if (!content) {
+        uni.showToast({
+          title: '二维码有误',
+          icon: 'none'
+        });
+        return;
+      }
+      const targetLength = 'abce563011c5347f'.length;
+      let code = content;
+      const index = code.lastIndexOf('/');
+      if (index !== -1) {
+        code = code.substring(index + 1);
+      }
+      if (code.length !== targetLength) {
+        uni.showToast({
+          title: '二维码有误',
+          icon: 'none'
+        });
+        return;
+      }
+      this.getCodeNumber(code);
+    },
+
+    scanWithWeChat() {
+      // #ifdef MP-WEIXIN
+      wx.scanCode({
+        scanType: ['qrCode'],
+        success: (res) => {
+          this.processScanResult(res.result || res.path || '');
+        },
+        fail: () => {
+          uni.showToast({
+            title: '微信扫一扫失败',
+            icon: 'none'
+          });
+        }
+      });
+      // #endif
+      // #ifndef MP-WEIXIN
+      uni.showToast({
+        title: '当前环境不支持微信扫一扫',
+        icon: 'none'
+      });
+      // #endif
     }
   }
 }
@@ -239,12 +279,36 @@ export default {
 .card-header {
   display: flex;
   align-items: center;
+  justify-content: space-between;
   padding-bottom: 25rpx;
   border-bottom: 1rpx solid #f0f0f0;
   // 头部高度固定,不参与flex缩放
   flex-shrink: 0;
 }
 
+.header-left {
+  display: flex;
+  align-items: center;
+  gap: 15rpx;
+}
+
+.header-actions {
+  display: flex;
+  align-items: center;
+  gap: 16rpx;
+}
+
+.wx-scan-btn {
+  margin: 0;
+  padding: 0 24rpx;
+  height: 60rpx;
+  line-height: 60rpx;
+  border-radius: 30rpx;
+  background-color: #07c160;
+  color: #ffffff;
+  font-size: 26rpx;
+}
+
 .header-title {
   font-size: 32rpx;
   font-weight: bold;