修复分享页面不能访问问题
This commit is contained in:
@@ -147,9 +147,17 @@ function Intro() {
|
||||
const [ready, setReady] = useState(false);
|
||||
const { setCallback } = useEvaluate();
|
||||
|
||||
const { last_test_result: { ntrp_level, create_time, id } = {} } =
|
||||
ntrpData || {};
|
||||
const lastTestTime = dayjs(create_time).format("YYYY年M月D日");
|
||||
const { last_test_result = null } = ntrpData || {};
|
||||
const { ntrp_level, create_time, id } = last_test_result || {};
|
||||
const lastTestTime = create_time ? dayjs(create_time).format("YYYY年M月D日") : "";
|
||||
|
||||
// 组件初始化时立即获取用户信息
|
||||
useEffect(() => {
|
||||
// 如果用户信息为空,立即获取
|
||||
if (!userInfo || Object.keys(userInfo).length === 0) {
|
||||
fetchUserInfo();
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
getLastResult();
|
||||
@@ -160,7 +168,10 @@ function Intro() {
|
||||
if (res.code === 0) {
|
||||
setNtrpData(res.data);
|
||||
if (res.data.has_ntrp_level) {
|
||||
fetchUserInfo();
|
||||
// 确保用户信息已加载
|
||||
if (!userInfo || Object.keys(userInfo).length === 0) {
|
||||
await fetchUserInfo();
|
||||
}
|
||||
}
|
||||
setReady(true);
|
||||
}
|
||||
@@ -197,7 +208,7 @@ function Intro() {
|
||||
<View className={styles.avatar}>
|
||||
<Image
|
||||
className={styles.avatarUrl}
|
||||
src={userInfo.avatar_url}
|
||||
src={userInfo?.avatar_url || ""}
|
||||
mode="aspectFill"
|
||||
/>
|
||||
</View>
|
||||
@@ -225,7 +236,7 @@ function Intro() {
|
||||
</View>
|
||||
<View className={styles.levelWrap}>
|
||||
<Text>NTRP</Text>
|
||||
<Text className={styles.level}>{formatNtrpDisplay(ntrp_level)}</Text>
|
||||
<Text className={styles.level}>{formatNtrpDisplay(ntrp_level || "")}</Text>
|
||||
</View>
|
||||
<View className={styles.slogan}>
|
||||
<Text>变线+网前,下一步就是赢比赛!</Text>
|
||||
@@ -439,9 +450,20 @@ function Result() {
|
||||
[propName: string, prop: number][]
|
||||
>([]);
|
||||
|
||||
// 组件初始化时立即获取用户信息
|
||||
useEffect(() => {
|
||||
// 如果用户信息为空,立即获取
|
||||
if (!userInfo || Object.keys(userInfo).length === 0) {
|
||||
fetchUserInfo();
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
getResultById();
|
||||
fetchUserInfo();
|
||||
// 确保用户信息已加载
|
||||
if (!userInfo || Object.keys(userInfo).length === 0) {
|
||||
fetchUserInfo();
|
||||
}
|
||||
}, [id]);
|
||||
|
||||
async function getResultById() {
|
||||
@@ -548,7 +570,7 @@ function Result() {
|
||||
|
||||
async function handleSaveImage() {
|
||||
console.log(userInfo);
|
||||
if (!userInfo.id) {
|
||||
if (!userInfo?.id) {
|
||||
return;
|
||||
}
|
||||
Taro.getSetting().then(async (res) => {
|
||||
@@ -597,7 +619,7 @@ function Result() {
|
||||
});
|
||||
|
||||
function handleAuth() {
|
||||
if (userInfo.id) {
|
||||
if (userInfo?.id) {
|
||||
return true;
|
||||
}
|
||||
const currentPage = getCurrentFullPath();
|
||||
@@ -616,7 +638,7 @@ function Result() {
|
||||
<View className={styles.avatar}>
|
||||
<Image
|
||||
className={styles.avatarUrl}
|
||||
src={userInfo.avatar_url}
|
||||
src={userInfo?.avatar_url || ""}
|
||||
mode="aspectFill"
|
||||
/>
|
||||
</View>
|
||||
@@ -649,9 +671,9 @@ function Result() {
|
||||
<Text>重新测试</Text>
|
||||
</View>
|
||||
</View>
|
||||
{userInfo.id ? (
|
||||
{userInfo?.id ? (
|
||||
<View className={styles.updateTip}>
|
||||
<Text>你的 NTRP 水平已更新为 {formatNtrpDisplay(result?.ntrp_level)} </Text>
|
||||
<Text>你的 NTRP 水平已更新为 {formatNtrpDisplay(result?.ntrp_level || "")} </Text>
|
||||
<Text className={styles.grayTip}>(可在个人信息中修改)</Text>
|
||||
</View>
|
||||
) : (
|
||||
@@ -669,7 +691,7 @@ function Result() {
|
||||
<View className={styles.share}>
|
||||
<Button
|
||||
className={styles.shareBtn}
|
||||
openType={userInfo.id ? "share" : undefined}
|
||||
openType={userInfo?.id ? "share" : undefined}
|
||||
onClick={handleAuth}
|
||||
></Button>
|
||||
<View className={styles.shareBtnCover}>
|
||||
|
||||
Reference in New Issue
Block a user