购买会员页面加上轮询

This commit is contained in:
yezian 2024-04-25 20:53:49 +08:00
parent dc16e096af
commit 59dace7c2b
1 changed files with 38 additions and 33 deletions

View File

@ -36,44 +36,49 @@ export default function Vip() {
const [isVip, setIsVip] = useState(false);
const [name, setName] = useState("");
const [isFetching, setIsFetching] = useState(true);
useEffect(() => {
const getUserData = async () => {
try {
const base = webviewBaseRequest();
const signature = generateSignature({
...base,
mid: base.b_mid,
});
const detailResponse = await fetch(
`/api/account/list_by_mid?signature=${signature}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
...base,
mid: base.b_mid,
}),
}
);
const detailData = await detailResponse.json();
if (detailData.ret === -1) {
Toast.show({
content: detailData.msg,
});
return;
const getUserData = async () => {
try {
const base = webviewBaseRequest();
const signature = generateSignature({
...base,
mid: base.b_mid,
});
const detailResponse = await fetch(
`/api/account/list_by_mid?signature=${signature}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
...base,
mid: base.b_mid,
}),
}
setName(detailData.data.account.name);
if (detailData.data.account.is_a_member === 1) setIsVip(true);
setIsFetching(false);
} catch (error) {
console.error(error);
);
const detailData = await detailResponse.json();
if (detailData.ret === -1) {
Toast.show({
content: detailData.msg,
});
return;
}
};
setName(detailData.data.account.name);
if (detailData.data.account.is_a_member === 1) setIsVip(true);
setIsFetching(false);
} catch (error) {
console.error(error);
}
};
//
useEffect(() => {
setTimeout(() => {
getUserData();
}, 500);
const intervalId = setInterval(() => {
getUserData();
}, 2000);
return () => clearInterval(intervalId);
}, []);
//