修改用户授权调用位置和逻辑
This commit is contained in:
@@ -7,6 +7,7 @@ import OrderService from "@/services/orderService";
|
||||
import { EvaluateCallback, EvaluateScene } from "@/store/evaluateStore";
|
||||
import { MATCH_STATUS, IsSubstituteSupported } from "@/services/detailService";
|
||||
import { GameManagePopup, NTRPEvaluatePopup } from "@/components";
|
||||
import { useUserInfo } from "@/store/userStore";
|
||||
import img from "@/config/images";
|
||||
import RMB_ICON from "@/static/detail/rmb.svg";
|
||||
import { toast, navto } from "@/utils/helper";
|
||||
@@ -76,6 +77,7 @@ export default function StickyButton(props) {
|
||||
currentUserInfo,
|
||||
} = props;
|
||||
const [commentCount, setCommentCount] = useState(0);
|
||||
const userInfo = useUserInfo();
|
||||
const ntrpRef = useRef<{
|
||||
show: (evaluateCallback: EvaluateCallback) => void;
|
||||
}>({ show: () => {} });
|
||||
@@ -93,6 +95,36 @@ export default function StickyButton(props) {
|
||||
|
||||
const { ntrp_level } = currentUserInfo || {};
|
||||
|
||||
// 检查手机号绑定的包装函数
|
||||
const checkPhoneAndExecute = (action: () => void) => {
|
||||
return () => {
|
||||
if (!userInfo?.phone) {
|
||||
Taro.showModal({
|
||||
title: '提示',
|
||||
content: '该功能需要绑定手机号',
|
||||
confirmText: '去绑定',
|
||||
cancelText: '取消',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
const currentPath = Taro.getCurrentInstance().router?.path || '';
|
||||
const currentParams = Taro.getCurrentInstance().router?.params || {};
|
||||
const queryString = Object.keys(currentParams)
|
||||
.map(key => `${key}=${currentParams[key]}`)
|
||||
.join('&');
|
||||
const fullPath = queryString ? `${currentPath}?${queryString}` : currentPath;
|
||||
|
||||
Taro.navigateTo({
|
||||
url: `/login_pages/index/index?redirect=${encodeURIComponent(fullPath)}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
action();
|
||||
};
|
||||
};
|
||||
|
||||
const matchNtrpReq = matchNtrpRequestment(
|
||||
ntrp_level,
|
||||
skill_level_min,
|
||||
@@ -224,14 +256,14 @@ export default function StickyButton(props) {
|
||||
<Text className={styles.btnText}>继续支付</Text>
|
||||
</>
|
||||
),
|
||||
action: async () => {
|
||||
action: checkPhoneAndExecute(async () => {
|
||||
const res = await OrderService.getUnpaidOrder(id);
|
||||
if (res.code === 0) {
|
||||
navto(
|
||||
`/order_pages/orderDetail/index?id=${res.data.order_info.order_id}`
|
||||
);
|
||||
}
|
||||
},
|
||||
}),
|
||||
};
|
||||
} else if (!matchNtrpReq) {
|
||||
return {
|
||||
@@ -255,7 +287,7 @@ export default function StickyButton(props) {
|
||||
<Text className={styles.btnText}>我要候补</Text>
|
||||
</>
|
||||
),
|
||||
action: handleJoinGame,
|
||||
action: checkPhoneAndExecute(handleJoinGame),
|
||||
};
|
||||
} else if (can_join) {
|
||||
return {
|
||||
@@ -268,7 +300,7 @@ export default function StickyButton(props) {
|
||||
</>
|
||||
);
|
||||
},
|
||||
action: handleJoinGame,
|
||||
action: checkPhoneAndExecute(handleJoinGame),
|
||||
};
|
||||
} else if (can_assess) {
|
||||
return {
|
||||
@@ -279,7 +311,7 @@ export default function StickyButton(props) {
|
||||
<Text className={styles.btnText}>立即加入</Text>
|
||||
</>
|
||||
),
|
||||
action: handleSelfEvaluate,
|
||||
action: checkPhoneAndExecute(handleSelfEvaluate),
|
||||
};
|
||||
}
|
||||
return {
|
||||
|
||||
@@ -10,6 +10,7 @@ import * as LoginService from "@/services/loginService";
|
||||
import { getCurrentLocation } from "@/utils/locationUtils";
|
||||
import { useUserInfo, useUserActions } from "@/store/userStore";
|
||||
import { useGlobalState } from "@/store/global";
|
||||
import { waitForAuthInit } from "@/utils/authInit";
|
||||
import { requireLoginWithPhone } from "@/utils/helper";
|
||||
import GameTags from "./components/GameTags";
|
||||
import Carousel from "./components/Carousel";
|
||||
@@ -46,8 +47,14 @@ function Index() {
|
||||
const commentRef = useRef();
|
||||
|
||||
useEffect(() => {
|
||||
updateLocation();
|
||||
fetchUserInfo();
|
||||
const init = async () => {
|
||||
updateLocation();
|
||||
// 先等待静默登录完成
|
||||
await waitForAuthInit();
|
||||
// 然后再获取用户信息
|
||||
await fetchUserInfo();
|
||||
};
|
||||
init();
|
||||
}, []);
|
||||
|
||||
useDidShow(() => {
|
||||
|
||||
@@ -16,6 +16,7 @@ import { updateUserLocation } from "@/services/userService";
|
||||
import { useUserActions } from "@/store/userStore";
|
||||
import { useDictionaryStore } from "@/store/dictionaryStore";
|
||||
import { saveImage } from "@/utils";
|
||||
import { waitForAuthInit } from "@/utils/authInit";
|
||||
|
||||
const ListPage = () => {
|
||||
// 从 store 获取数据和方法
|
||||
@@ -220,11 +221,14 @@ const ListPage = () => {
|
||||
getCities();
|
||||
getCityQrCode();
|
||||
|
||||
// 2. 延迟执行:获取用户信息(不阻塞渲染)
|
||||
requestAnimationFrame(() => {
|
||||
fetchUserInfo().catch((error) => {
|
||||
// 2. 延迟执行:等待静默登录完成后获取用户信息
|
||||
requestAnimationFrame(async () => {
|
||||
try {
|
||||
await waitForAuthInit();
|
||||
await fetchUserInfo();
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 3. 延迟执行:获取位置信息(可能较慢,不阻塞首屏)
|
||||
|
||||
@@ -14,6 +14,7 @@ import WechatTimeline from "@/static/detail/wechat_timeline.svg";
|
||||
import { useUserActions } from "@/store/userStore";
|
||||
import { DayOfWeekMap } from "../detail/config";
|
||||
import { genNTRPRequirementText } from "@/utils/helper";
|
||||
import { waitForAuthInit } from "@/utils/authInit";
|
||||
import styles from "./index.module.scss";
|
||||
|
||||
function SharePoster(props) {
|
||||
@@ -41,6 +42,8 @@ function SharePoster(props) {
|
||||
image_list,
|
||||
title,
|
||||
} = detail || {};
|
||||
// 先等待静默登录完成
|
||||
await waitForAuthInit();
|
||||
const userInfo = await fetchUserInfo();
|
||||
const { avatar_url, nickname } = userInfo;
|
||||
const startTime = dayjs(start_time);
|
||||
|
||||
Reference in New Issue
Block a user