2 16.统计面板组件开发
src/pages/index.vue
<template>
<div>
<el-row :gutter="20">
<!-- 骨架屏优化体验 -->
<template v-if="panels.length == 0">
<el-col :span="6" :offset="0" v-for="i in 4" :key="i">
<el-skeleton style="width: 100%;" animated loading>
<template #template>
<el-card shadow="hover" class="border-0">
<template #header>
<div class="flex justify-between">
<el-skeleton-item variant="text" style="width: 50%" />
<el-skeleton-item variant="text" style="width: 10%" />
</div>
</template>
<el-skeleton-item variant="text" style="width: 80%" />
<el-divider></el-divider>
<div class="flex justify-between text-sm text-gray-500">
<el-skeleton-item variant="text" style="width: 50%" />
<el-skeleton-item variant="text" style="width: 10%" />
</div>
</el-card>
<el-skeleton-item variant="text" style="width: 30%" />
</template>
</el-skeleton>
</el-col>
</template>
<!-- -->
<el-col :span="6" :offset="0" v-for="(item, index) in panels" :key="index">
<el-card shadow="hover" class="border-0">
<template #header>
<div class="flex justify-between">
<span>{{ item.title }}</span>
<el-tag :type="item.unitColor" effect="plain">
{{ item.unit }}
</el-tag>
</div>
</template>
<span class="text-3xl font-bold text-gray-500">
{{ item.value }}
</span>
<el-divider></el-divider>
<div class="flex justify-between text-sm text-gray-500">
<span>{{ item.subTitle }}</span>
<span>{{ item.subValue }}</span>
</div>
</el-card>
</el-col>
</el-row>
</div>
</template>
<script setup>
import { getStatistics1 } from '../api';
import { ref } from 'vue';
const panels = ref([])
getStatistics1().then(res => {
console.log(res.panels)
panels.value = res.panels
})
</script>
{
"msg": "ok",
"data": {
"panels": [
{
"title": "支付订单",
"value": 49,
"unit": "年",
"unitColor": "success",
"subTitle": "总支付订单",
"subValue": 49,
"subUnit": ""
},
{
"title": "订单量",
"value": 555,
"unit": "周",
"unitColor": "danger",
"subTitle": "转化率",
"subValue": "60%",
"subUnit": ""
},
{
"title": "销售额",
"value": "¥3.54",
"unit": "年",
"unitColor": "primary",
"subTitle": "总销售额",
"subValue": 3.54,
"subUnit": ""
},
{
"title": "新增用户",
"value": 16,
"unit": "年",
"unitColor": "warning",
"subTitle": "总用户",
"subValue": 16,
"subUnit": "人"
}
]
}
}
Last updated