1
0

perf: 优化财务数据的采集和显示

This commit is contained in:
2025-09-15 13:56:07 +08:00
parent 4cc7d2344f
commit 9f781ce794
16 changed files with 229 additions and 865 deletions

View File

@@ -2,10 +2,11 @@ import React from 'react'
import {useParams} from 'react-router'
import {amisRender, commonInfo, readOnlyDialogOptions, remoteMappings} from '../../util/amis.tsx'
import type {Schema} from 'amis'
import {isNil} from 'es-toolkit'
// 格式化财务数字显示的公共函数
const formatFinanceNumber = (value: number): string => {
if (value === null || value === undefined) {
if (isNil(value)) {
return '-'
}
@@ -24,7 +25,17 @@ const formatFinanceNumber = (value: number): string => {
return isNegative ? `-${formatted}` : formatted
}
const financePropertyLabel = (id: string | undefined, label: string, type: string, field: string): Schema => {
// 格式化百分比数字显示的公共函数
const formatPercentageNumber = (value: number): string => {
if (isNil(value)) {
return '-'
}
return `${(value * 100).toFixed(2)}%`
}
type FinanceType = 'PERCENTAGE' | 'FINANCE'
const financePropertyLabel = (id: string | undefined, label: string, type: FinanceType, field: string): Schema => {
if (!id) {
return {
type: 'tpl',
@@ -32,6 +43,7 @@ const financePropertyLabel = (id: string | undefined, label: string, type: strin
}
}
let current = new Date().getFullYear()
let formatter: (value: number) => string = type === 'PERCENTAGE' ? formatPercentageNumber : formatFinanceNumber
return {
type: 'wrapper',
size: 'none',
@@ -54,7 +66,7 @@ const financePropertyLabel = (id: string | undefined, label: string, type: strin
...readOnlyDialogOptions(),
body: {
type: 'chart',
api: `get:${commonInfo.baseUrl}/stock/finance/${id}/${type}/${field}`,
api: `get:${commonInfo.baseUrl}/stock/finance/${id}/${field}`,
height: 500,
config: {
tooltip: {
@@ -68,7 +80,7 @@ const financePropertyLabel = (id: string | undefined, label: string, type: strin
padding: [10, 15],
formatter: (params: any) => {
const item = params[0]
return `${item.name}<br/>${item.marker}${formatFinanceNumber(item.value)}`
return `${item.name}<br/>${item.marker}${formatter(item.value)}`
},
},
grid: {
@@ -116,7 +128,7 @@ const financePropertyLabel = (id: string | undefined, label: string, type: strin
color: '#999',
fontSize: 12,
formatter: (value: number) => {
return formatFinanceNumber(value)
return formatter(value)
},
},
axisTick: {
@@ -163,7 +175,7 @@ const financePropertyLabel = (id: string | undefined, label: string, type: strin
fontWeight: 'bold',
fontSize: 12,
formatter: (params: any) => {
return formatFinanceNumber(params.value)
return formatter(params.value)
},
},
},
@@ -212,30 +224,49 @@ function StockDetail() {
{
className: 'my-2',
type: 'property',
column: 4,
items: [
{
label: financePropertyLabel(id, '总资产', 'balanceSheet', 'totalAssets'),
label: financePropertyLabel(id, '总资产', 'FINANCE', 'totalAssets'),
content: '${balanceSheet.totalAssets}',
span: 4,
},
{
label: financePropertyLabel(id, '流动资产', 'balanceSheet', 'totalCurrentAssets'),
content: '${balanceSheet.totalCurrentAssets}',
label: financePropertyLabel(id, '流动资产', 'FINANCE', 'currentAssets'),
content: '${balanceSheet.currentAssets}',
},
{
label: financePropertyLabel(id, '流动资产', 'balanceSheet', 'totalNonCurrentAssets'),
content: '${balanceSheet.totalNonCurrentAssets}',
label: financePropertyLabel(id, '流动资产占比', 'PERCENTAGE', 'currentAssetsToTotalAssetsRatio'),
content: '${balanceSheet.currentAssetsRatio}',
},
{
label: financePropertyLabel(id, '总负债', 'balanceSheet', 'totalLiabilities'),
label: financePropertyLabel(id, '非流动资产', 'FINANCE', 'fixedAssets'),
content: '${balanceSheet.fixedAssets}',
},
{
label: financePropertyLabel(id, '非流动资产占比', 'PERCENTAGE', 'fixedAssetsToTotalAssetsRatio'),
content: '${balanceSheet.fixedAssetsRatio}',
},
{
label: financePropertyLabel(id, '总负债', 'FINANCE', 'totalLiabilities'),
content: '${balanceSheet.totalLiabilities}',
span: 4,
},
{
label: financePropertyLabel(id, '流动负债', 'balanceSheet', 'totalCurrentLiabilities'),
content: '${balanceSheet.totalCurrentLiabilities}',
label: financePropertyLabel(id, '流动负债', 'FINANCE', 'currentLiabilities'),
content: '${balanceSheet.currentLiabilities}',
},
{
label: financePropertyLabel(id, '流动负债', 'balanceSheet', 'totalNonCurrentLiabilities'),
content: '${balanceSheet.totalNonCurrentLiabilities}',
label: financePropertyLabel(id, '流动负债占比', 'PERCENTAGE', 'currentLiabilitiesToTotalAssetsRatio'),
content: '${balanceSheet.currentLiabilitiesRatio}',
},
{
label: financePropertyLabel(id, '非流动负债', 'FINANCE', 'longTermLiabilities'),
content: '${balanceSheet.longTermLiabilities}',
},
{
label: financePropertyLabel(id, '非流动负债占比', 'PERCENTAGE', 'longTermLiabilitiesToTotalAssetsRatio'),
content: '${balanceSheet.longTermLiabilitiesRatio}',
},
],
},
@@ -245,16 +276,16 @@ function StockDetail() {
type: 'property',
items: [
{
label: financePropertyLabel(id, '营业收入', 'income', 'totalOperatingRevenue'),
content: '${income.totalOperatingRevenue}',
label: financePropertyLabel(id, '营业收入', 'FINANCE', 'operatingRevenue'),
content: '${income.operatingRevenue}',
},
{
label: financePropertyLabel(id, '营业成本', 'income', 'totalOperatingCost'),
content: '${income.totalOperatingCost}',
label: financePropertyLabel(id, '营业成本', 'FINANCE', 'operatingCost'),
content: '${income.operatingCost}',
},
{
label: financePropertyLabel(id, '营业利润', 'income', 'totalProfit'),
content: '${income.totalProfit}',
label: financePropertyLabel(id, '营业利润', 'FINANCE', 'operatingProfit'),
content: '${income.operatingProfit}',
},
],
},
@@ -264,7 +295,7 @@ function StockDetail() {
type: 'property',
items: [
{
label: financePropertyLabel(id, '净利润', 'cashflow', 'netProfit'),
label: financePropertyLabel(id, '净利润', 'FINANCE', 'netProfit'),
content: '${cashFlow.netProfit}',
},
],