feat(admin): full integration of order, product, and finance modules with real RPC data streams
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
<text class="icon-white">💰</text>
|
||||
</view>
|
||||
<view class="stat-content">
|
||||
<text class="stat-value">1447117274.55</text>
|
||||
<text class="stat-value">{{ statsData.current_balance.toFixed(2) }}</text>
|
||||
<text class="stat-label">当前余额</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -16,7 +16,7 @@
|
||||
<text class="icon-white">🏦</text>
|
||||
</view>
|
||||
<view class="stat-content">
|
||||
<text class="stat-value">1602611838.49</text>
|
||||
<text class="stat-value">{{ statsData.total_accumulation.toFixed(2) }}</text>
|
||||
<text class="stat-label">累计余额</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -25,7 +25,7 @@
|
||||
<text class="icon-white">💳</text>
|
||||
</view>
|
||||
<view class="stat-content">
|
||||
<text class="stat-value">155494563.94</text>
|
||||
<text class="stat-value">{{ statsData.total_consumption.toFixed(2) }}</text>
|
||||
<text class="stat-label">累计消耗余额</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -144,30 +144,31 @@
|
||||
<script setup lang="uts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import EChartsView from '@/uni_modules/charts/EChartsView.vue'
|
||||
import {
|
||||
fetchAdminBalanceStats,
|
||||
fetchAdminBalanceTrend,
|
||||
fetchAdminBalanceDistribution
|
||||
} from '@/services/admin/financeService.uts'
|
||||
|
||||
const trendOption = ref<any>(null)
|
||||
const sourceOption = ref<any>(null)
|
||||
const consumptionOption = ref<any>(null)
|
||||
const loading = ref(false)
|
||||
|
||||
// 顶部汇总指标
|
||||
const statsData = ref({
|
||||
current_balance: 0,
|
||||
total_accumulation: 0,
|
||||
total_consumption: 0
|
||||
})
|
||||
|
||||
// 样式切换状态: 0=图表, 1=列表
|
||||
const sourceStyleMode = ref(0)
|
||||
const consumptionStyleMode = ref(0)
|
||||
|
||||
// 统计数据 (使用 ref 保证响应式)
|
||||
const sourceData = ref([
|
||||
{ value: 125000.00, name: '系统增加', percent: 40.00 },
|
||||
{ value: 93750.00, name: '用户充值', percent: 30.00 },
|
||||
{ value: 78125.00, name: '佣金提现', percent: 25.00 },
|
||||
{ value: 62500.00, name: '抽奖赠送', percent: 20.00 },
|
||||
{ value: 46875.00, name: '商品退款', percent: 15.00 }
|
||||
])
|
||||
|
||||
const consumptionDataList = ref([
|
||||
{ value: 435692.51, name: '购买商品', percent: 50.00 },
|
||||
{ value: 8060.18, name: '购买会员', percent: 20.00 },
|
||||
{ value: 0.00, name: '充值退款', percent: 15.00 },
|
||||
{ value: 0.00, name: '系统减少', percent: 15.00 }
|
||||
])
|
||||
// 统计数据列表 (用于展示样式1)
|
||||
const sourceData = ref<any[]>([])
|
||||
const consumptionDataList = ref<any[]>([])
|
||||
|
||||
/**
|
||||
* 转换 Plain Object 工具
|
||||
@@ -195,17 +196,46 @@ function toPlainObject(obj : any) : any {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
setTimeout(() => {
|
||||
initTrendChart()
|
||||
initSourceChart()
|
||||
initConsumptionChart()
|
||||
}, 300)
|
||||
loadAllData()
|
||||
})
|
||||
|
||||
function initTrendChart() {
|
||||
const dates = ['01-05', '01-06', '01-07', '01-08', '01-09', '01-10', '01-11', '01-12', '01-13', '01-14', '01-15', '01-16', '01-17', '01-18', '01-19', '01-20', '01-21', '01-22', '01-23', '01-24', '01-25', '01-26', '01-27', '01-28', '01-29', '01-30', '01-31', '02-01', '02-02', '02-03']
|
||||
const accumulationData = [2500000, 2900000, 1500000, 2400000, 1800000, 1300000, 500000, 2100000, 3000000, 2800000, 2300000, 2200000, 1500000, 1100000, 2300000, 2800000, 2600000, 2700000, 1800000, 1950000, 650000, 1600000, 1750000, 2400000, 2600000, 2000000, 1400000, 550000, 2100000, 550000]
|
||||
const consumptionData = [10000, 20000, 15000, 120000, 50000, 20000, 10000, 30000, 40000, 35000, 60000, 25000, 30000, 45000, 55000, 110000, 60000, 50000, 40000, 35000, 85000, 45000, 120000, 50000, 45000, 40000, 35000, 55000, 65000, 45000]
|
||||
async function loadAllData() {
|
||||
loading.value = true
|
||||
const endTime = new Date().toISOString()
|
||||
const startTime = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString() // 默认最近30天
|
||||
|
||||
try {
|
||||
// 1. 加载汇总指标
|
||||
const stats = await fetchAdminBalanceStats()
|
||||
if (stats != null) {
|
||||
statsData.value.current_balance = (stats as any).current_balance ?? 0
|
||||
statsData.value.total_accumulation = (stats as any).total_accumulation ?? 0
|
||||
statsData.value.total_consumption = (stats as any).total_consumption ?? 0
|
||||
}
|
||||
|
||||
// 2. 加载趋势数据
|
||||
const trendData = await fetchAdminBalanceTrend(startTime, endTime)
|
||||
initTrendChart(trendData)
|
||||
|
||||
// 3. 加载分布数据 (来源与消耗)
|
||||
const distRes = await fetchAdminBalanceDistribution(startTime, endTime)
|
||||
if (distRes != null) {
|
||||
sourceData.value = (distRes as any).income ?? []
|
||||
consumptionDataList.value = (distRes as any).expense ?? []
|
||||
initSourceChart()
|
||||
initConsumptionChart()
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载统计数据失败', icon: 'none' })
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function initTrendChart(data : any[]) {
|
||||
const dates = data.map(item => item.date_group.substring(5))
|
||||
const accumulationData = data.map(item => item.accumulation)
|
||||
const consumptionData = data.map(item => item.consumption)
|
||||
|
||||
const option = {
|
||||
grid: { left: '3%', right: '4%', bottom: '5%', top: '5%', containLabel: true },
|
||||
@@ -255,7 +285,6 @@ function initSourceChart() {
|
||||
radius: '70%',
|
||||
center: ['40%', '50%'],
|
||||
label: { show: true, fontSize: 11, formatter: '{b}\n{c}%' },
|
||||
// 关键点:将图表数据映射到 percent 字段
|
||||
data: sourceData.value.map(item => ({ value: item.percent, name: item.name }))
|
||||
}
|
||||
]
|
||||
@@ -275,7 +304,6 @@ function initConsumptionChart() {
|
||||
radius: '70%',
|
||||
center: ['40%', '50%'],
|
||||
label: { show: true, fontSize: 11, formatter: '{b}\n{c}%' },
|
||||
// 关键点:将图表数据映射到 percent 字段
|
||||
data: consumptionDataList.value.map(item => ({ value: item.percent, name: item.name }))
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user