Merge pull request '每次进入会员页面会重新获取用户信息更新会员状态' (#12) from feat-20240118 into main

Reviewed-on: https://git.wishpal.cn/wishpal_ironfan/tiefen_space_web/pulls/12
This commit is contained in:
yezian 2024-01-23 20:01:23 +08:00
commit 5f9c6a36cf
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 [name, setName] = useState("");
useEffect(() => {
const cookies = getCookies();
const is_a_member = cookies.is_a_member;
const _name = cookies.name;
setName(_name);
const int_is_a_member = parseInt(is_a_member, 10);
if (int_is_a_member === 1) setIsVip(true);
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;
}
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();
console.log(data);
if (data.ret === -1) {
Toast.show({
content: data.msg,