WholeProcessPlatform/frontend/src/components/developStatusChart/index.vue

164 lines
4.5 KiB
Vue
Raw Normal View History

<!-- SidePanelItem.vue -->
<template>
<div class="basic_body">
<div ref="chartContainer" class="chart-container"></div>
2026-05-15 08:51:17 +08:00
<!-- 水电开发情况弹框 -->
<a-modal
v-model:open="modalVisible"
title="水电开发情况"
:width="1540"
@ok="handleModalOk"
@cancel="handleModalCancel"
>
<div class="modal-content">
<!-- 内容区域供用户自定义 -->
<!-- <p>选中类型{{ selectedType }}</p> -->
<SDKFQKPie :defaultTab="selectedType" />
<!-- 用户可在此处自定义内容 -->
</div>
</a-modal>
</div>
</template>
<script lang="ts" setup>
import { ref, onMounted, onUnmounted } from 'vue';
import * as echarts from 'echarts';
2026-05-15 08:51:17 +08:00
import { message } from 'ant-design-vue';
import SDKFQKPie from '@/modules/shuidianhuangjingjieruMod/TwoLayer/ShuiDianKaiFQKTwoLayer.vue'
// 定义组件名(便于调试和递归)
defineOptions({
name: 'developStatusChart'
});
const chartContainer = ref<HTMLDivElement | null>(null);
let chartInstance: echarts.ECharts | null = null;
2026-05-15 08:51:17 +08:00
// 弹框相关状态
const modalVisible = ref(false);
const selectedType = ref('');
// 页面加载时执行的逻辑
onMounted(() => {
if (chartContainer.value) {
initChart();
}
});
onUnmounted(() => {
if (chartInstance) {
chartInstance.dispose();
chartInstance = null;
}
});
const initChart = () => {
if (!chartContainer.value) return;
chartInstance = echarts.init(chartContainer.value);
const option = {
2026-04-03 16:08:05 +08:00
tooltip: {
trigger: 'item',
2026-04-10 11:11:30 +08:00
formatter: '{a} {b}: {c} ({d}%)',
2026-04-03 16:08:05 +08:00
position: 'right'
},
legend: {
2026-04-03 16:08:05 +08:00
data: ['已建', '在建'],
2026-04-03 16:08:05 +08:00
left: '60%',
orient: 'vertical',
top: 'center',
itemWidth: 20,
itemHeight: 12
},
series: [
{
2026-04-03 16:08:05 +08:00
name: '装机容量',
type: 'pie',
2026-04-03 16:08:05 +08:00
radius: ['70%', '90%'], // 外环
center: ['30%', '50%'], // 整体向下移动一点
itemStyle: {
borderRadius: 2,
borderColor: '#fff',
borderWidth: 2
},
label: {
show: false // 不显示外侧标签
},
labelLine: {
show: false // 不显示引导线
},
data: [
2026-04-02 10:54:14 +08:00
{ value: 80, name: '已建', itemStyle: { color: '#78c300' } },
{ value: 20, name: '在建', itemStyle: { color: '#2196F3' } }
]
},
{
2026-04-03 16:08:05 +08:00
name: '数量(座)',
type: 'pie',
2026-04-03 16:08:05 +08:00
radius: ['0%', '50%'], // 中心圆
center: ['30%', '50%'], // 与外环保持一致,整体向下移动
itemStyle: {
2026-04-03 16:08:05 +08:00
borderRadius: 2,
borderColor: '#fff',
borderWidth: 2
},
label: {
show: false
},
labelLine: {
show: false
},
data: [
2026-04-02 10:54:14 +08:00
{ value: 80, name: '已建', itemStyle: { color: '#78c300' } },
{ value: 20, name: '在建', itemStyle: { color: '#2196F3' } }
]
}
]
};
chartInstance.setOption(option);
// 监听窗口大小变化,重新调整图表大小
window.addEventListener('resize', () => {
chartInstance?.resize();
});
2026-05-15 08:51:17 +08:00
// 添加图表点击事件
chartInstance.on('click', (params: any) => {
if (params.data && params.data.name) {
selectedType.value = params.data.name;
modalVisible.value = true;
}
});
};
// 弹框确认按钮处理
const handleModalOk = () => {
modalVisible.value = false;
};
// 弹框取消按钮处理
const handleModalCancel = () => {
modalVisible.value = false;
};
</script>
2026-04-03 16:08:05 +08:00
<style lang="scss" scoped>
.basic_body {
width: 100%;
height: 100%;
.chart-container {
2026-04-03 16:08:05 +08:00
width: 203px; // 容器宽度
height: 100px; // 容器高度
}
2026-05-15 08:51:17 +08:00
.modal-content {
padding: 10px 0;
min-height: 100px;
}
}
</style>