111 lines
3.1 KiB
JavaScript
111 lines
3.1 KiB
JavaScript
import { ScrollView, View } from "react-native";
|
|
import React, { useState, useEffect } from "react";
|
|
import { useTailwind } from "tailwind-rn";
|
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
import NoticeItem from "../components/NoticeItem";
|
|
import baseRequest from "../../../utils/baseRequest";
|
|
import { generateSignature } from "../../../utils/crypto";
|
|
import { Image } from "expo-image";
|
|
import Empty from "../../../components/Empty";
|
|
export default function SystemNotice({ navigation, route }) {
|
|
const tailwind = useTailwind();
|
|
const insets = useSafeAreaInsets();
|
|
const [data, setData] = useState([]);
|
|
useEffect(() => {
|
|
// handleClearCount();
|
|
getData();
|
|
}, []);
|
|
|
|
// const handleClearCount = async () => {
|
|
// const type = route.params["type"];
|
|
// const total = route.params["total"];
|
|
// let msgName = "";
|
|
// switch (type) {
|
|
// case 0:
|
|
// msgName = "system_msg";
|
|
// break;
|
|
// case 1:
|
|
// msgName = "pay_msg";
|
|
// break;
|
|
// case 2:
|
|
// msgName = "active_msg";
|
|
// break;
|
|
// case 3:
|
|
// msgName = "exam_msg";
|
|
// break;
|
|
// default:
|
|
// break;
|
|
// }
|
|
// await save(msgName, total);
|
|
// };
|
|
const getData = async (searchValue) => {
|
|
const apiUrl = process.env.EXPO_PUBLIC_API_URL;
|
|
try {
|
|
const base = await baseRequest();
|
|
const body = {
|
|
mid: base.b_mid,
|
|
...base,
|
|
};
|
|
const signature = await generateSignature(body);
|
|
const _receiveResponse = await fetch(
|
|
`${apiUrl}/api/notification/receive?signature=${signature}`,
|
|
{
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(body),
|
|
}
|
|
);
|
|
const receive = await _receiveResponse.json();
|
|
const _response = await fetch(
|
|
`${apiUrl}/api/notification/list_by_mid?signature=${signature}`,
|
|
{
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(body),
|
|
}
|
|
);
|
|
const _data = await _response.json();
|
|
if (_data.ret === -1) {
|
|
Toast.show({
|
|
type: "error",
|
|
text1: _data.msg,
|
|
topOffset: 60,
|
|
});
|
|
return;
|
|
}
|
|
// console.log("_data", _data);
|
|
const type = route.params["type"];
|
|
setData(_data.data.list.filter((it) => it.n_type == type));
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
};
|
|
return (
|
|
<ScrollView style={tailwind("p-4")}>
|
|
{data.map((it) => (
|
|
<NoticeItem
|
|
key={it.id}
|
|
data={it}
|
|
hasLink={{ url: "", text: "直达帖子" }}
|
|
leftIcon={
|
|
<View>
|
|
<Image
|
|
source={require("../../../assets/icon/others/m_system.png")}
|
|
contentFit="cover"
|
|
cachePolicy="disk"
|
|
transition={1000}
|
|
style={{ width: 32, height: 32 }}
|
|
/>
|
|
</View>
|
|
}
|
|
/>
|
|
))}
|
|
{!data.length && <Empty type="nodata" />}
|
|
</ScrollView>
|
|
);
|
|
}
|