| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- <template>
- <div class="seizure-info">
- <div class="total-section">
- <div class="donut-container">
- <div class="chart-container" ref="seizureDonut"></div>
- </div>
- <div class="dept-bar-container">
- <div class="chart-container" ref="deptSeizureBar"></div>
- </div>
- </div>
- </div>
- </template>
- <script>
- import * as echarts from 'echarts'
- export default {
- name: 'SeizureInfo',
- props: {
- chartsData: {
- type: Object,
- default: () => ({
- total: 1982,
- depts: {
- labels: ['旅检一部', '旅检二部', '旅检三部'],
- data: [620, 680, 682]
- }
- })
- }
- },
- data() {
- return {
- charts: {}
- }
- },
- mounted() {
- this.$nextTick(() => {
- this.initCharts()
- })
- },
- watch: {
- chartsData: {
- deep: true,
- handler() {
- this.$nextTick(() => {
- this.disposeCharts()
- this.initCharts()
- })
- }
- }
- },
- methods: {
- disposeCharts() {
- Object.values(this.charts).forEach(chart => {
- if (chart) chart.dispose()
- })
- this.charts = {}
- },
- initCharts() {
- this.initSeizureDonut()
- this.initDeptSeizureBar()
- },
- initSeizureDonut() {
- if (!this.$refs.seizureDonut) return
- this.charts.seizureDonut = echarts.init(this.$refs.seizureDonut)
- const option = {
- responsive: true,
- maintainAspectRatio: false,
- series: [{
- type: 'pie',
- radius: ['60%', '80%'],
- data: [
- { value: this.chartsData.total, name: '查获总数' }
- ],
- itemStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 1,
- y2: 1,
- colorStops: [{
- offset: 0, color: '#A78BFA'
- }, {
- offset: 1, color: '#6366F1'
- }]
- }
- },
- label: {
- show: false
- }
- }],
- graphic: [
- {
- type: 'text',
- left: 'center',
- top: '38%',
- style: {
- text: String(this.chartsData.total),
- fill: '#333',
- fontSize: 14,
- fontWeight: 'bold',
- textAlign: 'center'
- },
- z: 100
- },
- {
- type: 'text',
- left: 'center',
- top: '58%',
- style: {
- text: '查获总数',
- fill: '#333',
- fontSize: 15,
- textAlign: 'center'
- },
- z: 100
- }
- ]
- }
- this.charts.seizureDonut.setOption(option)
- },
- initDeptSeizureBar() {
- if (!this.$refs.deptSeizureBar) return
- this.charts.deptSeizureBar = echarts.init(this.$refs.deptSeizureBar)
- const option = {
- responsive: true,
- maintainAspectRatio: false,
- tooltip: {
- trigger: 'axis',
- axisPointer: { type: 'shadow' }
- },
- legend: {
- data: ['查获数量'],
- textStyle: { color: '#666', fontSize: 10 },
- top: 0
- },
- grid: {
- left: '15%',
- right: '5%',
- bottom: '15%',
- top: '22%'
- },
- xAxis: {
- type: 'category',
- data: this.chartsData.depts.labels,
- axisLine: {
- lineStyle: {
- color: 'rgba(0, 0, 0, 0.1)'
- }
- },
- axisLabel: {
- color: '#666',
- fontSize: 9
- }
- },
- yAxis: {
- type: 'value',
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- splitLine: {
- lineStyle: {
- color: 'rgba(0, 0, 0, 0.05)'
- }
- },
- axisLabel: {
- color: '#666',
- fontSize: 9
- }
- },
- series: [{
- type: 'bar',
- data: this.chartsData.depts.data,
- itemStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [{
- offset: 0, color: '#60A5FA'
- }, {
- offset: 1, color: '#3B82F6'
- }]
- }
- },
- barWidth: '50%'
- }]
- }
- this.charts.deptSeizureBar.setOption(option)
- }
- },
- beforeDestroy() {
- Object.values(this.charts).forEach(chart => {
- if (chart) chart.dispose()
- })
- }
- }
- </script>
- <style lang="scss" scoped>
- .seizure-info {
- .total-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- }
-
- .donut-container {
- position: relative;
- width: 240rpx;
- height: 240rpx;
- margin-bottom: 24rpx;
-
- .chart-container {
- min-height: 240rpx;
- width: 100%;
- height: 100%;
- }
- }
-
- .dept-bar-container {
- width: 100%;
- height: 240rpx;
- .chart-container {
- width: 100%;
- height: 100%;
- }
- }
- }
- </style>
|