|
|
@@ -1,13 +1,65 @@
|
|
|
-import React, { useState } from 'react';
|
|
|
+import React, { useState, useEffect } from 'react';
|
|
|
+import { useQuery } from '@tanstack/react-query';
|
|
|
import { AssetMetrics } from './components/AssetMetrics';
|
|
|
import { ProfitMetrics } from './components/ProfitMetrics';
|
|
|
import { IncomeMetrics } from './components/IncomeMetrics';
|
|
|
import { DebtRatioMetrics } from './components/DebtRatioMetrics';
|
|
|
import { VariationModal } from './components/VariationModal';
|
|
|
+import { client } from '@/api';
|
|
|
+
|
|
|
+interface FinancialData {
|
|
|
+ code: number;
|
|
|
+ msg: string;
|
|
|
+ rows: Array<{
|
|
|
+ assetTotalNet: Array<{
|
|
|
+ id: number;
|
|
|
+ year: number;
|
|
|
+ assetTotal: number;
|
|
|
+ assetNet: number;
|
|
|
+ dataDeadline: string;
|
|
|
+ createTime: string;
|
|
|
+ updateTime: string;
|
|
|
+ }>;
|
|
|
+ profitTotalNet: Array<{
|
|
|
+ id: number;
|
|
|
+ year: number;
|
|
|
+ profitTotal: number;
|
|
|
+ profitNet: number;
|
|
|
+ dataDeadline: string;
|
|
|
+ createTime: string;
|
|
|
+ updateTime: string;
|
|
|
+ }>;
|
|
|
+ incomeStatement: Array<{
|
|
|
+ id: number;
|
|
|
+ year: number;
|
|
|
+ income: number;
|
|
|
+ dataDeadline: string;
|
|
|
+ createTime: string;
|
|
|
+ updateTime: string;
|
|
|
+ }>;
|
|
|
+ assetLiabilityRatio: Array<{
|
|
|
+ id: number;
|
|
|
+ year: number;
|
|
|
+ assetLiabilityRatio: number;
|
|
|
+ dataDeadline: string;
|
|
|
+ createTime: string;
|
|
|
+ updateTime: string;
|
|
|
+ }>;
|
|
|
+ }>;
|
|
|
+}
|
|
|
|
|
|
export function FinancialDashboard() {
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
|
|
|
|
+ // 获取财务数据
|
|
|
+ const { data: financialData, isLoading, error } = useQuery({
|
|
|
+ queryKey: ['financial-data'],
|
|
|
+ queryFn: async () => {
|
|
|
+ const response = await client.dash.outlook.$get();
|
|
|
+ return response.json() as Promise<FinancialData>;
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
const handleOpenModal = () => {
|
|
|
setIsModalOpen(true);
|
|
|
};
|
|
|
@@ -16,6 +68,46 @@ export function FinancialDashboard() {
|
|
|
setIsModalOpen(false);
|
|
|
};
|
|
|
|
|
|
+ // 加载状态
|
|
|
+ if (isLoading) {
|
|
|
+ return (
|
|
|
+ <div className="min-h-screen bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900 text-white p-6 flex items-center justify-center">
|
|
|
+ <div className="text-center">
|
|
|
+ <div className="animate-spin rounded-full h-12 w-12 border-b-2 border-white mx-auto mb-4"></div>
|
|
|
+ <p className="text-lg">加载财务数据中...</p>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // 错误状态
|
|
|
+ if (error) {
|
|
|
+ return (
|
|
|
+ <div className="min-h-screen bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900 text-white p-6 flex items-center justify-center">
|
|
|
+ <div className="text-center">
|
|
|
+ <div className="text-red-400 text-4xl mb-4">⚠️</div>
|
|
|
+ <h2 className="text-xl font-bold mb-2">数据加载失败</h2>
|
|
|
+ <p className="text-slate-300">无法获取财务数据,请稍后重试</p>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // 数据为空状态
|
|
|
+ if (!financialData || !financialData.rows || financialData.rows.length === 0) {
|
|
|
+ return (
|
|
|
+ <div className="min-h-screen bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900 text-white p-6 flex items-center justify-center">
|
|
|
+ <div className="text-center">
|
|
|
+ <div className="text-slate-400 text-4xl mb-4">📊</div>
|
|
|
+ <h2 className="text-xl font-bold mb-2">暂无财务数据</h2>
|
|
|
+ <p className="text-slate-300">当前没有可显示的财务数据</p>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ const financialRow = financialData.rows[0];
|
|
|
+
|
|
|
return (
|
|
|
<div className="min-h-screen bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900 text-white p-6">
|
|
|
{/* 页面标题 */}
|
|
|
@@ -29,22 +121,22 @@ export function FinancialDashboard() {
|
|
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6 max-w-7xl mx-auto">
|
|
|
{/* 资产负债率模块 */}
|
|
|
<div className="bg-slate-800/50 backdrop-blur-sm rounded-xl border border-slate-700/50 p-6">
|
|
|
- <AssetMetrics />
|
|
|
+ <AssetMetrics data={financialRow.assetTotalNet} />
|
|
|
</div>
|
|
|
|
|
|
{/* 利润总额与净利润模块 */}
|
|
|
<div className="bg-slate-800/50 backdrop-blur-sm rounded-xl border border-slate-700/50 p-6">
|
|
|
- <ProfitMetrics />
|
|
|
+ <ProfitMetrics data={financialRow.profitTotalNet} />
|
|
|
</div>
|
|
|
|
|
|
{/* 收入模块 */}
|
|
|
<div className="bg-slate-800/50 backdrop-blur-sm rounded-xl border border-slate-700/50 p-6">
|
|
|
- <IncomeMetrics />
|
|
|
+ <IncomeMetrics data={financialRow.incomeStatement} />
|
|
|
</div>
|
|
|
|
|
|
{/* 资产负债率(百分比)模块 */}
|
|
|
<div className="bg-slate-800/50 backdrop-blur-sm rounded-xl border border-slate-700/50 p-6">
|
|
|
- <DebtRatioMetrics />
|
|
|
+ <DebtRatioMetrics data={financialRow.assetLiabilityRatio} />
|
|
|
</div>
|
|
|
</div>
|
|
|
|