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都更新一次数据 const [isInJoinProgress, setIsInJoinProgress] = useState(false); 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 oldAccount = await get( `account_list_${accountData.data.account.user_id}` ); await save(`account_list_${accountData.data.account.user_id}`, { ...oldAccount, account: accountData.data.account, login_time: new Date().getTime(), }); //获取关注、粉丝数 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); } }; //查看用户是否正在申请成为主播 const getBasicStatus = async () => { //获取环境变量 const apiUrl = process.env.EXPO_PUBLIC_API_URL; const base = await baseRequest(); const body = { ...base, }; const signature = await generateSignature(body); try { const _response = await fetch( `${apiUrl}/api/streamer_auth_approval/get_statuses?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(body), } ); const _data = await _response.json(); console.log(_data); if (_data.ret === -1) { Toast.show({ type: "error", text1: _data.msg, topOffset: 60, }); return; } if ( _data.data.basic_status === 0 || _data.data.basic_status === 1 || _data.data.basic_status === 3 ) { setIsInJoinProgress(true); return; } setIsInJoinProgress(false); } catch (error) { console.error(error); } }; getData(); getBasicStatus(); }, []) ); //通过toast向准主播提示需要先补充资料 const remainCompleteInformation = (func) => { if (data?.role === 3) { func(); return; } Toast.show({ type: "error", text1: "请先完善资料并等待审核通过", topOffset: 60, }); }; 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 || isInJoinProgress) && ( {isInJoinProgress && ( navigation.navigate("StreamerVerification", { screen: "CompleteStreamerInformation", }) } style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 完善资料 完善后解锁全部功能 )} {data?.streamer_ext?.zones?.length === 0 ? ( remainCompleteInformation(() => navigation.navigate("CreateSpace") ) } style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 开通空间 {data?.role === 3 ? "创作者功能" : "完善资料后解锁"} ) : ( remainCompleteInformation(() => navigation.navigate("StreamerSpace", { mid: data?.mid }) ) } style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 我的空间 {data?.role === 3 ? "创作者功能" : "完善资料后解锁"} )} remainCompleteInformation(() => navigation.navigate("StreamerPosts", { mid: data?.mid }) ) } style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 广场动态 {data?.role === 3 ? "创作者功能" : "完善资料后解锁"} remainCompleteInformation(() => navigation.navigate("WechatWaitingToAdd", { tab: 0 }) ) } style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 待添加微信 {data?.role === 3 ? "创作者功能" : "完善资料后解锁"} {data?.role === 3 && ( remainCompleteInformation(() => navigation.navigate("EditStreamerInfo") ) } style={tailwind("flex flex-row h-12 items-center pr-2 pl-4")} > 编辑资料 {data?.role === 3 ? "创作者功能" : "完善资料后解锁"} )} remainCompleteInformation(() => 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")} > 生成分享页 {data?.role === 3 ? "创作者功能" : "完善资料后解锁"} )} 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", { screen: "JoinStreamer", }) } 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")} > 联系客服 ); }