2024-01-25 03:43:07 +08:00
|
|
|
import {
|
|
|
|
View,
|
|
|
|
RefreshControl,
|
|
|
|
ActivityIndicator,
|
|
|
|
Image as NativeImage,
|
|
|
|
Text,
|
|
|
|
TouchableOpacity,
|
2024-03-15 20:14:22 +08:00
|
|
|
FlatList,
|
2024-01-25 03:43:07 +08:00
|
|
|
} from "react-native";
|
|
|
|
import React, { useState, useEffect } from "react";
|
|
|
|
import Empty from "../../../components/Empty";
|
|
|
|
import { useTailwind } from "tailwind-rn";
|
|
|
|
import baseRequest from "../../../utils/baseRequest";
|
|
|
|
import Toast from "react-native-toast-message";
|
|
|
|
import { generateSignature } from "../../../utils/crypto";
|
|
|
|
import Post from "../../../components/Post";
|
|
|
|
import { useNavigation } from "@react-navigation/native";
|
2024-02-04 20:09:31 +08:00
|
|
|
import { get } from "../../../utils/storeInfo";
|
2024-05-02 22:56:41 +08:00
|
|
|
import { useVipVisibility } from "../../../context/VipVisibilityProvider";
|
2024-01-25 03:43:07 +08:00
|
|
|
|
|
|
|
export default function FeedPosts({ blur }) {
|
|
|
|
const navigation = useNavigation();
|
2024-02-04 20:09:31 +08:00
|
|
|
|
2024-05-02 22:56:41 +08:00
|
|
|
//查看是否展示vip功能
|
|
|
|
const { isVipVisible } = useVipVisibility();
|
|
|
|
|
2024-02-04 20:09:31 +08:00
|
|
|
//获取会员价格
|
|
|
|
const [vipPrice, setVipPrice] = useState();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//获取置顶动态数据
|
|
|
|
const getTopPostsData = async () => {
|
|
|
|
const account = await get("account");
|
|
|
|
const role = account.role;
|
|
|
|
const isVip = account.is_a_member;
|
2024-05-02 22:56:41 +08:00
|
|
|
const base = await baseRequest();
|
|
|
|
if (
|
|
|
|
base.b_ver !== "1.2.4" &&
|
|
|
|
(role !== 0 || isVip === 1 || !isVipVisible)
|
|
|
|
) {
|
2024-02-06 20:34:51 +08:00
|
|
|
return [];
|
2024-02-04 20:09:31 +08:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
const apiUrl = process.env.EXPO_PUBLIC_API_URL;
|
|
|
|
//查询动态id
|
|
|
|
const signature = await generateSignature({
|
|
|
|
config_key: "free_moment_ids",
|
|
|
|
...base,
|
|
|
|
});
|
|
|
|
const _response = await fetch(
|
|
|
|
`${apiUrl}/api/app_config/list_by_key?signature=${signature}`,
|
|
|
|
{
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
config_key: "free_moment_ids",
|
|
|
|
...base,
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
const _data = await _response.json();
|
|
|
|
if (_data.ret === -1) {
|
|
|
|
Toast.show({
|
|
|
|
type: "error",
|
|
|
|
text1: _data.msg,
|
|
|
|
topOffset: 60,
|
|
|
|
});
|
2024-02-06 20:34:51 +08:00
|
|
|
return [];
|
2024-02-04 20:09:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//用动态id查动态数据
|
2024-02-06 20:34:51 +08:00
|
|
|
if (!_data.data.app_config.config_value) return [];
|
2024-02-04 20:09:31 +08:00
|
|
|
const intIds = _data.data.app_config.config_value?.map((item) =>
|
|
|
|
parseInt(item, 10)
|
|
|
|
);
|
|
|
|
const signature2 = await generateSignature({
|
|
|
|
ids: intIds,
|
|
|
|
...base,
|
|
|
|
});
|
|
|
|
const _response2 = await fetch(
|
|
|
|
`${apiUrl}/api/moment/list_by_ids?signature=${signature2}`,
|
|
|
|
{
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
ids: intIds,
|
|
|
|
...base,
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
const _data2 = await _response2.json();
|
|
|
|
if (_data2.ret === -1) {
|
|
|
|
Toast.show({
|
|
|
|
type: "error",
|
|
|
|
text1: _data2.msg,
|
|
|
|
topOffset: 60,
|
|
|
|
});
|
2024-02-06 20:34:51 +08:00
|
|
|
return [];
|
2024-02-04 20:09:31 +08:00
|
|
|
}
|
|
|
|
const topPostsData = _data2.data.list.map((item) => {
|
|
|
|
return { ...item, top: true };
|
|
|
|
});
|
|
|
|
return topPostsData;
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
2024-02-06 20:34:51 +08:00
|
|
|
return [];
|
2024-02-04 20:09:31 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-03-15 20:14:22 +08:00
|
|
|
//获取新数据
|
2024-01-25 03:43:07 +08:00
|
|
|
const [data, setData] = useState([]);
|
|
|
|
const [isActivityIndicatorShow, setIsActivityIndicatorShow] = useState(true);
|
2024-03-15 20:14:22 +08:00
|
|
|
const [isFetching, setIsFetching] = useState(false);
|
|
|
|
const getData = async (type = 0) => {
|
|
|
|
//type 0-上滑 1-下拉 2-初始化
|
|
|
|
if (isFetching) return;
|
|
|
|
const apiUrl = process.env.EXPO_PUBLIC_API_URL;
|
|
|
|
setIsFetching(true);
|
2024-01-25 03:43:07 +08:00
|
|
|
try {
|
|
|
|
const base = await baseRequest();
|
|
|
|
const signature = await generateSignature({
|
2024-03-15 20:14:22 +08:00
|
|
|
op_type: type,
|
2024-01-25 03:43:07 +08:00
|
|
|
...base,
|
|
|
|
});
|
|
|
|
const _response = await fetch(
|
2024-03-15 20:14:22 +08:00
|
|
|
`${apiUrl}/api/moment/recomm_list?signature=${signature}`,
|
2024-01-25 03:43:07 +08:00
|
|
|
{
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
2024-03-15 20:14:22 +08:00
|
|
|
op_type: type,
|
2024-01-25 03:43:07 +08:00
|
|
|
...base,
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
const _data = await _response.json();
|
|
|
|
if (_data.ret === -1) {
|
|
|
|
Toast.show({
|
|
|
|
type: "error",
|
|
|
|
text1: _data.msg,
|
|
|
|
topOffset: 60,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2024-03-15 20:14:22 +08:00
|
|
|
if (type === 1 || type === 2) {
|
2024-02-04 20:09:31 +08:00
|
|
|
const topPosts = await getTopPostsData();
|
2024-03-15 20:14:22 +08:00
|
|
|
setData((prev) => [...topPosts, ..._data.data.recomm_list]);
|
|
|
|
setIsActivityIndicatorShow(true);
|
2024-01-25 03:43:07 +08:00
|
|
|
} else {
|
2024-03-15 20:14:22 +08:00
|
|
|
setData((prev) => [...prev, ..._data.data.recomm_list]);
|
|
|
|
if (_data.data.recomm_list.length === 0)
|
|
|
|
setIsActivityIndicatorShow(false);
|
2024-01-25 03:43:07 +08:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
2024-03-15 20:14:22 +08:00
|
|
|
} finally {
|
|
|
|
setIsFetching(false);
|
2024-01-25 03:43:07 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-03-15 20:14:22 +08:00
|
|
|
//初始化加载
|
2024-01-25 03:43:07 +08:00
|
|
|
useEffect(() => {
|
2024-02-04 20:09:31 +08:00
|
|
|
getVipPrice();
|
2024-03-15 20:14:22 +08:00
|
|
|
getData(2);
|
2024-03-23 15:28:01 +08:00
|
|
|
}, [blur]);
|
2024-01-25 03:43:07 +08:00
|
|
|
|
|
|
|
const tailwind = useTailwind();
|
2024-02-04 20:09:31 +08:00
|
|
|
const renderItem = ({ item }) => <Post isBlur={blur} data={item} />;
|
2024-01-25 03:43:07 +08:00
|
|
|
const [refreshing, setRefreshing] = useState(false);
|
|
|
|
//下拉刷新
|
|
|
|
const handleRefresh = async () => {
|
|
|
|
setRefreshing(true);
|
2024-03-15 20:14:22 +08:00
|
|
|
await getData(1);
|
2024-01-25 03:43:07 +08:00
|
|
|
setRefreshing(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={tailwind("flex-1")}>
|
2024-03-15 20:14:22 +08:00
|
|
|
<FlatList
|
2024-01-25 03:43:07 +08:00
|
|
|
data={data}
|
2024-03-15 20:14:22 +08:00
|
|
|
extraData={blur}
|
2024-01-25 03:43:07 +08:00
|
|
|
renderItem={renderItem}
|
|
|
|
initialNumToRender={4}
|
|
|
|
refreshControl={
|
|
|
|
<RefreshControl
|
|
|
|
colors={["#FF669E"]}
|
|
|
|
tintColor="white"
|
|
|
|
refreshing={refreshing}
|
|
|
|
onRefresh={() => handleRefresh()}
|
|
|
|
/>
|
|
|
|
}
|
2024-03-15 20:14:22 +08:00
|
|
|
onEndReached={() => getData(0)}
|
2024-01-25 03:43:07 +08:00
|
|
|
ListEmptyComponent={<Empty type="nodata" />}
|
|
|
|
ListFooterComponent={
|
|
|
|
<View>
|
|
|
|
{isActivityIndicatorShow && data.length !== 0 && (
|
|
|
|
<ActivityIndicator style={tailwind("my-4")} size="large" />
|
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
{blur && (
|
2024-01-29 01:53:13 +08:00
|
|
|
<TouchableOpacity
|
|
|
|
activeOpacity={1}
|
|
|
|
onPress={() =>
|
|
|
|
navigation.navigate("WebWithoutHeader", {
|
|
|
|
uri: process.env.EXPO_PUBLIC_WEB_URL + "/vip",
|
|
|
|
})
|
|
|
|
}
|
2024-01-25 03:43:07 +08:00
|
|
|
style={tailwind(
|
|
|
|
"flex flex-row items-center justify-between h-12 bg-[#301024] px-4"
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<View style={tailwind("flex flex-row items-center")}>
|
|
|
|
<NativeImage
|
|
|
|
source={require("../../../assets/icon/others/vipbig.png")}
|
|
|
|
/>
|
2024-01-29 01:53:13 +08:00
|
|
|
<Text
|
|
|
|
numberOfLines={1}
|
|
|
|
ellipsizeMode="tail"
|
|
|
|
style={tailwind("text-[#FF669E] text-base font-medium ml-1")}
|
|
|
|
>
|
2024-02-06 20:34:51 +08:00
|
|
|
即刻订阅全部精选内容
|
2024-01-25 03:43:07 +08:00
|
|
|
</Text>
|
|
|
|
</View>
|
2024-01-29 01:53:13 +08:00
|
|
|
<View
|
2024-01-25 03:43:07 +08:00
|
|
|
style={tailwind(
|
|
|
|
"flex justify-center items-center h-9 bg-[#FF669E] rounded-full px-4"
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<Text style={tailwind("text-white text-sm font-medium")}>
|
2024-02-04 20:09:31 +08:00
|
|
|
¥{vipPrice}/永久
|
2024-01-25 03:43:07 +08:00
|
|
|
</Text>
|
2024-01-29 01:53:13 +08:00
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
2024-01-25 03:43:07 +08:00
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|