import { View, Text, TouchableOpacity, ScrollView, Image as NativeImage, } from "react-native"; import React, { useState, useEffect, useCallback } from "react"; import { useTailwind } from "tailwind-rn"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { Icon } from "@rneui/themed"; import { Image } from "expo-image"; import Toast from "react-native-toast-message"; import { get, save } from "../../utils/storeInfo"; import baseRequest from "../../utils/baseRequest"; import { useFocusEffect } from "@react-navigation/native"; import { generateSignature } from "../../utils/crypto"; const blurhash = "LcKUTa%gOYWBYRt6xuoJo~s8V@fk"; export default function My({ navigation }) { const tailwind = useTailwind(); const insets = useSafeAreaInsets(); //获取当前页面数据 const [data, setData] = useState(); useEffect(() => { const initData = async () => { const account = await get("account"); const account_relation = await get("account_relation"); setData({ ...account, ...account_relation }); }; initData(); }, []); //每次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); //获取关注、粉丝数 const signature2 = await generateSignature({ ...base, mid: account.mid, }); const accountRelationResponse = await fetch( `${apiUrl}/api/account_relation/count?signature=${signature2}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ ...base, mid: account.mid, }), } ); const accountRelationData = await accountRelationResponse.json(); if (accountRelationData.ret === -1) { Toast.show({ type: "error", text1: accountRelationData.msg, topOffset: 60, }); return; } await save("account_relation", accountRelationData.data); setData({ ...accountData.data.account, ...accountRelationData.data }); } catch (error) { console.error(error); } }; getData(); }, []) ); return ( navigation.navigate("EditUserProfile")} style={tailwind("bg-[#FFFFFF1A] rounded-full mr-2")} > navigation.navigate("Setting")} style={tailwind("bg-[#FFFFFF1A] rounded-full")} > {/* 头像、id、昵称 */} { if (data?.role === 3) { navigation.navigate("StreamerProfile", { mid: data?.mid, }); } else { navigation.navigate("UserProfile"); } }} style={tailwind("flex flex-row items-center h-24")} > {data?.name} ID {data?.user_id} {/* 关注、粉丝、金币、钻石 */} navigation.navigate("Relationship", { tab: 0 })} style={tailwind("flex flex-col items-center w-1/4")} > {data?.follow_count} 关注 navigation.navigate("Relationship", { tab: 1 })} style={tailwind("flex flex-col items-center w-1/4")} > {data?.is_followed_count} 粉丝 navigation.navigate("Wallet")} style={tailwind("flex flex-col items-center w-1/4")} > {data?.gold_num} 金币 {data?.role === 3 && ( navigation.navigate("Wallet")} style={tailwind("flex flex-col items-center w-1/4")} > {data?.diamond_num} 钻石 )} {/* 纵向列表设置区 */} {data?.role === 3 && ( navigation.navigate("WechatWaitingToAdd", { tab: 0 }) } style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 待添加微信 创作者功能 navigation.navigate("EditStreamerProfile")} style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 编辑主页 创作者功能 navigation.navigate("EditPlatformOrder")} style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 编辑平台 创作者功能 navigation.navigate("WebWithHeader", { title: "邀请有礼", uri: process.env.EXPO_PUBLIC_WEB_URL + "/invite/" + data?.user_id, }) } style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 邀请分成 创作者功能 navigation.navigate("WebWithHeader", { title: "我的专属链接", uri: process.env.EXPO_PUBLIC_WEB_URL + "/generatelink/" + data?.user_id, }) } style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 生成分享页 创作者功能 )} navigation.navigate("Wallet")} style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 我的钱包 navigation.navigate("UnlockedWechat")} style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 已解锁微信 navigation.navigate("StreamerVerification")} style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 申请入驻 navigation.navigate("MessageDetail", { mid: 1, }) } style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 联系客服 ); }