feat: 日志优化
This commit is contained in:
@@ -279,7 +279,11 @@ export default function AuthFormContent() {
|
|||||||
// ⚡ Mock 模式:先在前端侧写入 localStorage,确保时序正确
|
// ⚡ Mock 模式:先在前端侧写入 localStorage,确保时序正确
|
||||||
if (process.env.REACT_APP_ENABLE_MOCK === 'true' && data.user) {
|
if (process.env.REACT_APP_ENABLE_MOCK === 'true' && data.user) {
|
||||||
setCurrentUser(data.user);
|
setCurrentUser(data.user);
|
||||||
console.log('[Auth] 前端侧设置当前用户(Mock模式):', data.user);
|
logger.debug('AuthFormContent', '前端侧设置当前用户(Mock模式)', {
|
||||||
|
userId: data.user?.id,
|
||||||
|
phone: data.user?.phone,
|
||||||
|
mockMode: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新session
|
// 更新session
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { FormControl, FormErrorMessage, HStack, Input, Button, Spinner } from "@chakra-ui/react";
|
import { FormControl, FormErrorMessage, HStack, Input, Button, Spinner } from "@chakra-ui/react";
|
||||||
|
import { logger } from "../../utils/logger";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用验证码输入组件
|
* 通用验证码输入组件
|
||||||
@@ -26,7 +27,12 @@ export default function VerificationCodeInput({
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// 错误已经在父组件处理,这里只需要防止未捕获的 Promise rejection
|
// 错误已经在父组件处理,这里只需要防止未捕获的 Promise rejection
|
||||||
console.error('Send code error (caught in VerificationCodeInput):', error);
|
logger.error('VerificationCodeInput', 'handleSendCode', error, {
|
||||||
|
hasOnSendCode: !!onSendCode,
|
||||||
|
countdown,
|
||||||
|
isLoading,
|
||||||
|
isSending
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { Typography, Space, Tag } from 'antd';
|
|||||||
import { RobotOutlined, FileSearchOutlined } from '@ant-design/icons';
|
import { RobotOutlined, FileSearchOutlined } from '@ant-design/icons';
|
||||||
import CitationMark from './CitationMark';
|
import CitationMark from './CitationMark';
|
||||||
import { processCitationData } from '../../utils/citationUtils';
|
import { processCitationData } from '../../utils/citationUtils';
|
||||||
|
import { logger } from '../../utils/logger';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
@@ -37,7 +38,10 @@ const CitedContent = ({
|
|||||||
|
|
||||||
// 如果数据无效,不渲染
|
// 如果数据无效,不渲染
|
||||||
if (!processed) {
|
if (!processed) {
|
||||||
console.warn('CitedContent: Invalid data, not rendering');
|
logger.warn('CitedContent', '无效数据,不渲染', {
|
||||||
|
hasData: !!data,
|
||||||
|
title
|
||||||
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import { createContext, useContext, useState, useCallback } from 'react';
|
import { createContext, useContext, useState, useCallback } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useAuth } from './AuthContext';
|
import { useAuth } from './AuthContext';
|
||||||
|
import { logger } from '../utils/logger';
|
||||||
|
|
||||||
const AuthModalContext = createContext();
|
const AuthModalContext = createContext();
|
||||||
|
|
||||||
@@ -69,7 +70,10 @@ export const AuthModalProvider = ({ children }) => {
|
|||||||
try {
|
try {
|
||||||
onSuccessCallback(user);
|
onSuccessCallback(user);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Success callback error:', error);
|
logger.error('AuthModalContext', 'handleLoginSuccess', error, {
|
||||||
|
userId: user?.id,
|
||||||
|
hasCallback: !!onSuccessCallback
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// src/hooks/useSubscription.js
|
// src/hooks/useSubscription.js
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
import { logger } from '../utils/logger';
|
||||||
|
|
||||||
// 订阅级别映射
|
// 订阅级别映射
|
||||||
const SUBSCRIPTION_LEVELS = {
|
const SUBSCRIPTION_LEVELS = {
|
||||||
@@ -46,7 +47,10 @@ export const useSubscription = () => {
|
|||||||
|
|
||||||
// 首先检查用户对象中是否已经包含订阅信息
|
// 首先检查用户对象中是否已经包含订阅信息
|
||||||
if (user.subscription_type) {
|
if (user.subscription_type) {
|
||||||
console.log('📋 从用户对象获取订阅信息:', user.subscription_type);
|
logger.debug('useSubscription', '从用户对象获取订阅信息', {
|
||||||
|
subscriptionType: user.subscription_type,
|
||||||
|
daysLeft: user.subscription_days_left
|
||||||
|
});
|
||||||
setSubscriptionInfo({
|
setSubscriptionInfo({
|
||||||
type: user.subscription_type,
|
type: user.subscription_type,
|
||||||
status: 'active',
|
status: 'active',
|
||||||
@@ -73,7 +77,10 @@ export const useSubscription = () => {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 如果API调用失败,回退到用户对象中的信息
|
// 如果API调用失败,回退到用户对象中的信息
|
||||||
console.log('📋 API失败,使用用户对象中的订阅信息');
|
logger.warn('useSubscription', 'API调用失败,使用用户对象订阅信息', {
|
||||||
|
status: response.status,
|
||||||
|
fallbackType: user.subscription_type || 'free'
|
||||||
|
});
|
||||||
setSubscriptionInfo({
|
setSubscriptionInfo({
|
||||||
type: user.subscription_type || 'free',
|
type: user.subscription_type || 'free',
|
||||||
status: 'active',
|
status: 'active',
|
||||||
@@ -82,7 +89,9 @@ export const useSubscription = () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取订阅信息失败:', error);
|
logger.error('useSubscription', 'fetchSubscriptionInfo', error, {
|
||||||
|
userId: user?.id
|
||||||
|
});
|
||||||
// 发生错误时,回退到用户对象中的信息
|
// 发生错误时,回退到用户对象中的信息
|
||||||
setSubscriptionInfo({
|
setSubscriptionInfo({
|
||||||
type: user.subscription_type || 'free',
|
type: user.subscription_type || 'free',
|
||||||
@@ -109,7 +118,10 @@ export const useSubscription = () => {
|
|||||||
const hasFeatureAccess = (featureName) => {
|
const hasFeatureAccess = (featureName) => {
|
||||||
// 临时调试:如果用户对象中有max权限,直接解锁所有功能
|
// 临时调试:如果用户对象中有max权限,直接解锁所有功能
|
||||||
if (user?.subscription_type === 'max') {
|
if (user?.subscription_type === 'max') {
|
||||||
console.log(`🔓 Max用户直接解锁功能: ${featureName}`);
|
logger.debug('useSubscription', 'Max用户解锁功能', {
|
||||||
|
featureName,
|
||||||
|
userId: user?.id
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ import {
|
|||||||
} from 'components/Scrollbar/Scrollbar';
|
} from 'components/Scrollbar/Scrollbar';
|
||||||
import { useRef, useState } from 'react';
|
import { useRef, useState } from 'react';
|
||||||
import { Scrollbars } from 'react-custom-scrollbars-2';
|
import { Scrollbars } from 'react-custom-scrollbars-2';
|
||||||
|
import { logger } from '../../utils/logger';
|
||||||
|
|
||||||
function Kanban() {
|
function Kanban() {
|
||||||
// Chakra color mode
|
// Chakra color mode
|
||||||
@@ -149,6 +150,15 @@ function Kanban() {
|
|||||||
return newCardLocal;
|
return newCardLocal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 卡片创建日志处理函数
|
||||||
|
function handleCardNew(cardData) {
|
||||||
|
logger.debug('Kanban', '创建新卡片', {
|
||||||
|
cardId: cardData?.id,
|
||||||
|
title: cardData?.title,
|
||||||
|
boardCounter: initialBoard.counter
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
direction='column'
|
direction='column'
|
||||||
@@ -167,7 +177,7 @@ function Kanban() {
|
|||||||
initialBoard={board}
|
initialBoard={board}
|
||||||
allowAddCard
|
allowAddCard
|
||||||
onNewCardConfirm={onCardNew}
|
onNewCardConfirm={onCardNew}
|
||||||
onCardNew={console.log}
|
onCardNew={handleCardNew}
|
||||||
renderColumnHeader={function ({ title }, { addCard }) {
|
renderColumnHeader={function ({ title }, { addCard }) {
|
||||||
const kanbanForm = useRef(null);
|
const kanbanForm = useRef(null);
|
||||||
const cardInput = useRef(null);
|
const cardInput = useRef(null);
|
||||||
|
|||||||
@@ -145,7 +145,10 @@ export default function CenterDashboard() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载实时行情失败:', error);
|
logger.error('Center', 'loadRealtimeQuotes', error, {
|
||||||
|
userId: user?.id,
|
||||||
|
watchlistLength: watchlist.length
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setQuotesLoading(false);
|
setQuotesLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import { useAuth } from '../../contexts/AuthContext';
|
|||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import heroBg from '../../assets/img/BackgroundCard1.png';
|
import heroBg from '../../assets/img/BackgroundCard1.png';
|
||||||
import '../../styles/home-animations.css';
|
import '../../styles/home-animations.css';
|
||||||
|
import { logger } from '../../utils/logger';
|
||||||
|
|
||||||
export default function HomePage() {
|
export default function HomePage() {
|
||||||
const { user, isAuthenticated } = useAuth(); // ⚡ 移除 isLoading,不再依赖它
|
const { user, isAuthenticated } = useAuth(); // ⚡ 移除 isLoading,不再依赖它
|
||||||
@@ -27,15 +28,12 @@ export default function HomePage() {
|
|||||||
|
|
||||||
// 保留原有的调试信息
|
// 保留原有的调试信息
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('🏠 HomePage AuthContext 状态:', {
|
logger.debug('HomePage', 'AuthContext状态', {
|
||||||
user,
|
userId: user?.id,
|
||||||
|
username: user?.username,
|
||||||
|
nickname: user?.nickname,
|
||||||
isAuthenticated,
|
isAuthenticated,
|
||||||
hasUser: !!user,
|
hasUser: !!user
|
||||||
userInfo: user ? {
|
|
||||||
id: user.id,
|
|
||||||
username: user.username,
|
|
||||||
nickname: user.nickname
|
|
||||||
} : null
|
|
||||||
});
|
});
|
||||||
}, [user, isAuthenticated]);
|
}, [user, isAuthenticated]);
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import {
|
|||||||
Icon,
|
Icon,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { StarIcon, TriangleUpIcon } from '@chakra-ui/icons';
|
import { StarIcon, TriangleUpIcon } from '@chakra-ui/icons';
|
||||||
|
import { logger } from '../../../utils/logger';
|
||||||
|
|
||||||
const HighPositionStocks = ({ dateStr }) => {
|
const HighPositionStocks = ({ dateStr }) => {
|
||||||
const [highPositionData, setHighPositionData] = useState(null);
|
const [highPositionData, setHighPositionData] = useState(null);
|
||||||
@@ -46,16 +47,25 @@ const HighPositionStocks = ({ dateStr }) => {
|
|||||||
const response = await fetch(`${API_URL}/api/limit-analyse/high-position-stocks?date=${dateStr}`);
|
const response = await fetch(`${API_URL}/api/limit-analyse/high-position-stocks?date=${dateStr}`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
console.log('High position stocks API response:', data); // 添加调试信息
|
logger.debug('HighPositionStocks', 'API响应', {
|
||||||
|
date: dateStr,
|
||||||
|
success: data.success,
|
||||||
|
dataLength: data.data?.length
|
||||||
|
});
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
setHighPositionData(data.data);
|
setHighPositionData(data.data);
|
||||||
} else {
|
} else {
|
||||||
console.error('API returned success: false', data);
|
logger.warn('HighPositionStocks', 'API返回失败', {
|
||||||
|
date: dateStr,
|
||||||
|
error: data.error
|
||||||
|
});
|
||||||
setHighPositionData(null);
|
setHighPositionData(null);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch high position stocks:', error);
|
logger.error('HighPositionStocks', 'fetchHighPositionStocks', error, {
|
||||||
|
date: dateStr
|
||||||
|
});
|
||||||
setHighPositionData(null);
|
setHighPositionData(null);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
import { FaCheckCircle, FaTimesCircle } from "react-icons/fa";
|
import { FaCheckCircle, FaTimesCircle } from "react-icons/fa";
|
||||||
import { authService } from "../../services/authService";
|
import { authService } from "../../services/authService";
|
||||||
import { useAuth } from "../../contexts/AuthContext";
|
import { useAuth } from "../../contexts/AuthContext";
|
||||||
|
import { logger } from "../../utils/logger";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信H5授权回调页面
|
* 微信H5授权回调页面
|
||||||
@@ -69,7 +70,11 @@ export default function WechatCallback() {
|
|||||||
navigate("/home", { replace: true });
|
navigate("/home", { replace: true });
|
||||||
}, 1500);
|
}, 1500);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("微信授权回调处理失败:", error);
|
logger.error('WechatCallback', 'handleCallback', error, {
|
||||||
|
code: searchParams.get("code"),
|
||||||
|
state: searchParams.get("state"),
|
||||||
|
errorMessage: error.message
|
||||||
|
});
|
||||||
setStatus("error");
|
setStatus("error");
|
||||||
setMessage(error.message || "授权失败,请重试");
|
setMessage(error.message || "授权失败,请重试");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user