浏览代码

fix: 修复安卓端扫不了码的问题

zengkunsen 4 月之前
父节点
当前提交
14e7f4aa71
共有 1 个文件被更改,包括 13 次插入33 次删除
  1. 13 33
      app/(auth)/(tabs)/(home)/scanQrPage.tsx

+ 13 - 33
app/(auth)/(tabs)/(home)/scanQrPage.tsx

@@ -11,7 +11,8 @@ import {
     StyleSheet,
     Text,
     Vibration,
-    View
+    View,
+    Platform,
 } from 'react-native';
 import sha256 from 'crypto-js/sha256';
 import ChooseCarForChargingRow from '../../../../component/global/chooseCarForChargingRow';
@@ -120,30 +121,6 @@ const ScanQrPage = () => {
         getWalletBalance();
     }, []);
 
-    const fetchCurrentPrice = async () => {
-        try {
-            const response = await chargeStationService.getCurrentPrice();
-            if (response) {
-                setCurrentPriceFetchedWhenScanQr(response);
-                setCurrentPrice(response);
-                return response;
-            }
-        } catch (error) {
-            console.error('Error fetching current price:', error);
-            Alert.alert('錯誤', '無法獲取當前價格,請稍後再試');
-            return null;
-        }
-    };
-
-    const planMap = {
-        // 3: { duration: 10, kWh: 3, displayDuration: 5, fee: 3 * currentPrice },
-        25: { duration: 40, kWh: 20, displayDuration: 25, fee: 20 * currentPrice },
-        30: { duration: 45, kWh: 25, displayDuration: 30, fee: 25 * currentPrice },
-        40: { duration: 55, kWh: 30, displayDuration: 40, fee: 30 * currentPrice },
-        45: { duration: 60, kWh: 40, displayDuration: 45, fee: 40 * currentPrice },
-        full: { duration: 120, displayDuration: '充滿停機', fee: 80 * currentPrice }
-    };
-
     // Function to handle barcode scanning
     const handleBarCodeScanned = async ({ bounds, data, type }: { bounds?: any; data: any; type: any }) => {
         if (
@@ -159,7 +136,7 @@ const ScanQrPage = () => {
             //after scanning, immediately fetch the correct station id and push to optionPage
             try {
                 const stationId = await chargeStationService.noImagefetchChargeStationIdByScannedConnectorId(data);
-                console.log('stationId', stationId);
+
                 if (!stationId) {
                     Alert.alert('錯誤', '無法找到充電站,請稍後再嘗試');
                     setTimeout(() => {
@@ -188,19 +165,22 @@ const ScanQrPage = () => {
         const transparentAreaY = (screenHeight - transparentAreaSize) / 2;
 
         // Check if the barcode is within the transparent area
-        if (
-            origin.x >= transparentAreaX &&
-            origin.y >= transparentAreaY &&
-            origin.x + size.width <= transparentAreaX + transparentAreaSize &&
-            origin.y + size.height <= transparentAreaY + transparentAreaSize
-        ) {
+        // 在iOS上检查二维码是否在扫描框内,在安卓上跳过位置检查
+          const isIOS = Platform.OS === 'ios';
+          const isWithinScanArea = isIOS ? (
+              origin.x >= transparentAreaX &&
+              origin.y >= transparentAreaY &&
+              origin.x + size.width <= transparentAreaX + transparentAreaSize &&
+              origin.y + size.height <= transparentAreaY + transparentAreaSize
+          ) : true;
+          
+          if (isWithinScanArea) {
             setScanned(true);
             setScannedQrCode(data);
             Vibration.vibrate(100);
             //after scanning, immediately fetch the correct station id and push to optionPage
             try {
                 const stationId = await chargeStationService.noImagefetchChargeStationIdByScannedConnectorId(data);
-                console.log('stationId', stationId);
                 if (!stationId) {
                     Alert.alert('錯誤', '無法找到充電站,請稍後再嘗試');
                     setTimeout(() => {