购买会员页面加上轮询

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 [isVip, setIsVip] = useState(false);
const [name, setName] = useState(""); const [name, setName] = useState("");
const [isFetching, setIsFetching] = useState(true); const [isFetching, setIsFetching] = useState(true);
useEffect(() => { const getUserData = async () => {
const getUserData = async () => { try {
try { const base = webviewBaseRequest();
const base = webviewBaseRequest(); const signature = generateSignature({
const signature = generateSignature({ ...base,
...base, mid: base.b_mid,
mid: base.b_mid, });
}); const detailResponse = await fetch(
const detailResponse = await fetch( `/api/account/list_by_mid?signature=${signature}`,
`/api/account/list_by_mid?signature=${signature}`, {
{ method: "POST",
method: "POST", headers: {
headers: { "Content-Type": "application/json",
"Content-Type": "application/json", },
}, body: JSON.stringify({
body: JSON.stringify({ ...base,
...base, mid: base.b_mid,
mid: base.b_mid, }),
}),
}
);
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); const detailData = await detailResponse.json();
setIsFetching(false); if (detailData.ret === -1) {
} catch (error) { Toast.show({
console.error(error); 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(() => { setTimeout(() => {
getUserData(); getUserData();
}, 500); }, 500);
const intervalId = setInterval(() => {
getUserData();
}, 2000);
return () => clearInterval(intervalId);
}, []); }, []);
// //