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(); const [vipPrice, setVipPrice] = useState(); useEffect(() => { const initData = async () => { const account = await get("account"); const account_relation = await get("account_relation"); setData({ ...account, ...account_relation }); }; const getVipPrice = async () => { try { const apiUrl = process.env.EXPO_PUBLIC_API_URL; const base = await baseRequest(); const signature = await generateSignature({ ...base, }); const _response = await fetch( `${apiUrl}/api/vas/get_membership_product_list?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ ...base, }), } ); const _data = await _response.json(); if (_data.ret === -1) { Toast.show({ type: "error", text1: _data.msg, topOffset: 60, }); return; } setVipPrice(_data.data.product.real_price / 100); } catch (error) { console.error(error); } }; initData(); getVipPrice(); }, []); //每次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); if (accountData.data.account.role === 3) { //获取主播信息 const signature3 = await generateSignature({ ...base, mid: account.mid, }); const streamerResponse = await fetch( `${apiUrl}/api/streamer/list_ext_by_mid?signature=${signature3}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ ...base, mid: account.mid, }), } ); const streamerData = await streamerResponse.json(); if (streamerData.ret === -1) { Toast.show({ type: "error", text1: streamerData.msg, topOffset: 60, }); return; } setData({ ...accountData.data.account, ...accountRelationData.data, ...streamerData.data, }); return; } 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} {data?.is_a_member === 1 && ( )} 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} 金币 navigation.navigate("Wallet")} style={tailwind("flex flex-col items-center w-1/4")} > {data?.diamond_num} 钻石 {/* 会员 */} navigation.navigate("WebWithoutHeader", { uri: process.env.EXPO_PUBLIC_WEB_URL + "/vip", }) } style={tailwind( "flex flex-col p-2.5 rounded-2xl mt-3.5 bg-[#301024]" )} > {data?.is_a_member !== 1 ? "开通会员订阅动态" : "尊贵的永久会员"} {data?.is_a_member !== 1 ? "限时优惠活动" : "已解锁全部会员权益"} {data?.is_a_member !== 1 && ( ¥{vipPrice}/永久 )} {/* 纵向列表设置区 */} {data?.role === 3 && ( {data?.streamer_ext?.zones?.length === 0 ? ( navigation.navigate("CreateSpace")} style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 开通空间 创作者功能 ) : ( navigation.navigate("StreamerSpace", { mid: data?.mid }) } style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 我的空间 创作者功能 )} {/* {data?.streamer_ext?.zones && ( navigation.navigate("StreamerSpace", { mid: data?.mid }) } style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 我的空间 创作者功能 )} */} navigation.navigate("StreamerPosts", { mid: data?.mid }) } style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 广场动态 创作者功能 navigation.navigate("WechatWaitingToAdd", { tab: 0 }) } style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 待添加微信 创作者功能 navigation.navigate("EditStreamerInfo")} 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")} > 联系客服 ); }