每次进入会员页面会重新获取用户信息更新会员状态

This commit is contained in:
yezian 2024-01-23 20:01:03 +08:00
parent 526b844e97
commit 71b44deaf2
1 changed files with 34 additions and 7 deletions

View File

@ -25,12 +25,40 @@ export default function Vip() {
const [isVip, setIsVip] = useState(false); const [isVip, setIsVip] = useState(false);
const [name, setName] = useState(""); const [name, setName] = useState("");
useEffect(() => { useEffect(() => {
const cookies = getCookies(); const getUserData = async () => {
const is_a_member = cookies.is_a_member; try {
const _name = cookies.name; const base = webviewBaseRequest();
setName(_name); const signature = generateSignature({
const int_is_a_member = parseInt(is_a_member, 10); ...base,
if (int_is_a_member === 1) setIsVip(true); 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;
}
setName(detailData.data.account.name);
if (detailData.data.account.is_a_member === 1) setIsVip(true);
} catch (error) {
console.error(error);
}
};
getUserData();
}, []); }, []);
// //
@ -57,7 +85,6 @@ export default function Vip() {
} }
); );
const data = await response.json(); const data = await response.json();
console.log(data);
if (data.ret === -1) { if (data.ret === -1) {
Toast.show({ Toast.show({
content: data.msg, content: data.msg,