Kaynağa Gözat

perf: 解决合并冲突

kuns 4 hafta önce
ebeveyn
işleme
4b7cfa488a

+ 121 - 123
app.json

@@ -1,26 +1,119 @@
 {
-  "expo": {
-    "name": "Crazy Charge",
-    "slug": "template",
-    "version": "1.3.15",
-    "orientation": "portrait",
-    "icon": "./assets/CC_Logo.png",
-    "userInterfaceStyle": "light",
-    "scheme": "ccscheme",
-    "splash": {
-      "image": "./assets/splash.png",
-      "resizeMode": "contain",
-      "backgroundColor": "#02677D"
-    },
-    "assetBundlePatterns": [
-      "**/*"
-    ],
-    "ios": {
-      "supportsTablet": false,
-      "bundleIdentifier": "hk.ayf.crazycharge",
-      "infoPlist": {
-        "LSApplicationQueriesSchemes": [
-          "whatsapp"
+    "expo": {
+        "name": "Crazy Charge",
+        "slug": "template",
+        "version": "1.3.16",
+        "orientation": "portrait",
+        "icon": "./assets/CC_Logo.png",
+        "userInterfaceStyle": "light",
+        "scheme": "ccscheme",
+        "splash": {
+            "image": "./assets/splash.png",
+            "resizeMode": "contain",
+            "backgroundColor": "#02677D"
+        },
+        "assetBundlePatterns": ["**/*"],
+        "ios": {
+            "supportsTablet": false,
+            "bundleIdentifier": "hk.ayf.crazycharge",
+            "infoPlist": {
+                "LSApplicationQueriesSchemes": ["whatsapp"],
+                "UIBackgroundModes": ["remote-notification"],
+                "CFBundleAllowMixedLocalizations": true,
+                "NSAppTransportSecurity": {
+                    "NSExceptionDomains": {
+                        "exp.direct": {
+                            "NSIncludesSubdomains": true,
+                            "NSExceptionAllowsInsecureHTTPLoads": true
+                        }
+                    }
+                },
+                "ITSAppUsesNonExemptEncryption": false
+            },
+            "config": {
+                "googleMapsApiKey": "process.env.GOOGLE_MAPS_API_KEY"
+            }
+        },
+        "android": {
+            "adaptiveIcon": {
+                "foregroundImage": "./assets/cc_android_ccLogo.png",
+                "backgroundColor": "#000000"
+            },
+            "icon": "./assets/cc_android_ccLogo.png",
+
+            "permissions": [
+                "android.permission.INTERNET",
+                "android.permission.CAMERA",
+                "android.permission.RECORD_AUDIO",
+                "android.permission.ACCESS_COARSE_LOCATION",
+                "android.permission.ACCESS_FINE_LOCATION"
+            ],
+            "package": "hk.ayf.crazycharge",
+            "versionCode": 30,
+            "googleServicesFile": "./google-services.json",
+            "config": {
+                "googleMaps": {
+                    "apiKey": "process.env.GOOGLE_MAPS_API_KEY"
+                }
+            }
+        },
+        "web": {
+            "bundler": "metro",
+            "favicon": "./assets/favicon.png"
+        },
+        "plugins": [
+            [
+                "expo-notifications",
+                {
+                    "icon": "./assets/cc_android_notification_icon.png",
+                    "color": "#02677D"
+                }
+            ],
+            "expo-router",
+            "expo-secure-store",
+            [
+                "expo-camera",
+                {
+                    "cameraPermission": "我們需要相機權限來掃描機器上的二維碼,以便識別並啟動充電機器。我們不會儲存或共享任何掃描到的資訊。",
+                    "microphonePermission": "我們需要麥克風權限來允許語音輸入,以便提供更好的充電體驗。我們不會儲存或共享任何錄製到的資訊。",
+                    "recordAudioAndroid": true
+                }
+            ],
+            [
+                "expo-location",
+                {
+                    "locationAlwaysAndWhenInUsePermission": "我們需要您的位置資訊來尋找附近的充電站。您的位置資訊只會被用於尋找充電站。我們不會儲存或共享任何資訊",
+                    "locationAlwaysPermission": "我們需要您的位置資訊來尋找附近的充電站。您的位置資訊只會被用於尋找充電站。我們不會儲存或共享任何資訊",
+                    "locationWhenInUsePermission": "我們需要您的位置資訊來尋找附近的充電站。您的位置資訊只會被用於尋找充電站。我們不會儲存或共享任何資訊"
+                }
+            ],
+            [
+                "expo-font",
+                {
+                "android": {
+                    "fonts": [
+                            {
+                                "fontFamily": "Roboto-Bold",
+                                "fontDefinitions": [
+                                {
+                                    "path": "./assets/fonts/Roboto-Bold.ttf",
+                                    "weight": 800
+                                }
+                                ]
+                            },
+                            {
+                                "fontFamily": "Roboto-Regular",
+                                "fontDefinitions": [
+                                {
+                                    "path": "./assets/fonts/Roboto-Regular.ttf",
+                                    "weight": 400
+                                }
+                                ]
+                            }
+                        ]
+                    }
+                }
+            ]
         ],
         "UIBackgroundModes": [
           "remote-notification"
@@ -35,105 +128,10 @@
             }
           }
         },
-        "ITSAppUsesNonExemptEncryption": false
-      },
-      "config": {
-        "googleMapsApiKey": "process.env.GOOGLE_MAPS_API_KEY"
-      }
-    },
-    "android": {
-      "adaptiveIcon": {
-        "foregroundImage": "./assets/cc_android_ccLogo.png",
-        "backgroundColor": "#000000"
-      },
-      "icon": "./assets/cc_android_ccLogo.png",
-      "permissions": [
-        "android.permission.INTERNET",
-        "android.permission.CAMERA",
-        "android.permission.RECORD_AUDIO",
-        "android.permission.ACCESS_COARSE_LOCATION",
-        "android.permission.ACCESS_FINE_LOCATION"
-      ],
-      "package": "hk.ayf.crazycharge",
-      "versionCode": 30,
-      "googleServicesFile": "./google-services.json",
-      "config": {
-        "googleMaps": {
-          "apiKey": "process.env.GOOGLE_MAPS_API_KEY"
-        }
-      }
-    },
-    "web": {
-      "bundler": "metro",
-      "favicon": "./assets/favicon.png"
-    },
-    "plugins": [
-      [
-        "expo-notifications",
-        {
-          "icon": "./assets/cc_android_notification_icon.png",
-          "color": "#02677D"
-        }
-      ],
-      "expo-router",
-      "expo-secure-store",
-      [
-        "expo-camera",
-        {
-          "cameraPermission": "我們需要相機權限來掃描機器上的二維碼,以便識別並啟動充電機器。我們不會儲存或共享任何掃描到的資訊。",
-          "microphonePermission": "我們需要麥克風權限來允許語音輸入,以便提供更好的充電體驗。我們不會儲存或共享任何錄製到的資訊。",
-          "recordAudioAndroid": true
-        }
-      ],
-      [
-        "expo-location",
-        {
-          "locationAlwaysAndWhenInUsePermission": "我們需要您的位置資訊來尋找附近的充電站。您的位置資訊只會被用於尋找充電站。我們不會儲存或共享任何資訊",
-          "locationAlwaysPermission": "我們需要您的位置資訊來尋找附近的充電站。您的位置資訊只會被用於尋找充電站。我們不會儲存或共享任何資訊",
-          "locationWhenInUsePermission": "我們需要您的位置資訊來尋找附近的充電站。您的位置資訊只會被用於尋找充電站。我們不會儲存或共享任何資訊"
-        }
-      ],
-      [
-        "expo-font",
-        {
-          "android": {
-            "fonts": [
-              {
-                "fontFamily": "Roboto-Bold",
-                "fontDefinitions": [
-                  {
-                    "path": "./assets/fonts/Roboto-Bold.ttf",
-                    "weight": 800
-                  }
-                ]
-              },
-              {
-                "fontFamily": "Roboto-Regular",
-                "fontDefinitions": [
-                  {
-                    "path": "./assets/fonts/Roboto-Regular.ttf",
-                    "weight": 400
-                  }
-                ]
-              }
-            ]
-          }
-        }
-      ],
-      "expo-localization"
-    ],
-    "extra": {
-      "router": {
-        "origin": false
-      },
-      "eas": {
-        "projectId": "dc6b7a3f-cf92-441a-8962-0f25e8d06902"
-      }
-    },
-    "runtimeVersion": "1.3.15",
-    "updates": {
-      "url": "https://u.expo.dev/dc6b7a3f-cf92-441a-8962-0f25e8d06902"
-    },
-    "owner": "kanff"
-  }
+        "runtimeVersion": "1.3.16",
+        "updates": {
+            "url": "https://u.expo.dev/dc6b7a3f-cf92-441a-8962-0f25e8d06902"
+        },
+        "owner": "kanff"
+    }
 }

+ 2 - 2
component/registrationMultiStepForm/formComponent/formPages/loginPage.tsx

@@ -76,7 +76,6 @@ const LoginPage: React.FC<LoginPageProps> = ({ goToNextPage, goToForgetPassWordP
             if (userTerms) {
                 const isBinding = false;
                 const response = await login(username, password, isBinding);
-
                 if (response) {
                     if (saveAccount) {
                         await AsyncStorage.setItem('savedPhone', username);
@@ -85,8 +84,9 @@ const LoginPage: React.FC<LoginPageProps> = ({ goToNextPage, goToForgetPassWordP
                         await AsyncStorage.removeItem('savedPhone');
                         await AsyncStorage.removeItem('savedPassword');
                     }
+
                 } else {
-                    Alert.alert(t('login.alert.error'), `${t('login.alert.reason')}: ${response}`);
+                    Alert.alert(t('login.alert.error'), `${t('login.alert.reason')}`);
                 }
             } else {
                 Alert.alert(t('login.alert.agree'));

+ 5 - 6
context/AuthProvider.tsx

@@ -77,22 +77,21 @@ export default function AuthProvider({ children }: { children: ReactNode }) {
     const login = async (username: string, password: string, isBinding: boolean) => {
         try {
             const result = await authenticationService.phoneLogin(username, password, isBinding);
-            if (result === 'login successful') {
+            if (result) {
                 const token = await SecureStore.getItemAsync('accessToken');
                 if (token) {
                     const userInfo = await getUserFromAccessToken();
                     if (userInfo) {
                         setUser(userInfo);
-                        return 'login successful';
+                        return true
                     }
                 }
-                return 'login successful';
+                return true;
             } else {
-                return result;
+                return false;
             }
         } catch (error) {
-            console.error('Login error:', error);
-            return error;
+            return false;
         }
     };
 

+ 1 - 1
i18n/locales/en/translation.json

@@ -19,7 +19,7 @@
       "binding2": "I want to bind now",
       "binding3": "I have bound, take me back to login page",
       "error": "Login failed",
-      "reason": "Reason",
+      "reason": "Please enter the correct username and password",
       "agree": "Please agree to the terms of service first"
     }
   },

+ 1 - 1
i18n/locales/zh-TW/translation.json

@@ -19,7 +19,7 @@
       "binding2": "我要進行綁定",
       "binding3": "我已綁定,帶我回登入頁面",
       "error": "登入失敗",
-      "reason": "原因",
+      "reason": "請輸入正確的用戶名跟密碼",
       "agree": "請先同意用戶條款"
     }
   },

+ 34 - 34
service/authService.tsx

@@ -14,20 +14,16 @@ class AuthenticationService {
                     email: username,
                     password: password,
                     isBinding: isBinding,
-                    
                 },
                 {
-                    customConfig: {needAuth: true}
+                    customConfig: {needAuth: false}
                 },
             );
             if (response.status === 201) {
                 const token = response.data.accessToken;
                 await SecureStore.setItemAsync('accessToken', token);
-                console.log('AccessToken', token);
                 return true;
             } else {
-                console.error('Login failed:', response.status);
-
                 return false;
             }
         } catch (error) {
@@ -42,35 +38,23 @@ class AuthenticationService {
     }
 
     async phoneLogin(username: string | null | undefined, password: string, isBinding?: boolean) {
-        try {
-            const response = await apiClient.instance.post(
-                `/public/client/customer/phone/sign-in`,
-                {
-                    phone: username,
-                    password: password,
-                    isBinding: isBinding,
-                    
-                },
-                {
-                
-                    customConfig: {needAuth: true}
-                }
-            );
-            if (response.status === 201) {
-                const token = response.data.accessToken;
-                await SecureStore.setItemAsync('accessToken', token);
-                return 'login successful';
-            } else {
-                return response.data.message;
-            }
-        } catch (error) {
-            if (axios.isAxiosError(error)) {
-                console.error('Login error:', error.response?.data?.message || error.message);
-                return error.response?.data?.message || error.message;
-            } else {
-                console.error('An unexpected error occurred:', error);
-                return 'An unexpected error occurred: ' + error;
+        const response = await apiClient.instance.post(
+            `/public/client/customer/phone/sign-in`,
+            {
+                phone: username,
+                password: password,
+                isBinding: isBinding,
+            },
+            {
+                customConfig: {needAuth: false}
             }
+        );
+        if (response.status === 201) {
+            const token = response.data.accessToken;
+            await SecureStore.setItemAsync('accessToken', token);
+            return true;
+        } else {
+            return false
         }
     }
 
@@ -250,11 +234,14 @@ class AuthenticationService {
         }
     }
 
-    async changePassword(confirmedNewPassword: string, data: string) {
+    async changePassword(confirmedNewPassword: string, token: string | null) {
         try {
             const res = await apiClient.instance.put(
                 `/clients/customer/pw/forget`,
                 { newPassword: confirmedNewPassword },
+                {
+                    customConfig: { token }
+                }
             );
             return true;
         } catch (error) {
@@ -271,6 +258,10 @@ class AuthenticationService {
             const res = await apiClient.instance.put(
                 `/clients/customer`,
                 { email: email },
+                {
+                
+                    customConfig: { token }
+                }
             );
             console.log('Change Name Successfully!');
             return true;
@@ -289,6 +280,9 @@ class AuthenticationService {
             const res = await apiClient.instance.put(
                 `/clients/customer`,
                 { nickname: name },
+                {
+                    customConfig: { token }
+                }
             );
             console.log('Change Name Successfully!');
             return true;
@@ -330,6 +324,9 @@ class AuthenticationService {
             const res = await apiClient.instance.put(
                 `/clients/customer`,
                 { phone: convertPhoneStringToNumber },
+                {
+                    customConfig: { token }
+                }
             );
             return true;
         } catch (error) {
@@ -347,6 +344,9 @@ class AuthenticationService {
             const res = await apiClient.instance.put(
                 `/clients/customer`,
                 { gender: gender },
+                {
+                    customConfig: { token }
+                }
             );
             console.log('Change gender Successfully!');
             return true;

+ 1 - 0
service/conf.ts

@@ -45,6 +45,7 @@ export interface ErrorResponse {
 // 请求配置扩展
 export interface RequestConfig {
   needAuth?: boolean; // 是否需要认证
+  token?: string | null;
   showError?: boolean; // 是否显示错误提示
   retryCount?: number; // 重试次数
 }

+ 8 - 7
service/requets.ts

@@ -1,3 +1,4 @@
+import { Alert } from 'react-native';
 import axios, { 
   AxiosInstance, 
   AxiosRequestConfig, 
@@ -37,13 +38,13 @@ class ApiClient {
     this.instance.interceptors.request.use(
       async (config: InternalAxiosRequestConfig) => {
         const extendedConfig = config as InternalAxiosRequestConfig & { customConfig?: RequestConfig };
-        const { needAuth = true } = extendedConfig.customConfig || {};
+        const { needAuth = true, token = null } = extendedConfig.customConfig || {};
 
         // 添加认证令牌
         if (needAuth) {
-          const token = await SecureStore.getItemAsync('accessToken')
-          if (token) {
-            config.headers.Authorization = `Bearer ${token}`;
+          const tokenStr = token? token : await SecureStore.getItemAsync('accessToken')
+          if (tokenStr) {
+            config.headers.Authorization = `Bearer ${tokenStr}`;
           }
         }
         return config;
@@ -120,7 +121,7 @@ class ApiClient {
         });
       }
     }
-
+    console.log('响应错误:', errorData);
     // 其他错误处理
     const customError: ErrorResponse = {
       code: status,
@@ -182,8 +183,8 @@ class ApiClient {
   // 显示错误提示(可根据实际使用的 Toast 库调整)
   private showErrorToast(message: string): void {
     // 使用你喜欢的 Toast 库,例如 react-native-toast-message
-    // Toast.show({ type: 'error', text1: message });
-    console.error('Error:', message);
+    // Alert.alert('Error', message);
+    // console.error('Error:', message);
   }
 
 }