bonus-ui/src/views/screen/wsScreenWidescreen/components/left/EquipItem.vue

172 lines
3.8 KiB
Vue
Raw Normal View History

2025-10-29 16:31:30 +08:00
<template>
<div>
<div class="title" @click="openDialog">{{ title }}</div>
<div class="content">
<div>
<div class="left-item">
2025-11-25 15:22:35 +08:00
<div class="left-tip">装备数 <span class="unit"></span></div>
2025-10-29 16:31:30 +08:00
<div class="number">{{ query.num || 0 }}</div>
</div>
<div class="left-item">
2025-11-25 15:22:35 +08:00
<div class="left-tip">装备价值 <span class="unit">亿元</span></div>
2025-10-29 16:31:30 +08:00
<div class="number">{{ query.price ? (query.price / 100000000).toFixed(4) : 0 }}</div>
</div>
</div>
<div>
<div class="right-tip">装备年限</div>
<!-- 饼状图 -->
<div ref="pieChart" class="pie-chart"></div>
</div>
</div>
</div>
</template>
<script>
import * as echarts from 'echarts'
export default {
props: {
title: {
type: String,
default: '',
},
state: {
type: Object,
default: () => {
return {
num: 0,
price: 0,
}
},
},
pieValues: {
type: Array,
default: () => [], // 只有 value
},
},
data() {
return {
query: {},
}
},
mounted() {
console.log('🚀 ~ mounted ~ this.state:', this.state)
console.log('state-->', this.pieValues)
setTimeout(() => {
this.query = this.state
this.initPieChart()
}, 300)
},
computed: {
pieData() {
// 固定 namevalue 从父组件传入
const names = ['5年以内', '5-10年', '10年以上']
return names.map((name, index) => ({
name,
value: this.pieValues[index] || '',
}))
},
},
methods: {
initPieChart() {
const chartDom = this.$refs.pieChart
// console.log('🚀 ~ initPieChart ~ chartDom:', chartDom)
if (!chartDom) return
const myChart = echarts.init(chartDom)
const option = {
tooltip: {
trigger: 'item',
},
series: [
{
name: '装备年限',
type: 'pie',
radius: '39%',
avoidLabelOverlap: false,
label: {
show: true,
formatter: '{b}\n{d}%',
color: '#A3D6F8',
},
labelLine: {
show: true,
length: 8, // 第一段线
length2: 5, // 第二段线
},
data: this.pieData,
},
],
}
myChart.setOption(option)
window.addEventListener('resize', () => myChart.resize())
},
openDialog() {
this.$emit('openDialog')
},
},
}
</script>
<style lang="scss" scoped>
.title {
2025-11-25 15:22:35 +08:00
padding-left: 12px;
font-size: 16px;
font-weight: 600;
background-image: url('../../img/wsScreenTitleSmall.png');
// background-size: 100% 100%;
2025-10-29 16:31:30 +08:00
color: #f0f5f8;
cursor: pointer;
}
.number {
font-size: 20px;
2025-11-25 15:22:35 +08:00
background: linear-gradient(180deg, #FFF 19.35%, #5DCBFE 77.42%);
2025-10-29 16:31:30 +08:00
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.content {
display: flex;
.left-item {
margin-top: 16px;
height: 100px;
text-align: center;
background-image: url('../../img/equip-item.png');
background-size: 100% 100%;
.left-tip {
padding-top: 6px;
padding-bottom: 15px;
font-size: 14px;
2025-11-25 15:22:35 +08:00
font-weight: 500;
}
.unit {
font-size: 14px;
font-weight: 300;
background: linear-gradient(180deg, #FFF 25.81%, #FFF 77.42%);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
2025-10-29 16:31:30 +08:00
}
}
.right-tip {
margin-left: 30px;
margin-top: 16px;
padding: 4px 0;
font-size: 14px;
2025-11-25 15:22:35 +08:00
font-weight: 500;
2025-10-29 16:31:30 +08:00
width: 160px;
text-align: center;
background-image: url('../../img/equip-title.png');
background-size: 100% 100%;
}
.pie-chart {
width: 200px;
height: 200px;
}
}
</style>