feat 搭建架构骨架
This commit is contained in:
115
src/views/finance/cpns/FinanceChart.vue
Normal file
115
src/views/finance/cpns/FinanceChart.vue
Normal file
@@ -0,0 +1,115 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
interface DistributionItem {
|
||||
name: string
|
||||
value: number
|
||||
color: string
|
||||
}
|
||||
|
||||
interface Props {
|
||||
distribution: DistributionItem[]
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const total = computed(() => props.distribution.reduce((sum, item) => sum + item.value, 0))
|
||||
|
||||
/** CSS conic-gradient(无图表库):按 value 占比切分色环 */
|
||||
const gradient = computed(() => {
|
||||
if (total.value <= 0) return 'conic-gradient(#e4e7ec 0% 100%)'
|
||||
let acc = 0
|
||||
const stops = props.distribution.map((item) => {
|
||||
const start = acc
|
||||
acc += (item.value / total.value) * 100
|
||||
return `${item.color} ${start}% ${acc}%`
|
||||
})
|
||||
return `conic-gradient(${stops.join(', ')})`
|
||||
})
|
||||
|
||||
function percentOf(value: number): number {
|
||||
if (total.value <= 0) return 0
|
||||
return Math.round((value / total.value) * 100)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="finance-chart card">
|
||||
<h3 class="finance-chart__title">
|
||||
业务类型分布
|
||||
</h3>
|
||||
<div class="finance-chart__body">
|
||||
<div class="finance-chart__pie" :style="{ background: gradient }" />
|
||||
<ul class="finance-chart__legend">
|
||||
<li
|
||||
v-for="item in distribution"
|
||||
:key="item.name"
|
||||
class="finance-chart__legend-item"
|
||||
>
|
||||
<span
|
||||
class="finance-chart__dot"
|
||||
:style="{ background: item.color }"
|
||||
/>
|
||||
<span class="finance-chart__name">{{ item.name }}</span>
|
||||
<span class="finance-chart__value">{{ percentOf(item.value) }}%</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.finance-chart {
|
||||
padding: @spacing-lg;
|
||||
border-radius: @radius-lg;
|
||||
background: @white;
|
||||
box-shadow: @shadow-base;
|
||||
|
||||
&__title {
|
||||
margin-bottom: @spacing-base;
|
||||
font-size: @font-size-lg;
|
||||
font-weight: 600;
|
||||
color: @heading-color;
|
||||
}
|
||||
|
||||
&__body {
|
||||
.flex(row, center, center);
|
||||
gap: @spacing-xl;
|
||||
}
|
||||
|
||||
&__pie {
|
||||
width: 180px;
|
||||
height: 180px;
|
||||
border-radius: @radius-round;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
&__legend {
|
||||
.flex(column, flex-start);
|
||||
gap: @spacing-base;
|
||||
}
|
||||
|
||||
&__legend-item {
|
||||
.flex(row, flex-start, center);
|
||||
gap: @spacing-sm;
|
||||
font-size: @font-size-base;
|
||||
color: @text-color;
|
||||
}
|
||||
|
||||
&__dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: @radius-round;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
&__name {
|
||||
min-width: 72px;
|
||||
}
|
||||
|
||||
&__value {
|
||||
color: @heading-color;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user