feat:添加mock接口
1. ✅ Profile 和 Settings 页面(2个文件) 2. ✅ EventDetail 页面(1个文件) 3. ✅ 身份验证组件(WechatRegister.js) 4. ✅ Company 页面(CompanyOverview, index, FinancialPanorama, MarketDataView) 5. ✅ Concept 页面(ConceptTimelineModal, ConceptStatsPanel, index)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// src/views/Company/FinancialPanorama.jsx
|
||||
import React, { useState, useEffect, useMemo } from 'react';
|
||||
import { logger } from '../../utils/logger';
|
||||
import {
|
||||
Box,
|
||||
Container,
|
||||
@@ -112,6 +113,7 @@ const FinancialPanorama = ({ stockCode: propStockCode }) => {
|
||||
// 加载所有财务数据
|
||||
const loadFinancialData = async () => {
|
||||
if (!stockCode || stockCode.length !== 6) {
|
||||
logger.warn('FinancialPanorama', 'loadFinancialData', '无效的股票代码', { stockCode });
|
||||
toast({
|
||||
title: '请输入有效的6位股票代码',
|
||||
status: 'warning',
|
||||
@@ -120,9 +122,10 @@ const FinancialPanorama = ({ stockCode: propStockCode }) => {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug('FinancialPanorama', '开始加载财务数据', { stockCode, selectedPeriods });
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
|
||||
try {
|
||||
// 并行加载所有数据
|
||||
const [
|
||||
@@ -158,19 +161,14 @@ const FinancialPanorama = ({ stockCode: propStockCode }) => {
|
||||
if (rankRes.success) setIndustryRank(rankRes.data);
|
||||
if (comparisonRes.success) setComparison(comparisonRes.data);
|
||||
|
||||
toast({
|
||||
title: '财务数据加载成功',
|
||||
status: 'success',
|
||||
duration: 2000,
|
||||
});
|
||||
// ❌ 移除数据加载成功toast
|
||||
logger.info('FinancialPanorama', '财务数据加载成功', { stockCode });
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
toast({
|
||||
title: '数据加载失败',
|
||||
description: err.message,
|
||||
status: 'error',
|
||||
duration: 5000,
|
||||
});
|
||||
logger.error('FinancialPanorama', 'loadFinancialData', err, { stockCode, selectedPeriods });
|
||||
|
||||
// ❌ 移除数据加载失败toast
|
||||
// toast({ title: '数据加载失败', description: err.message, status: 'error', duration: 5000 });
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -1501,6 +1499,7 @@ const FinancialPanorama = ({ stockCode: propStockCode }) => {
|
||||
|
||||
const loadCompareData = async () => {
|
||||
if (!compareStock || compareStock.length !== 6) {
|
||||
logger.warn('FinancialPanorama', 'loadCompareData', '无效的对比股票代码', { compareStock });
|
||||
toast({
|
||||
title: '请输入有效的6位股票代码',
|
||||
status: 'warning',
|
||||
@@ -1508,7 +1507,8 @@ const FinancialPanorama = ({ stockCode: propStockCode }) => {
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
logger.debug('FinancialPanorama', '开始加载对比数据', { currentStock, compareStock });
|
||||
setCompareLoading(true);
|
||||
try {
|
||||
const [stockInfoRes, metricsRes, comparisonRes] = await Promise.all([
|
||||
@@ -1516,25 +1516,20 @@ const FinancialPanorama = ({ stockCode: propStockCode }) => {
|
||||
financialService.getFinancialMetrics(compareStock, 4),
|
||||
financialService.getPeriodComparison(compareStock, 4)
|
||||
]);
|
||||
|
||||
|
||||
setCompareData({
|
||||
stockInfo: stockInfoRes.data,
|
||||
metrics: metricsRes.data,
|
||||
comparison: comparisonRes.data
|
||||
});
|
||||
|
||||
toast({
|
||||
title: '对比数据加载成功',
|
||||
status: 'success',
|
||||
duration: 2000,
|
||||
});
|
||||
|
||||
// ❌ 移除对比数据加载成功toast
|
||||
logger.info('FinancialPanorama', '对比数据加载成功', { currentStock, compareStock });
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: '加载对比数据失败',
|
||||
description: error.message,
|
||||
status: 'error',
|
||||
duration: 3000,
|
||||
});
|
||||
logger.error('FinancialPanorama', 'loadCompareData', error, { currentStock, compareStock });
|
||||
|
||||
// ❌ 移除对比数据加载失败toast
|
||||
// toast({ title: '加载对比数据失败', description: error.message, status: 'error', duration: 3000 });
|
||||
} finally {
|
||||
setCompareLoading(false);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// src/views/Market/MarketDataPro.jsx
|
||||
import React, { useState, useEffect, useMemo } from 'react';
|
||||
import { logger } from '../../utils/logger';
|
||||
import {
|
||||
Box,
|
||||
Container,
|
||||
@@ -151,7 +152,7 @@ const marketService = {
|
||||
}
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
console.error(`API request failed for ${url}:`, error);
|
||||
logger.error('marketService', 'apiRequest', error, { url });
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
@@ -317,6 +318,7 @@ const MarketDataView = ({ stockCode: propStockCode }) => {
|
||||
|
||||
// 加载数据
|
||||
const loadMarketData = async () => {
|
||||
logger.debug('MarketDataView', '开始加载市场数据', { stockCode, selectedPeriod });
|
||||
setLoading(true);
|
||||
try {
|
||||
const [summaryRes, tradeRes, fundingRes, bigDealRes, unusualRes, pledgeRes, riseAnalysisRes] = await Promise.all([
|
||||
@@ -337,12 +339,12 @@ const MarketDataView = ({ stockCode: propStockCode }) => {
|
||||
if (pledgeRes.success) setPledgeData(pledgeRes.data);
|
||||
if (riseAnalysisRes.success) {
|
||||
setRiseAnalysisData(riseAnalysisRes.data);
|
||||
|
||||
|
||||
// 创建分析数据映射
|
||||
const tempAnalysisMap = {};
|
||||
if (tradeRes.success && tradeRes.data && riseAnalysisRes.data) {
|
||||
riseAnalysisRes.data.forEach(analysis => {
|
||||
const dateIndex = tradeRes.data.findIndex(item =>
|
||||
const dateIndex = tradeRes.data.findIndex(item =>
|
||||
item.date.substring(0, 10) === analysis.trade_date
|
||||
);
|
||||
if (dateIndex !== -1) {
|
||||
@@ -352,22 +354,14 @@ const MarketDataView = ({ stockCode: propStockCode }) => {
|
||||
}
|
||||
setAnalysisMap(tempAnalysisMap);
|
||||
}
|
||||
|
||||
toast({
|
||||
title: '数据加载成功',
|
||||
status: 'success',
|
||||
duration: 2000,
|
||||
isClosable: true,
|
||||
});
|
||||
|
||||
// ❌ 移除数据加载成功toast
|
||||
logger.info('MarketDataView', '市场数据加载成功', { stockCode });
|
||||
} catch (error) {
|
||||
console.error('Failed to load market data:', error);
|
||||
toast({
|
||||
title: '数据加载失败',
|
||||
description: error.message,
|
||||
status: 'error',
|
||||
duration: 5000,
|
||||
isClosable: true,
|
||||
});
|
||||
logger.error('MarketDataView', 'loadMarketData', error, { stockCode, selectedPeriod });
|
||||
|
||||
// ❌ 移除数据加载失败toast
|
||||
// toast({ title: '数据加载失败', description: error.message, status: 'error', duration: 5000, isClosable: true });
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -375,6 +369,7 @@ const MarketDataView = ({ stockCode: propStockCode }) => {
|
||||
|
||||
// 获取分钟频数据
|
||||
const loadMinuteData = async () => {
|
||||
logger.debug('MarketDataView', '开始加载分钟频数据', { stockCode });
|
||||
setMinuteLoading(true);
|
||||
try {
|
||||
const response = await fetch(
|
||||
@@ -394,19 +389,17 @@ const MarketDataView = ({ stockCode: propStockCode }) => {
|
||||
const data = await response.json();
|
||||
if (data.data && Array.isArray(data.data)) {
|
||||
setMinuteData(data);
|
||||
logger.info('MarketDataView', '分钟频数据加载成功', { stockCode, dataPoints: data.data.length });
|
||||
} else {
|
||||
setMinuteData({ data: [], code: stockCode, name: '', trade_date: '', type: 'minute' });
|
||||
logger.warn('MarketDataView', '分钟频数据为空', { stockCode });
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to load minute data:', error);
|
||||
toast({
|
||||
title: '分钟数据加载失败',
|
||||
description: error.message,
|
||||
status: 'error',
|
||||
duration: 3000,
|
||||
isClosable: true,
|
||||
});
|
||||
logger.error('MarketDataView', 'loadMinuteData', error, { stockCode });
|
||||
|
||||
// ❌ 移除分钟数据加载失败toast
|
||||
// toast({ title: '分钟数据加载失败', description: error.message, status: 'error', duration: 3000, isClosable: true });
|
||||
setMinuteData({ data: [], code: stockCode, name: '', trade_date: '', type: 'minute' });
|
||||
} finally {
|
||||
setMinuteLoading(false);
|
||||
|
||||
@@ -29,6 +29,7 @@ import { SearchIcon, MoonIcon, SunIcon, StarIcon } from '@chakra-ui/icons';
|
||||
import { FaChartLine, FaMoneyBillWave, FaChartBar, FaInfoCircle } from 'react-icons/fa';
|
||||
import HomeNavbar from '../../components/Navbars/HomeNavbar';
|
||||
import { useAuth } from '../../contexts/AuthContext';
|
||||
import { logger } from '../../utils/logger';
|
||||
import FinancialPanorama from './FinancialPanorama';
|
||||
import ForecastReport from './ForecastReport';
|
||||
import MarketDataView from './MarketDataView';
|
||||
@@ -99,10 +100,12 @@ const CompanyIndex = () => {
|
||||
|
||||
const handleWatchlistToggle = async () => {
|
||||
if (!stockCode) {
|
||||
logger.warn('CompanyIndex', 'handleWatchlistToggle', '无效的股票代码', { stockCode });
|
||||
toast({ title: '无效的股票代码', status: 'error', duration: 2000 });
|
||||
return;
|
||||
}
|
||||
if (!isAuthenticated) {
|
||||
logger.warn('CompanyIndex', 'handleWatchlistToggle', '用户未登录', { stockCode });
|
||||
toast({ title: '请先登录后再加入自选', status: 'warning', duration: 2000 });
|
||||
return;
|
||||
}
|
||||
@@ -110,25 +113,39 @@ const CompanyIndex = () => {
|
||||
setIsWatchlistLoading(true);
|
||||
const base = getApiBase();
|
||||
if (isInWatchlist) {
|
||||
const resp = await fetch(base + `/api/account/watchlist/${stockCode}`, {
|
||||
logger.debug('CompanyIndex', '准备从自选移除', { stockCode });
|
||||
const url = base + `/api/account/watchlist/${stockCode}`;
|
||||
logger.api.request('DELETE', url, { stockCode });
|
||||
|
||||
const resp = await fetch(url, {
|
||||
method: 'DELETE',
|
||||
credentials: 'include'
|
||||
});
|
||||
|
||||
logger.api.response('DELETE', url, resp.status);
|
||||
if (!resp.ok) throw new Error('删除失败');
|
||||
setIsInWatchlist(false);
|
||||
toast({ title: '已从自选移除', status: 'info', duration: 1500 });
|
||||
} else {
|
||||
const resp = await fetch(base + '/api/account/watchlist', {
|
||||
logger.debug('CompanyIndex', '准备添加到自选', { stockCode });
|
||||
const url = base + '/api/account/watchlist';
|
||||
const body = { stock_code: stockCode };
|
||||
logger.api.request('POST', url, body);
|
||||
|
||||
const resp = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({ stock_code: stockCode })
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
|
||||
logger.api.response('POST', url, resp.status);
|
||||
if (!resp.ok) throw new Error('添加失败');
|
||||
setIsInWatchlist(true);
|
||||
toast({ title: '已加入自选', status: 'success', duration: 1500 });
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('CompanyIndex', 'handleWatchlistToggle', error, { stockCode, isInWatchlist });
|
||||
toast({ title: '操作失败,请稍后重试', status: 'error', duration: 2000 });
|
||||
} finally {
|
||||
setIsWatchlistLoading(false);
|
||||
|
||||
Reference in New Issue
Block a user