feat: 调整微信登陆UI
This commit is contained in:
@@ -15,7 +15,6 @@ import { authService, WECHAT_STATUS, STATUS_MESSAGES } from "../../services/auth
|
|||||||
// 配置常量
|
// 配置常量
|
||||||
const POLL_INTERVAL = 2000; // 轮询间隔:2秒
|
const POLL_INTERVAL = 2000; // 轮询间隔:2秒
|
||||||
const QR_CODE_TIMEOUT = 300000; // 二维码超时:5分钟
|
const QR_CODE_TIMEOUT = 300000; // 二维码超时:5分钟
|
||||||
const ENABLE_MOCK = 'true'; // 通过环境变量控制 mock
|
|
||||||
|
|
||||||
export default function WechatRegister() {
|
export default function WechatRegister() {
|
||||||
// 状态管理
|
// 状态管理
|
||||||
@@ -192,41 +191,9 @@ export default function WechatRegister() {
|
|||||||
* 获取微信二维码
|
* 获取微信二维码
|
||||||
*/
|
*/
|
||||||
const getWechatQRCode = async () => {
|
const getWechatQRCode = async () => {
|
||||||
debugger
|
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
// 开发环境:使用 mock 数据
|
|
||||||
if (ENABLE_MOCK) {
|
|
||||||
console.log('🔧 开发模式:使用 Mock 数据');
|
|
||||||
|
|
||||||
// 模拟网络延迟
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 500));
|
|
||||||
|
|
||||||
// 检查组件是否已卸载
|
|
||||||
if (!isMountedRef.current) return;
|
|
||||||
|
|
||||||
// Mock 数据 - 使用一个测试页面
|
|
||||||
const mockResponse = {
|
|
||||||
auth_url: 'https://open.weixin.qq.com/connect/qrconnect?appid=mock&redirect_uri=mock&response_type=code&scope=snsapi_login&state=mock#wechat_redirect',
|
|
||||||
session_id: 'mock-session-' + Date.now()
|
|
||||||
};
|
|
||||||
|
|
||||||
setWechatAuthUrl(mockResponse.auth_url);
|
|
||||||
setWechatSessionId(mockResponse.session_id);
|
|
||||||
setWechatStatus(WECHAT_STATUS.WAITING);
|
|
||||||
|
|
||||||
toast({
|
|
||||||
title: "Mock 模式",
|
|
||||||
description: "正在使用测试数据展示",
|
|
||||||
status: "info",
|
|
||||||
duration: 2000,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 不启动轮询(避免无效请求)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 生产环境:调用真实 API
|
// 生产环境:调用真实 API
|
||||||
const response = await authService.getWechatQRCode();
|
const response = await authService.getWechatQRCode();
|
||||||
|
|
||||||
@@ -238,12 +205,12 @@ export default function WechatRegister() {
|
|||||||
throw new Error('服务器无响应');
|
throw new Error('服务器无响应');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!response.auth_url || !response.session_id) {
|
if (response.code !== 0) {
|
||||||
throw new Error('获取二维码失败:响应数据不完整');
|
throw new Error('获取二维码失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
setWechatAuthUrl(response.auth_url);
|
setWechatAuthUrl(response.data.auth_url);
|
||||||
setWechatSessionId(response.session_id);
|
setWechatSessionId(response.data.session_id);
|
||||||
setWechatStatus(WECHAT_STATUS.WAITING);
|
setWechatStatus(WECHAT_STATUS.WAITING);
|
||||||
|
|
||||||
// 启动轮询检查扫码状态
|
// 启动轮询检查扫码状态
|
||||||
@@ -357,7 +324,7 @@ export default function WechatRegister() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
{renderStatusText()}
|
{/* {renderStatusText()} */}
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
@@ -367,10 +334,13 @@ export default function WechatRegister() {
|
|||||||
|
|
||||||
<Box
|
<Box
|
||||||
position="relative"
|
position="relative"
|
||||||
minH="120px"
|
width="150px"
|
||||||
|
height="100px"
|
||||||
|
maxWidth="100%"
|
||||||
display="flex"
|
display="flex"
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
justifyContent="center"
|
justifyContent="center"
|
||||||
|
overflow="hidden"
|
||||||
>
|
>
|
||||||
{/* 灰色二维码底图 - 始终显示 */}
|
{/* 灰色二维码底图 - 始终显示 */}
|
||||||
<Icon as={FaQrcode} w={24} h={24} color="gray.300" />
|
<Icon as={FaQrcode} w={24} h={24} color="gray.300" />
|
||||||
|
|||||||
Reference in New Issue
Block a user