This commit is contained in:
2026-03-22 14:43:35 +08:00
parent ccb6704528
commit c8c4228446

View File

@@ -1,4 +1,5 @@
<script lang="ts" setup>
import Decimal from 'decimal.js'
import { Icon } from '@iconify/vue'
import VChart from 'vue-echarts'
@@ -11,6 +12,15 @@ import {
useGetUserGrowthQuery,
} from '@/services/api/monisuo-admin.api'
// 计算增长率
function calcGrowthRate(current: number, previous: number): string {
if (previous === 0)
return current > 0 ? '+100%' : '0%'
const rate = new Decimal(current).minus(previous).div(previous).mul(100).toDecimalPlaces(1)
const sign = rate.gte(0) ? '+' : ''
return `${sign}${rate}%`
}
// ========== 模块1: 盈利分析 ==========
const { data: profitData, isLoading: profitLoading } = useGetProfitAnalysisQuery('month')
@@ -23,7 +33,7 @@ const profitMetrics = computed(() => {
{ label: '交易手续费', value: data.tradeFee, rate: data.tradeFeeRate, icon: 'lucide:percent', color: 'text-green-600' },
{ label: '充提手续费', value: data.fundFee, rate: data.fundFeeRate, icon: 'lucide:credit-card', color: 'text-blue-600' },
{ label: '资金利差', value: data.interestProfit, rate: data.interestRate, icon: 'lucide:trending-up', color: 'text-purple-600' },
{ label: '本月收益', value: data.totalProfit, rate: '+18.5%', icon: 'lucide:dollar-sign', color: 'text-orange-600' },
{ label: '本月收益', value: data.totalProfit, rate: '本月', icon: 'lucide:dollar-sign', color: 'text-orange-600' },
]
})
@@ -79,11 +89,30 @@ const userMetrics = computed(() => {
if (!data)
return []
const trend = data.trend || []
const len = trend.length
const thisMonth = len >= 1 ? trend[len - 1] : null
const lastMonth = len >= 2 ? trend[len - 2] : null
// 新增用户增长率
const newUsersChange = thisMonth && lastMonth
? calcGrowthRate(thisMonth.newUsers as number, lastMonth.newUsers as number)
: '+0%'
// 活跃用户增长率
const activeUsersChange = thisMonth && lastMonth
? calcGrowthRate(thisMonth.activeUsers as number, lastMonth.activeUsers as number)
: '+0%'
// 总用户增长率(本月总用户 vs 上月累计)
const lastMonthTotal = len >= 2 && thisMonth ? data.totalUsers - thisMonth.newUsers : data.totalUsers
const totalUsersChange = calcGrowthRate(data.totalUsers, lastMonthTotal)
return [
{ label: '新增用户', value: data.monthNewUsers, change: '+15.3%', up: true },
{ label: '活跃用户', value: data.activeUsersToday, change: '+8.7%', up: true },
{ label: '总用户', value: data.totalUsers, change: '+12.1%', up: true },
{ label: '留存率', value: '68%', change: '+5.2%', up: true },
{ label: '新增用户', value: data.monthNewUsers, change: newUsersChange, up: !newUsersChange.startsWith('-') },
{ label: '活跃用户', value: data.activeUsersToday, change: activeUsersChange, up: !activeUsersChange.startsWith('-') },
{ label: '总用户', value: data.totalUsers, change: totalUsersChange, up: !totalUsersChange.startsWith('-') },
{ label: '留存率', value: '-', change: '-', up: true },
]
})