From 0e1ddc385be64cc36bf42ef709b477003f916831 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 18 May 2025 14:20:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=A6=BBapp.tsx=E7=9A=84=E5=B1=8F?= =?UTF-8?q?=E5=B9=95=E7=B1=BB=E5=9E=8B=E5=92=8C=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.tsx | 455 ++------------------ app/navigation/AppNavigator.tsx | 341 +++++++++++++++ app/navigation/screens.ts | 77 ++++ app/navigation/types.ts | 36 +- app/screens/BalanceScreen.tsx | 2 +- app/screens/ChatScreen.tsx | 1 - app/screens/ProfileScreen.tsx | 4 +- app/screens/previewOrder/PaymentMethod.tsx | 3 +- app/screens/previewOrder/PreviewAddress.tsx | 18 +- app/screens/previewOrder/ShippingFee.tsx | 2 + app/store/burialPoint.ts | 325 ++++++++++++++ app/store/previewShipping.ts | 6 +- app/types/react-native-md5.d.ts | 3 + package.json | 3 +- yarn.lock | 5 + 15 files changed, 834 insertions(+), 447 deletions(-) create mode 100644 app/navigation/AppNavigator.tsx create mode 100644 app/navigation/screens.ts create mode 100644 app/store/burialPoint.ts create mode 100644 app/types/react-native-md5.d.ts diff --git a/App.tsx b/App.tsx index 0e13be8..7e45cae 100644 --- a/App.tsx +++ b/App.tsx @@ -1,118 +1,48 @@ import "react-native-gesture-handler"; import React from "react"; import { useEffect, useState } from "react"; -import Toast from "react-native-toast-message"; -import { Alert, ActivityIndicator, View } from "react-native"; import { userApi } from "./app/services/api/userApi"; import useUserStore from "./app/store/user"; -import { NavigationContainer } from "@react-navigation/native"; -import { createNativeStackNavigator } from "@react-navigation/native-stack"; -import { CountrySelect } from "./app/screens/CountrySelect"; -import { MainApp } from "./app/screens/MainApp"; -import { LoginScreen } from "./app/screens/loginList/index"; -import { EmailLoginScreen } from "./app/screens/EmailLoginScreen"; -import { GoogleScreen } from "./app/screens/login/Google"; -import "./app/i18n"; -import { TabNavigator } from "./app/navigation/TabNavigator"; +import useBurialPointStore from "./app/store/burialPoint"; import { AuthProvider, useAuth } from "./app/contexts/AuthContext"; -import { SearchScreen } from "./app/screens/SearchScreen"; -import { SearchResultScreen } from "./app/screens/SearchResultScreen"; -import { ProductDetailScreen } from "./app/screens/ProductDetailScreen"; -import { BalanceScreen } from "./app/screens/BalanceScreen"; -import { ShippingDetailsSection } from "./app/screens/banner/ShippingDetailsSection"; import { GestureHandlerRootView } from "react-native-gesture-handler"; -import { InquiryScreen } from "./app/screens/banner/InquiryScreen"; -import { Recipient } from "./app/screens/Recipient/Recipient"; -import { AddRess } from "./app/screens/Recipient/Address"; -import { SettingList } from "./app/screens/setting/SettingList"; -import { CountrySetting } from "./app/screens/setting/CountrySetting"; -import { MySetting } from "./app/services/api/setting"; -import { MyAddress } from "./app/screens/setting/MyAddress"; -import { CartScreen } from "./app/screens/CartScreen"; -import { PaymentSuccessScreen } from "./app/screens/pay/PaySuccess"; -import { MyAccount } from "./app/screens/MyAccount/myAccount"; -import { ConfirmOrder } from "./app/screens/Recipient/ConfirmOrder"; -import { Pay } from "./app/screens/pay/Pay"; -import { Status } from "./app/screens/productStatus/Status"; -import { OrderDetails } from "./app/screens/productStatus/OrderDatails"; -import { TikTokScreen } from "./app/screens/banner/TikTokScreen"; -import { BrowseHistoryScreen } from "./app/screens/function/BrowseHistoryScreen"; -import { Collection } from "./app/screens/function/Collection"; +import { AppNavigator } from "./app/navigation/AppNavigator"; +import { View, ActivityIndicator } from "react-native"; import AsyncStorage from "@react-native-async-storage/async-storage"; -import { MemberIntroduction } from "./app/screens/MemberScreen/MemberIntroduction"; -import { CompanyScreen } from "./app/screens/MemberScreen/CompanyScreen"; -import { PreviewAddress } from "./app/screens/previewOrder/PreviewAddress"; -import { AddressList } from "./app/screens/address/AddressList"; -import { AddAddress } from "./app/screens/address/AddAddress"; -import { EditAddress } from "./app/screens/address/EditAddress"; -import { PaymentMethod } from "./app/screens/previewOrder/PaymentMethod"; -import { ShippingFee } from "./app/screens/previewOrder/ShippingFee"; -import { PreviewOrder } from "./app/screens/previewOrder/perviewOrder"; -import {ForgotPhonePassword} from "./app/screens/loginList/ForgotPhonePassword"; - -export type RootStackParamList = { - CountrySelect: undefined; - MainApp: undefined; - Login: undefined; - EmailLogin: undefined; - MainTabs: undefined; - Search: undefined; - SearchResult: { keyword: string }; - ProductDetail: { productId: string; searchKeyword?: string }; - Balance: undefined; - ShippingDetailsSection: undefined; - InquiryScreen: undefined; - Recipient: { items: { cart_item_id: number }[] }; - AddRess: undefined; - SettingList: undefined; - CountrySetting: { mySetting?: MySetting }; - MyAddress: undefined; - CartScreen: undefined; - PaymentSuccessScreen: undefined; - MyAccount: undefined; - Google: undefined; - ConfirmOrder: undefined; - Pay: undefined; - Status: undefined; - OrderDetails: undefined; - TikTokScreen: undefined; - BrowseHistoryScreen: undefined; - Collection: undefined; - MemberIntroduction: undefined; - CompanyScreen: undefined; - PreviewAddress: undefined; - AddressList: undefined; - AddAddress: undefined; - EditAddress: undefined; - PaymentMethod: undefined; - ShippingFee: undefined; - PreviewOrder: undefined; - ForgotPhonePassword: undefined, -}; - -const Stack = createNativeStackNavigator(); +import "./app/i18n"; function AppContent() { const { setUser } = useUserStore(); const { login, logout } = useAuth(); + const { logAppLaunch } = useBurialPointStore(); const [isLoading, setIsLoading] = useState(true); - const getUserInfo = async () => { - const token = await AsyncStorage.getItem("token"); - if (token) { + useEffect(() => { + const initApp = async () => { try { - const user = await userApi.getProfile(); - setUser(user); - login(); + const token = await AsyncStorage.getItem("token"); + if (token) { + try { + const user = await userApi.getProfile(); + setUser(user); + login(); + } catch (error) { + console.error('Failed to get user profile:', error); + logout(); + } + } + // 记录应用启动成功埋点 + logAppLaunch(true); } catch (error) { - logout(); + console.error('App initialization error:', error); + // 记录应用启动失败埋点 + logAppLaunch(false); + } finally { + setIsLoading(false); } - } - setIsLoading(false); - }; + }; - useEffect(() => { - getUserInfo(); + initApp(); }, []); if (isLoading) { @@ -123,336 +53,7 @@ function AppContent() { ); } - return ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ); + return ; } export default function App() { diff --git a/app/navigation/AppNavigator.tsx b/app/navigation/AppNavigator.tsx new file mode 100644 index 0000000..63448c2 --- /dev/null +++ b/app/navigation/AppNavigator.tsx @@ -0,0 +1,341 @@ +import React from 'react'; +import { NavigationContainer } from "@react-navigation/native"; +import { createNativeStackNavigator } from "@react-navigation/native-stack"; +import { RootStackParamList } from './types'; +import * as Screens from './screens'; +import Toast from "react-native-toast-message"; + +const Stack = createNativeStackNavigator(); + +export const AppNavigator = () => { + return ( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +}; \ No newline at end of file diff --git a/app/navigation/screens.ts b/app/navigation/screens.ts new file mode 100644 index 0000000..7a2ab6e --- /dev/null +++ b/app/navigation/screens.ts @@ -0,0 +1,77 @@ +import { CountrySelect } from "../screens/CountrySelect"; +import { MainApp } from "../screens/MainApp"; +import { LoginScreen } from "../screens/loginList/index"; +import { EmailLoginScreen } from "../screens/EmailLoginScreen"; +import { TabNavigator } from "./TabNavigator"; +import { SearchScreen } from "../screens/SearchScreen"; +import { SearchResultScreen } from "../screens/SearchResultScreen"; +import { ProductDetailScreen } from "../screens/ProductDetailScreen"; +import { BalanceScreen } from "../screens/BalanceScreen"; +import { ShippingDetailsSection } from "../screens/banner/ShippingDetailsSection"; +import { InquiryScreen } from "../screens/banner/InquiryScreen"; +import { Recipient } from "../screens/Recipient/Recipient"; +import { AddRess } from "../screens/Recipient/Address"; +import { SettingList } from "../screens/setting/SettingList"; +import { CountrySetting } from "../screens/setting/CountrySetting"; +import { MyAddress } from "../screens/setting/MyAddress"; +import { CartScreen } from "../screens/CartScreen"; +import { PaymentSuccessScreen } from "../screens/pay/PaySuccess"; +import { MyAccount } from "../screens/MyAccount/myAccount"; +import { GoogleScreen } from "../screens/login/Google"; +import { ConfirmOrder } from "../screens/Recipient/ConfirmOrder"; +import { Pay } from "../screens/pay/Pay"; +import { Status } from "../screens/productStatus/Status"; +import { OrderDetails } from "../screens/productStatus/OrderDatails"; +import { TikTokScreen } from "../screens/banner/TikTokScreen"; +import { BrowseHistoryScreen } from "../screens/function/BrowseHistoryScreen"; +import { Collection } from "../screens/function/Collection"; +import { MemberIntroduction } from "../screens/MemberScreen/MemberIntroduction"; +import { CompanyScreen } from "../screens/MemberScreen/CompanyScreen"; +import { PreviewAddress } from "../screens/previewOrder/PreviewAddress"; +import { AddressList } from "../screens/address/AddressList"; +import { AddAddress } from "../screens/address/AddAddress"; +import { EditAddress } from "../screens/address/EditAddress"; +import { PaymentMethod } from "../screens/previewOrder/PaymentMethod"; +import { ShippingFee } from "../screens/previewOrder/ShippingFee"; +import { PreviewOrder } from "../screens/previewOrder/perviewOrder"; +import { ForgotPhonePassword } from "../screens/loginList/ForgotPhonePassword"; + +export { + CountrySelect, + MainApp, + LoginScreen, + EmailLoginScreen, + TabNavigator, + SearchScreen, + SearchResultScreen, + ProductDetailScreen, + BalanceScreen, + ShippingDetailsSection, + InquiryScreen, + Recipient, + AddRess, + SettingList, + CountrySetting, + MyAddress, + CartScreen, + PaymentSuccessScreen, + MyAccount, + GoogleScreen, + ConfirmOrder, + Pay, + Status, + OrderDetails, + TikTokScreen, + BrowseHistoryScreen, + Collection, + MemberIntroduction, + CompanyScreen, + PreviewAddress, + AddressList, + AddAddress, + EditAddress, + PaymentMethod, + ShippingFee, + PreviewOrder, + ForgotPhonePassword +}; \ No newline at end of file diff --git a/app/navigation/types.ts b/app/navigation/types.ts index 6b3c6c3..4b1b604 100644 --- a/app/navigation/types.ts +++ b/app/navigation/types.ts @@ -1,15 +1,41 @@ import { MySetting } from '../services/api/setting'; export type RootStackParamList = { - Login: undefined; - EmailLogin: undefined; CountrySelect: undefined; MainApp: undefined; + Login: undefined; + EmailLogin: undefined; MainTabs: undefined; + Search: undefined; + SearchResult: { keyword: string }; + ProductDetail: { productId: string; searchKeyword?: string }; Balance: undefined; - Recipient: undefined; + ShippingDetailsSection: undefined; + InquiryScreen: undefined; + Recipient: { items: { cart_item_id: number }[] }; + AddRess: undefined; SettingList: undefined; - CountrySetting: { mySetting?: MySetting | undefined }; + CountrySetting: { mySetting?: MySetting }; MyAddress: undefined; - MyAccount:undefined; + CartScreen: undefined; + PaymentSuccessScreen: undefined; + MyAccount: undefined; + Google: undefined; + ConfirmOrder: undefined; + Pay: undefined; + Status: undefined; + OrderDetails: undefined; + TikTokScreen: undefined; + BrowseHistoryScreen: undefined; + Collection: undefined; + MemberIntroduction: undefined; + CompanyScreen: undefined; + PreviewAddress: undefined; + AddressList: undefined; + AddAddress: undefined; + EditAddress: undefined; + PaymentMethod: undefined; + ShippingFee: undefined; + PreviewOrder: undefined; + ForgotPhonePassword: undefined; }; diff --git a/app/screens/BalanceScreen.tsx b/app/screens/BalanceScreen.tsx index 3a0b8d2..dc51bff 100644 --- a/app/screens/BalanceScreen.tsx +++ b/app/screens/BalanceScreen.tsx @@ -5,7 +5,7 @@ import fontSize from '../utils/fontsizeUtils'; import widthUtils from '../utils/widthUtils'; import { useNavigation } from '@react-navigation/native'; import { NativeStackNavigationProp } from '@react-navigation/native-stack'; -import { RootStackParamList } from '../../App'; +import { RootStackParamList } from '../navigation/types'; import RechargeScreen from './RechargeScreen'; import BackIcon from '../components/BackIcon'; diff --git a/app/screens/ChatScreen.tsx b/app/screens/ChatScreen.tsx index de02b4c..ce4e00c 100644 --- a/app/screens/ChatScreen.tsx +++ b/app/screens/ChatScreen.tsx @@ -16,7 +16,6 @@ import { } from "react-native"; import { useNavigation } from "@react-navigation/native"; import { NativeStackNavigationProp } from "@react-navigation/native-stack"; -import { RootStackParamList } from "../../App"; import { useTranslation } from 'react-i18next'; diff --git a/app/screens/ProfileScreen.tsx b/app/screens/ProfileScreen.tsx index 0ff4713..94c3a20 100644 --- a/app/screens/ProfileScreen.tsx +++ b/app/screens/ProfileScreen.tsx @@ -452,11 +452,13 @@ const styles = StyleSheet.create({ }, gradientCardContainer: { position: "absolute", - bottom: -10, + bottom: 0, left: 19, right: 19, backgroundColor: "#3A3128", borderRadius: 10, + marginBottom: Platform.OS === 'ios' ? -18 : -15, + zIndex: 1, }, promoCardContainer2: { flexDirection: "column", diff --git a/app/screens/previewOrder/PaymentMethod.tsx b/app/screens/previewOrder/PaymentMethod.tsx index a26066c..92f643e 100644 --- a/app/screens/previewOrder/PaymentMethod.tsx +++ b/app/screens/previewOrder/PaymentMethod.tsx @@ -8,7 +8,6 @@ import { Image, Alert, ActivityIndicator, - Platform, StatusBar, SafeAreaView } from "react-native"; @@ -275,7 +274,7 @@ export const PaymentMethod = () => { const getPaymentMethods = async () => { try { const response = await payApi.getCountryPaymentMethods(); - + console.log(response); setPaymentMethods(response); // 设置默认支付方式选项 setTabs([ diff --git a/app/screens/previewOrder/PreviewAddress.tsx b/app/screens/previewOrder/PreviewAddress.tsx index 2d3a58c..b968e19 100644 --- a/app/screens/previewOrder/PreviewAddress.tsx +++ b/app/screens/previewOrder/PreviewAddress.tsx @@ -13,7 +13,8 @@ import { FlatList, Dimensions, StatusBar, - SafeAreaView + SafeAreaView, + ScrollView } from "react-native"; import { useState } from "react"; @@ -207,7 +208,6 @@ export const PreviewAddress = () => { const handleSubmit = async () => { if (validateForm()) { console.log(defaultAddress); - setOrderData({ ...orderData, address_id: defaultAddress?.address_id, @@ -227,8 +227,11 @@ export const PreviewAddress = () => { return ( - - + + {loading ? ( @@ -500,8 +503,8 @@ export const PreviewAddress = () => { - - + + ); }; @@ -520,7 +523,8 @@ const styles = StyleSheet.create({ backgroundColor: '#fff', }, scrollContainer: { - width: "100%", + flexGrow: 1, + paddingBottom: 20, }, recipientFormContainer3: { flex: 1, diff --git a/app/screens/previewOrder/ShippingFee.tsx b/app/screens/previewOrder/ShippingFee.tsx index 974dd3d..8d36314 100644 --- a/app/screens/previewOrder/ShippingFee.tsx +++ b/app/screens/previewOrder/ShippingFee.tsx @@ -83,6 +83,8 @@ export const ShippingFee = () => { useEffect(() => { if (state.freightForwarderAddress) { + console.log(state.freightForwarderAddress.other_addresses); + setFreightForwarderAddress(state.freightForwarderAddress); // 设置默认选择第一项 if ( diff --git a/app/store/burialPoint.ts b/app/store/burialPoint.ts new file mode 100644 index 0000000..bb74650 --- /dev/null +++ b/app/store/burialPoint.ts @@ -0,0 +1,325 @@ +import { Platform } from "react-native"; +import { create } from 'zustand'; +import useUserStore from "./user"; + +// 定义事件属性类型为灵活的记录类型 +type EventProperty = Record; + +// 定义事件类型 +type BurialEvent = { + event_name: string; + page_name: string | null; + referre_page: string | null; // 注意这里字段名已更正为referre_page + event_properties: EventProperty[]; +} + +// 定义产品属性类型 +type ProductProperty = { + offer_id: number; + category_id: number; + price: number; + sku_id: number; + currency: string; + product_name: string; + timestamp: string; + product_img: string; +} + +// 定义搜索属性类型 +type SearchProperty = { + key_word: string; + timestamp: string; +} + +// 定义地址信息属性类型 +type AddressProperty = { + last_name: string; + first_name: string; + country: string; + phone_number: number; + whatsApp_number: number; + timestamp: string; +} + +// 定义物流信息属性类型 +type ShippingProperty = { + shipping_method: number; + shipping_price_outside: number; + shipping_price_within: number; + currency: string; + forwarder_name: string; + country_city: string; + timestamp: string; + product_list_text?: string; +} + +// 定义支付方式属性类型 +type PaymentProperty = { + pay_method: string; + offline_payment: number; + all_price: number; + currency: string; + pay_product?: string; + shipping_method: number; + shipping_price_outside: number; + shipping_price_within: number; + timestamp: string; +} + +// 定义支付结账属性类型 +type CheckoutProperty = { + is_suc: number; + all_price: number; + currency: string; + shipping_method: number; + shipping_price_outside: number; + shipping_price_within: number; + pay_product?: string; + timestamp: string; +} + +// 生成唯一ID函数,替代md5 +const generateUniqueId = () => { + return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`; +}; + +// 创建唯一的session_id +const SESSION_ID = generateUniqueId(); + +// 定义埋点store的状态 +type BurialPointState = { + device_id: string; + version: string; + session_id: string; + event_list: BurialEvent[]; + addEvent: (event: BurialEvent) => void; + logAppLaunch: (isSuccess?: boolean) => void; + logLogin: (isSuccess: boolean, loginMethod: string) => void; + logRegister: (isSuccess: boolean, registerMethod: string) => void; + logViewProduct: (productInfo: ProductProperty, fromPage?: string) => void; + logSearch: (keyword: string, fromPage?: string) => void; + logAddressInfo: (addressInfo: Omit, fromPage?: string) => void; + logShippingConfirm: (shippingInfo: Omit, fromPage?: string) => void; + logPaymentConfirm: (paymentInfo: Omit, fromPage?: string) => void; + logPreviewOrder: (fromPage?: string) => void; + logCheckout: (checkoutInfo: Omit, fromPage?: string) => void; + clearData: () => void; +} + +// 获取当前格式化的时间字符串 YYYY-MM-DD HH:MM:SS +const getCurrentFormattedTime = (): string => { + return new Date().toISOString().replace('T', ' ').substr(0, 19); +}; + +// 创建埋点store +const useBurialPointStore = create((set, get) => ({ + device_id: Platform.OS, + version: generateUniqueId(), + session_id: SESSION_ID, + event_list: [], + + // 添加事件 + addEvent: (event: BurialEvent) => { + set((state) => { + const newEventList = [...state.event_list, event]; + + // 检查是否需要清理数据 + if (newEventList.length >= 10) { + // 这里可以在清理前添加发送数据到服务器的逻辑 + console.log('Data cleared, event count:', newEventList.length); + return { event_list: [] }; + } + + return { event_list: newEventList }; + }); + }, + + // 记录应用启动埋点 + logAppLaunch: (isSuccess = true) => { + const appLaunchEvent: BurialEvent = { + event_name: "app_launch", + page_name: null, + referre_page: null, + event_properties: [ + { + is_open: isSuccess ? 1 : 0, // 1表示成功,0表示失败 + timestamp: getCurrentFormattedTime() + } + ] + }; + + get().addEvent(appLaunchEvent); + }, + + // 记录登录事件埋点 + logLogin: (isSuccess = true, loginMethod = "phone") => { + const loginEvent: BurialEvent = { + event_name: "login", + page_name: null, + referre_page: null, + event_properties: [ + { + is_login: isSuccess ? 1 : 0, // 1表示成功,0表示失败 + login_method: loginMethod, // 登录方式 + timestamp: getCurrentFormattedTime() + } + ] + }; + + get().addEvent(loginEvent); + }, + + // 记录注册事件埋点 + logRegister: (isSuccess = true, registerMethod = "phone") => { + const registerEvent: BurialEvent = { + event_name: "register", + page_name: null, + referre_page: null, + event_properties: [ + { + is_register: isSuccess ? 1 : 0, // 1表示成功,0表示失败 + register_method: registerMethod, // 注册方式 + timestamp: getCurrentFormattedTime() + } + ] + }; + + get().addEvent(registerEvent); + }, + + // 记录浏览商品事件埋点 + logViewProduct: (productInfo: ProductProperty, fromPage = "home") => { + const viewProductEvent: BurialEvent = { + event_name: "view-product", + page_name: "product", + referre_page: fromPage, + event_properties: [productInfo] + }; + + get().addEvent(viewProductEvent); + }, + + // 记录搜索事件埋点 + logSearch: (keyword: string, fromPage = "home") => { + const searchEvent: BurialEvent = { + event_name: "search", + page_name: "search", + referre_page: fromPage, + event_properties: [ + { + key_word: keyword, + timestamp: getCurrentFormattedTime() + } + ] + }; + + get().addEvent(searchEvent); + }, + + // 记录填写地址信息事件埋点 + logAddressInfo: (addressInfo: Omit, fromPage = "cart") => { + const addressEvent: BurialEvent = { + event_name: "fill_information", + page_name: "address", + referre_page: fromPage, + event_properties: [ + { + ...addressInfo, + timestamp: getCurrentFormattedTime() + } + ] + }; + + get().addEvent(addressEvent); + }, + + // 记录物流信息确认事件埋点 + logShippingConfirm: (shippingInfo: Omit, fromPage = "address") => { + const shippingEvent: BurialEvent = { + event_name: "shipping_confirm", + page_name: "shipping", + referre_page: fromPage, + event_properties: [ + { + ...shippingInfo, + timestamp: getCurrentFormattedTime() + } + ] + }; + + get().addEvent(shippingEvent); + }, + + // 记录支付方式确认事件埋点 + logPaymentConfirm: (paymentInfo: Omit, fromPage = "shipping") => { + const paymentEvent: BurialEvent = { + event_name: "payment_confirm", + page_name: "pay_method", + referre_page: fromPage, + event_properties: [ + { + ...paymentInfo, + timestamp: getCurrentFormattedTime() + } + ] + }; + + get().addEvent(paymentEvent); + }, + + // 记录预览订单事件埋点 + logPreviewOrder: (fromPage = "pay_method") => { + const previewEvent: BurialEvent = { + event_name: "preview_order", + page_name: "preview", + referre_page: fromPage, + event_properties: [ + { + timestamp: getCurrentFormattedTime() + } + ] + }; + + get().addEvent(previewEvent); + }, + + // 记录支付结账事件埋点 + logCheckout: (checkoutInfo: Omit, fromPage = "perview") => { + const checkoutEvent: BurialEvent = { + event_name: "check_out", + page_name: "pay", + referre_page: fromPage, + event_properties: [ + { + ...checkoutInfo, + timestamp: getCurrentFormattedTime() + } + ] + }; + + get().addEvent(checkoutEvent); + }, + + // 清空数据 + clearData: () => { + // 这里可以添加发送数据到服务器的逻辑 + console.log('Data cleared, event count:', get().event_list.length); + set({ event_list: [] }); + } +})); + +// 获取埋点数据,包括从userStore获取的user_id +export const getBurialPointData = () => { + const burialState = useBurialPointStore.getState(); + const user = useUserStore.getState().user; + + return { + user_id: user?.user_id || null, + device_id: burialState.device_id, + version: burialState.version, + session_id: burialState.session_id, + event_list: burialState.event_list + }; +}; + +export default useBurialPointStore; \ No newline at end of file diff --git a/app/store/previewShipping.ts b/app/store/previewShipping.ts index a577bee..8998bd6 100644 --- a/app/store/previewShipping.ts +++ b/app/store/previewShipping.ts @@ -39,8 +39,10 @@ const usePreviewShippingStore = create((set) => ({ })); try { - const response = await ordersApi.freightForwarderAddress(transportMode); - response.other_addresses.unshift(response.current_country_address); + const response = await ordersApi.freightForwarderAddress(transportMode); + if (response.current_country_address != null){ + response.other_addresses.unshift(response.current_country_address); + } set((state) => ({ state: { ...state.state, diff --git a/app/types/react-native-md5.d.ts b/app/types/react-native-md5.d.ts new file mode 100644 index 0000000..61237c6 --- /dev/null +++ b/app/types/react-native-md5.d.ts @@ -0,0 +1,3 @@ +declare module 'react-native-md5' { + export function md5(str: string): string; +} \ No newline at end of file diff --git a/package.json b/package.json index 78bf1ac..54f0608 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "react-native-image-zoom-viewer": "^3.0.1", "react-native-linear-gradient": "^2.8.3", "react-native-localize": "^3.4.1", + "react-native-md5": "^1.0.0", "react-native-pager-view": "^6.7.0", "react-native-paper": "^5.13.3", "react-native-reanimated": "~3.16.1", @@ -72,4 +73,4 @@ "typescript": "^5.3.3" }, "private": true -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index d6631ec..e405f3b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9914,6 +9914,11 @@ react-native-localize@^3.4.1: resolved "https://registry.npmmirror.com/react-native-localize/-/react-native-localize-3.4.1.tgz#df07c13231b4e8cc949e68513b124105f861229c" integrity sha512-NJqJGBUpHtD/MpLCCkrNiqNZ+xFwbHCivxaoN1Oeb8tBAiZr/IqgP3E+MgnqmmdTMOJ33llUfiW3EM6pEIb33w== +react-native-md5@^1.0.0: + version "1.0.0" + resolved "https://registry.npmmirror.com/react-native-md5/-/react-native-md5-1.0.0.tgz#2320be24d674938ae5ef4f492698edbbfa0e0205" + integrity sha512-+QGVe0ShxWpcgr1pNKc2XGv/EbDpOdpvSQVkIPSGU+wLtlgbz5eDECgIZt+1y8JdNHfofGyQJk4FTTDu3rAX2w== + react-native-pager-view@^6.7.0: version "6.7.1" resolved "https://registry.npmmirror.com/react-native-pager-view/-/react-native-pager-view-6.7.1.tgz#60d52dedbcc92ee7037a13287ebeed5f74e49df7"