fix: ntrp测试流程优化

This commit is contained in:
2025-11-21 12:50:35 +08:00
parent ebd49553a8
commit 95900663dd
2 changed files with 68 additions and 60 deletions

View File

@@ -44,15 +44,14 @@ function NTRPTestEntryCard(props: {
}
};
init();
}, [userInfo.id]);
}, [userInfo]);
const handleTest = useCallback(
function () {
// 没有绑定手机号,线条转登陆
if (!requireLoginWithPhone()) {
return;
}
// if (!requireLoginWithPhone()) {
// return;
// }
switch (type) {
case EvaluateScene.list:

View File

@@ -1,29 +1,35 @@
import React, { useState } from 'react';
import { View, Text, Button, Image } from '@tarojs/components';
import Taro, { useRouter } from '@tarojs/taro';
import { wechat_auth_login, save_login_state, check_login_status } from '@/services/loginService';
import './index.scss';
import React, { useState } from "react";
import { View, Text, Button, Image } from "@tarojs/components";
import Taro, { useRouter } from "@tarojs/taro";
import {
wechat_auth_login,
save_login_state,
check_login_status,
} from "@/services/loginService";
import { useUserActions } from "@/store/userStore";
import "./index.scss";
const LoginPage: React.FC = () => {
const [is_loading, set_is_loading] = useState(false);
const [agree_terms, set_agree_terms] = useState(false);
const [show_terms_layer, set_show_terms_layer] = useState(false);
const [pending_login_type, set_pending_login_type] = useState<'wechat' | 'phone' | null>(null); // 记录待执行的登录类型
const [pending_login_type, set_pending_login_type] = useState<
"wechat" | "phone" | null
>(null); // 记录待执行的登录类型
const [pending_phone_event, set_pending_phone_event] = useState<any>(null); // 记录微信登录的事件数据
const { params: { redirect } } = useRouter();
const {
params: { redirect },
} = useRouter();
const { fetchUserInfo } = useUserActions();
// 执行微信登录的核心逻辑
const execute_wechat_login = async (e: any) => {
// 检查是否获取到手机号
if (!e.detail || !e.detail.code) {
Taro.showToast({
title: '获取手机号失败,请重试',
icon: 'none',
duration: 2000
title: "获取手机号失败,请重试",
icon: "none",
duration: 2000,
});
return;
}
@@ -34,26 +40,27 @@ const LoginPage: React.FC = () => {
const response = await wechat_auth_login(e.detail.code);
if (response.success) {
save_login_state(response.token!, response.user_info!);
fetchUserInfo();
setTimeout(() => {
if (redirect) {
Taro.redirectTo({ url: decodeURIComponent(redirect) });
} else {
Taro.redirectTo({ url: '/main_pages/index' });
Taro.redirectTo({ url: "/main_pages/index" });
}
}, 10);
} else {
Taro.showToast({
title: response.message,
icon: 'none',
duration: 2000
icon: "none",
duration: 2000,
});
}
} catch (error) {
Taro.showToast({
title: '登录失败,请重试',
icon: 'none',
duration: 2000
title: "登录失败,请重试",
icon: "none",
duration: 2000,
});
} finally {
set_is_loading(false);
@@ -64,13 +71,13 @@ const LoginPage: React.FC = () => {
const handle_wechat_login = async (e: any) => {
if (!agree_terms) {
// 记录待执行的登录类型和事件数据
set_pending_login_type('wechat');
set_pending_login_type("wechat");
set_pending_phone_event(e);
set_show_terms_layer(true);
Taro.showToast({
title: '请先同意用户协议',
icon: 'none',
duration: 2000
title: "请先同意用户协议",
icon: "none",
duration: 2000,
});
return;
}
@@ -83,7 +90,7 @@ const LoginPage: React.FC = () => {
const execute_phone_login = () => {
// 跳转到验证码页面
Taro.navigateTo({
url: `/login_pages/verification/index?redirect=${redirect}`
url: `/login_pages/verification/index?redirect=${redirect}`,
});
};
@@ -91,12 +98,12 @@ const LoginPage: React.FC = () => {
const handle_phone_login = async () => {
if (!agree_terms) {
// 记录待执行的登录类型
set_pending_login_type('phone');
set_pending_login_type("phone");
set_show_terms_layer(true);
Taro.showToast({
title: '请先同意用户协议',
icon: 'none',
duration: 2000
title: "请先同意用户协议",
icon: "none",
duration: 2000,
});
return;
}
@@ -111,13 +118,13 @@ const LoginPage: React.FC = () => {
set_show_terms_layer(false);
// 根据待执行的登录类型,继续执行登录
if (pending_login_type === 'wechat' && pending_phone_event) {
if (pending_login_type === "wechat" && pending_phone_event) {
// 继续执行微信登录
execute_wechat_login(pending_phone_event);
// 清空待执行状态
set_pending_login_type(null);
set_pending_phone_event(null);
} else if (pending_login_type === 'phone') {
} else if (pending_login_type === "phone") {
// 继续执行手机号登录
execute_phone_login();
// 清空待执行状态
@@ -131,9 +138,9 @@ const LoginPage: React.FC = () => {
};
// 查看协议
const handle_view_terms = (type: string = 'terms') => {
const handle_view_terms = (type: string = "terms") => {
Taro.navigateTo({
url: `/login_pages/terms/index?type=${type}`
url: `/login_pages/terms/index?type=${type}`,
});
};
@@ -152,7 +159,7 @@ const LoginPage: React.FC = () => {
<View className="background_image">
<Image
className="bg_img"
src={require('@/static/login/login_bg.jpg')}
src={require("@/static/login/login_bg.jpg")}
mode="aspectFill"
/>
<View className="bg_overlay"></View>
@@ -162,29 +169,30 @@ const LoginPage: React.FC = () => {
<View className="login_main_content">
{/* 品牌区域 */}
<View className="brand_section">
<View className="logo_container" >
<View className="logo_container"></View>
</View>
<View className="slogan_container">
</View>
<View className="slogan_container"></View>
</View>
{/* 登录按钮区域 */}
<View className="login_section">
{/* 微信快捷登录 */}
<Button
className={`login_button wechat_button ${is_loading ? 'loading' : ''}`}
className={`login_button wechat_button ${
is_loading ? "loading" : ""
}`}
openType="getPhoneNumber"
onGetPhoneNumber={handle_wechat_login}
disabled={is_loading}
>
<View className="wechat_icon">
<Image className="wechat_logo" src={require('@/static/login/wechat_icon.svg')} />
<Image
className="wechat_logo"
src={require("@/static/login/wechat_icon.svg")}
/>
</View>
<Text className="button_text">
{is_loading ? '登录中...' : '微信授权登录'}
{is_loading ? "登录中..." : "微信授权登录"}
</Text>
</Button>
@@ -194,7 +202,10 @@ const LoginPage: React.FC = () => {
onClick={handle_phone_login}
>
<View className="phone_icon">
<Image className="phone_logo" src={require('@/static/login/phone_icon.svg')} />
<Image
className="phone_logo"
src={require("@/static/login/phone_icon.svg")}
/>
</View>
<Text className="button_text"></Text>
</Button>
@@ -202,7 +213,7 @@ const LoginPage: React.FC = () => {
{/* 用户协议复选框 */}
<View className="terms_checkbox_section">
<View className="checkbox_container" onClick={handle_toggle_terms}>
<View className={`checkbox ${agree_terms ? 'checked' : ''}`}>
<View className={`checkbox ${agree_terms ? "checked" : ""}`}>
{/* {agree_terms && <View className="checkmark"></View>} */}
</View>
</View>
@@ -210,19 +221,19 @@ const LoginPage: React.FC = () => {
<Text className="terms_text"></Text>
<Text
className="terms_link"
onClick={() => handle_view_terms('terms')}
onClick={() => handle_view_terms("terms")}
>
</Text>
<Text
className="terms_link"
onClick={() => handle_view_terms('binding')}
onClick={() => handle_view_terms("binding")}
>
</Text>
<Text
className="terms_link"
onClick={() => handle_view_terms('privacy')}
onClick={() => handle_view_terms("privacy")}
>
</Text>
@@ -245,19 +256,19 @@ const LoginPage: React.FC = () => {
<View className="terms_list">
<Text
className="terms_item"
onClick={() => handle_view_terms('terms')}
onClick={() => handle_view_terms("terms")}
>
</Text>
<Text
className="terms_item"
onClick={() => handle_view_terms('binding')}
onClick={() => handle_view_terms("binding")}
>
</Text>
<Text
className="terms_item"
onClick={() => handle_view_terms('privacy')}
onClick={() => handle_view_terms("privacy")}
>
</Text>
@@ -265,13 +276,11 @@ const LoginPage: React.FC = () => {
{/* 同意按钮 */}
<Button
className={`agree_button ${agree_terms ? 'agreed' : ''}`}
className={`agree_button ${agree_terms ? "agreed" : ""}`}
onClick={handle_agree_terms}
>
{agree_terms ? '已同意' : '同意并继续'}
{agree_terms ? "已同意" : "同意并继续"}
</Button>
</View>
</View>
)}