|
11 | 11 | value?: number |
12 | 12 | } |
13 | 13 |
|
| 14 | + interface RiskLiquidityItem { |
| 15 | + name: string |
| 16 | + value: number |
| 17 | + color: string |
| 18 | + } |
| 19 | +
|
14 | 20 | export let sources |
15 | 21 |
|
16 | 22 | const options: ApexOptions | any = genDonutOptions() |
17 | 23 | let percentages: PercentageItem[] = [] |
| 24 | + let riskDistribution: RiskLiquidityItem[] = [] |
| 25 | + let liquidityDistribution: RiskLiquidityItem[] = [] |
18 | 26 |
|
19 | 27 | $: { |
20 | 28 | options.series = [] |
|
28 | 36 | options.labels = labels |
29 | 37 | options.series = series |
30 | 38 | regenWealthPercentages(options) |
| 39 | + calculateRiskLiquidityDistribution(sources, totalSumNum) |
31 | 40 | } |
32 | 41 |
|
33 | 42 | const regenWealthPercentages = (sources) => { |
|
40 | 49 | }) |
41 | 50 | percentages = percentages.sort((a, b) => b.value - a.value) |
42 | 51 | } |
| 52 | +
|
| 53 | + const calculateRiskLiquidityDistribution = (sources, totalSum) => { |
| 54 | + // 计算风险分布 |
| 55 | + const riskGroups = {} |
| 56 | + sources.forEach((item) => { |
| 57 | + const risk = item.risk || 'LOW' |
| 58 | + if (!riskGroups[risk]) { |
| 59 | + riskGroups[risk] = 0 |
| 60 | + } |
| 61 | + riskGroups[risk] += item.amount |
| 62 | + }) |
| 63 | +
|
| 64 | + riskDistribution = Object.entries(riskGroups).map(([risk, amount]) => ({ |
| 65 | + name: $_(risk.toLowerCase()), |
| 66 | + value: Number(((Number(amount) / totalSum) * 100).toFixed(2)), |
| 67 | + color: getRiskColor(risk), |
| 68 | + })) |
| 69 | +
|
| 70 | + // 计算流动性分布 |
| 71 | + const liquidityGroups = {} |
| 72 | + sources.forEach((item) => { |
| 73 | + const liquidity = item.liquidity || 'GOOD' |
| 74 | + if (!liquidityGroups[liquidity]) { |
| 75 | + liquidityGroups[liquidity] = 0 |
| 76 | + } |
| 77 | + liquidityGroups[liquidity] += item.amount |
| 78 | + }) |
| 79 | +
|
| 80 | + liquidityDistribution = Object.entries(liquidityGroups).map(([liquidity, amount]) => ({ |
| 81 | + name: $_(liquidity.toLowerCase()), |
| 82 | + value: Number(((Number(amount) / totalSum) * 100).toFixed(2)), |
| 83 | + color: getLiquidityColor(liquidity), |
| 84 | + })) |
| 85 | + } |
| 86 | +
|
| 87 | + const getRiskColor = (risk: string): string => { |
| 88 | + switch (risk) { |
| 89 | + case 'LOW': |
| 90 | + return '#2edfa3' // success color |
| 91 | + case 'MIDDLE': |
| 92 | + return '#f8d826' // link color |
| 93 | + case 'HIGH': |
| 94 | + return '#ff4582' // mark color |
| 95 | + default: |
| 96 | + return '#B7B8B9' // grey color |
| 97 | + } |
| 98 | + } |
| 99 | +
|
| 100 | + const getLiquidityColor = (liquidity: string): string => { |
| 101 | + switch (liquidity) { |
| 102 | + case 'GOOD': |
| 103 | + return '#2edfa3' // success color |
| 104 | + case 'MIDDLE': |
| 105 | + return '#f8d826' // link color |
| 106 | + case 'POOR': |
| 107 | + return '#ff4582' // mark color |
| 108 | + default: |
| 109 | + return '#B7B8B9' // grey color |
| 110 | + } |
| 111 | + } |
43 | 112 | </script> |
44 | 113 |
|
45 | 114 | <Card size="xl" class="h-fit shadow-none md:p-4"> |
46 | 115 | <Caption title={$_('assetAllocation')} subtitle={$_('currentAssetStatus')}></Caption> |
| 116 | + |
| 117 | + <!-- 风险与流动性分布概览 --> |
| 118 | + <div class="my-4 grid grid-cols-2 gap-4 md:grid-cols-1"> |
| 119 | + <!-- 风险分布 --> |
| 120 | + <div class="rounded-lg border border-gray-200 p-4"> |
| 121 | + <h3 class="mb-3 text-lg font-semibold text-gray-800">{$_('risk')} {$_('distribution')}</h3> |
| 122 | + <div class="space-y-3"> |
| 123 | + {#each riskDistribution as item} |
| 124 | + <div class="flex items-center justify-between"> |
| 125 | + <div class="flex items-center space-x-2"> |
| 126 | + <div class="h-3 w-3 rounded-full" style="background-color: {item.color}"></div> |
| 127 | + <span class="text-sm font-medium text-gray-700">{item.name}</span> |
| 128 | + </div> |
| 129 | + <span class="text-blue text-sm font-bold">{item.value}%</span> |
| 130 | + </div> |
| 131 | + {/each} |
| 132 | + </div> |
| 133 | + </div> |
| 134 | + |
| 135 | + <!-- 流动性分布 --> |
| 136 | + <div class="rounded-lg border border-gray-200 p-4"> |
| 137 | + <h3 class="mb-3 text-lg font-semibold text-gray-800"> |
| 138 | + {$_('liquidity')} |
| 139 | + {$_('distribution')} |
| 140 | + </h3> |
| 141 | + <div class="space-y-3"> |
| 142 | + {#each liquidityDistribution as item} |
| 143 | + <div class="flex items-center justify-between"> |
| 144 | + <div class="flex items-center space-x-2"> |
| 145 | + <div class="h-3 w-3 rounded-full" style="background-color: {item.color}"></div> |
| 146 | + <span class="text-sm font-medium text-gray-700">{item.name}</span> |
| 147 | + </div> |
| 148 | + <span class="text-blue text-sm font-bold">{item.value}%</span> |
| 149 | + </div> |
| 150 | + {/each} |
| 151 | + </div> |
| 152 | + </div> |
| 153 | + </div> |
| 154 | + |
47 | 155 | <Chart {options}></Chart> |
| 156 | + |
48 | 157 | <div class="my-6 flex flex-wrap items-center justify-start pt-4 sm:pt-6 md:justify-evenly"> |
49 | 158 | {#each percentages as item} |
50 | 159 | <SmallPanel title={item.name} subtitle={`${item.value}%`} /> |
|
0 commit comments