refactor(Company): fetch 请求迁移至 axios
- DeepAnalysis: 4 个 fetch → axios - DynamicTracking: 3 个 fetch → axios (NewsPanel, ForecastPanel) - MarketDataView/services: 4 个 fetch → axios - CompanyOverview/hooks: 9 个 fetch → axios (6 个文件) - StockQuoteCard/hooks: 1 个 fetch → axios - ValueChainNodeCard: 1 个 fetch → axios 清理: - 删除未使用的 useCompanyOverviewData.ts - 移除所有 getApiBase/API_BASE_URL 引用 总计: 22 个 fetch 调用迁移, 复用项目已有的 axios 拦截器配置 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -3,13 +3,11 @@
|
||||
|
||||
import React, { useState, useEffect, useCallback, useRef } from "react";
|
||||
import { logger } from "@utils/logger";
|
||||
import { getApiBase } from "@utils/apiConfig";
|
||||
import axios from "@utils/axiosConfig";
|
||||
|
||||
// 复用原有的展示组件
|
||||
import DeepAnalysisTab from "../CompanyOverview/DeepAnalysisTab";
|
||||
|
||||
const API_BASE_URL = getApiBase();
|
||||
|
||||
/**
|
||||
* Tab 与 API 接口映射
|
||||
* - strategy 和 business 共用 comprehensive 接口
|
||||
@@ -84,9 +82,9 @@ const DeepAnalysis = ({ stockCode }) => {
|
||||
switch (apiKey) {
|
||||
case "comprehensive":
|
||||
setComprehensiveLoading(true);
|
||||
const comprehensiveRes = await fetch(
|
||||
`${API_BASE_URL}/api/company/comprehensive-analysis/${stockCode}`
|
||||
).then((r) => r.json());
|
||||
const { data: comprehensiveRes } = await axios.get(
|
||||
`/api/company/comprehensive-analysis/${stockCode}`
|
||||
);
|
||||
// 检查 stockCode 是否已变更(防止竞态)
|
||||
if (currentStockCodeRef.current === stockCode) {
|
||||
if (comprehensiveRes.success)
|
||||
@@ -97,9 +95,9 @@ const DeepAnalysis = ({ stockCode }) => {
|
||||
|
||||
case "valueChain":
|
||||
setValueChainLoading(true);
|
||||
const valueChainRes = await fetch(
|
||||
`${API_BASE_URL}/api/company/value-chain-analysis/${stockCode}`
|
||||
).then((r) => r.json());
|
||||
const { data: valueChainRes } = await axios.get(
|
||||
`/api/company/value-chain-analysis/${stockCode}`
|
||||
);
|
||||
if (currentStockCodeRef.current === stockCode) {
|
||||
if (valueChainRes.success) setValueChainData(valueChainRes.data);
|
||||
loadedApisRef.current.valueChain = true;
|
||||
@@ -108,9 +106,9 @@ const DeepAnalysis = ({ stockCode }) => {
|
||||
|
||||
case "keyFactors":
|
||||
setKeyFactorsLoading(true);
|
||||
const keyFactorsRes = await fetch(
|
||||
`${API_BASE_URL}/api/company/key-factors-timeline/${stockCode}`
|
||||
).then((r) => r.json());
|
||||
const { data: keyFactorsRes } = await axios.get(
|
||||
`/api/company/key-factors-timeline/${stockCode}`
|
||||
);
|
||||
if (currentStockCodeRef.current === stockCode) {
|
||||
if (keyFactorsRes.success) setKeyFactorsData(keyFactorsRes.data);
|
||||
loadedApisRef.current.keyFactors = true;
|
||||
@@ -119,9 +117,9 @@ const DeepAnalysis = ({ stockCode }) => {
|
||||
|
||||
case "industryRank":
|
||||
setIndustryRankLoading(true);
|
||||
const industryRankRes = await fetch(
|
||||
`${API_BASE_URL}/api/financial/industry-rank/${stockCode}`
|
||||
).then((r) => r.json());
|
||||
const { data: industryRankRes } = await axios.get(
|
||||
`/api/financial/industry-rank/${stockCode}`
|
||||
);
|
||||
if (currentStockCodeRef.current === stockCode) {
|
||||
if (industryRankRes.success) setIndustryRankData(industryRankRes.data);
|
||||
loadedApisRef.current.industryRank = true;
|
||||
|
||||
Reference in New Issue
Block a user