import { View, Text, Image, TouchableOpacity } from "react-native"; import React, { useState, useCallback } from "react"; import { useTailwind } from "tailwind-rn"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { Divider, Icon } from "@rneui/themed"; import { LinearGradient } from "expo-linear-gradient"; import { useHeaderHeight } from "@react-navigation/elements"; import { get, save } from "../../utils/storeInfo"; import baseRequest from "../../utils/baseRequest"; import Toast from "react-native-toast-message"; import * as Linking from "expo-linking"; import { generateSignature } from "../../utils/crypto"; import { useFocusEffect } from "@react-navigation/native"; export default function Wallet({ navigation, route }) { const tailwind = useTailwind(); const insets = useSafeAreaInsets(); const headerHeight = useHeaderHeight(); const [tokenAndMobilePhone, setTokenAndMobilePhone] = useState(""); const [data, setData] = useState(""); //每次focus都更新一次数据 useFocusEffect( useCallback(() => { const getData = async () => { //获取环境变量 const apiUrl = process.env.EXPO_PUBLIC_API_URL; const account = await get("account"); const base = await baseRequest(); const signature = await generateSignature({ ...base, mid: account.mid, }); try { //获取账号基本信息 const accountResponse = await fetch( `${apiUrl}/api/account/list_by_mid?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ ...base, mid: account.mid, }), } ); const accountData = await accountResponse.json(); if (accountData.ret === -1) { Toast.show({ type: "error", text1: accountData.msg, topOffset: 60, }); return; } await save("account", accountData.data.account); setData(accountData.data.account); const tokenCache = await get("token"); const temToken = encodeURIComponent(tokenCache); const mobilePhone = await get("mobile_phone"); setTokenAndMobilePhone({ token: temToken, mobile_phone: mobilePhone, }); } catch (error) { console.error(error); } }; getData(); }, []) ); return ( {data?.gold_num} 金币 {data?.role === 3 && } {data?.role === 3 && ( {data?.diamond_num} 钻石 )} navigation.navigate("WebWithHeader", { title: "充值中心", uri: process.env.EXPO_PUBLIC_WEB_URL + "/pay", }) } style={tailwind("flex-row justify-between items-center py-4")} > 充值 navigation.navigate("WebWithHeader", { title: "收支明细", uri: process.env.EXPO_PUBLIC_WEB_URL + "/bill/cost", }) } style={tailwind("flex-row justify-between items-center py-4")} > 收支明细 {data?.role === 3 && ( Linking.openURL( `${process.env.EXPO_PUBLIC_WEB_URL}/withdrawal?mid=${data?.mid}&mobile_phone=${tokenAndMobilePhone?.mobile_phone}&token=${tokenAndMobilePhone?.token}` ) } style={tailwind("flex-row justify-between items-center py-4")} > 提现 )} ); }