| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- <template>
- <InfoCard :title="title">
- <div class="radar-section">
- <div ref="radarChartRef" class="radar-chart"></div>
- <div class="radar-list">
- <div class="radar-item" v-for="(item, index) in computedRadarData" :key="index">
- <span class="item-label">{{ item.name }}</span>
- <div class="progress-row">
- <div class="progress-bar">
- <div class="progress-fill"
- :style="{ width: ((item.finalScore || 0) / (computedMaxScore || 1) * 100) + '%', background: `linear-gradient(90deg, ${item.color}33, ${item.color})` }">
- <span class="progress-end" :style="{ background: item.color }"></span>
- </div>
- </div>
- <span class="item-value">{{ item.finalScore || 0 }}</span>
- </div>
- </div>
- </div>
- </div>
- </InfoCard>
- </template>
- <script setup>
- import { ref, computed, watch, onMounted, onUnmounted, nextTick } from 'vue'
- import * as echarts from 'echarts'
- import InfoCard from './card.vue'
- const props = defineProps({
- title: {
- type: String,
- default: '七维得分一览'
- },
- chartData: {
- type: Array,
- default: () => []
- }
- })
- const getScoreColor = (score) => {
- if (score < 75) return '#ff4d4f'
- if (score >= 90) return '#52c41a'
- return '#ffffff'
- }
- const freshColors = [
- '#00e5ff', '#36d399', '#fbbf24', '#f472b6', '#a78bfa',
- '#34d399', '#f97316', '#2dd4bf', '#e879f9', '#38bdf8'
- ]
- const defaultRadarData = []
- const computedRadarData = computed(() => {
- const data = props.chartData.length > 0 ? props.chartData : defaultRadarData
- return data.map((item, index) => ({
- ...item,
- color: item.color || freshColors[index % freshColors.length],
- itemColor: getScoreColor(item.finalScore || 0)
- }))
- })
- const computedIndicators = computed(() => {
- const data = computedRadarData.value
- const allScores = data.map(item => item.finalScore || 0)
- const maxValue = allScores.length > 0 ? Math.max(...allScores) : 100
- return data.map(item => ({
- name: item.name + '\n\n' + (item.finalScore || 0),
- max: Math.max(maxValue, 1)
- }))
- })
- const computedMaxScore = computed(() => {
- const data = computedRadarData.value
- const allScores = data.map(item => item.finalScore || 0)
- return allScores.length > 0 ? Math.max(...allScores) : 100
- })
- const computedSeries = computed(() => {
- return computedRadarData.value.map(item => item.finalScore || 0)
- })
- const radarChartRef = ref(null)
- let radarChart = null
- const updateRadarChart = () => {
- if (!radarChartRef.value) return
- if (!radarChart) {
- radarChart = echarts.init(radarChartRef.value)
- }
- const radarData = computedRadarData.value
- const indicators = computedIndicators.value
- const pointColors = radarData.map(item => item.itemColor)
- const pointValues = radarData.map(item => item.finalScore || 0)
- const option = {
- grid: {
- top: 40,
- bottom: 40,
- left: 50,
- right: 50
- },
- radar: {
- indicator: indicators,
- center: ['50%', '52%'],
- radius: '50%',
- splitNumber: 8,
- axisLine: { lineStyle: { color: '#ccc' } },
- splitLine: { lineStyle: { color: ['#ccc', '#ccc', '#ccc', '#ccc', '#ccc', '#ccc', '#fe4322', '#8EC742', '#ccc'], width: 3 } },
- splitArea: { show: false },
- axisName: {
- color: '#fff',
- fontSize: 13
- }
- },
- series: [
- {
- type: 'radar',
- symbol: 'circle',
- symbolSize: 13,
- data: [
- {
- value: pointValues,
- name: '综合得分',
- opacity: 0,
- lineStyle: {
- color: '#4DC8FE',
- width: 2
- },
- itemStyle: { color: '#fff', borderWidth: 1, borderColor: '#00C8DA', borderJoin: 'round' }
- }
- ],
- label: {
- show: false,
- formatter: (p) => p.value,
- color: '#fff',
- fontSize: 16,
- fontWeight: 'bold'
- }
- }
- ],
- tooltip: {
- trigger: 'item',
- backgroundColor: 'rgba(13, 80, 122, 0.95)',
- borderColor: '#70CFE7',
- textStyle: {
- color: '#fff'
- }
- }
- }
- radarChart.setOption(option)
- }
- const handleResize = () => {
- if (radarChart) radarChart.resize()
- }
- watch(() => props.chartData, () => {
- updateRadarChart()
- }, { deep: true })
- onMounted(() => {
- nextTick(() => {
- setTimeout(() => {
- updateRadarChart()
- window.addEventListener('resize', handleResize)
- }, 100)
- })
- })
- onUnmounted(() => {
- window.removeEventListener('resize', handleResize)
- if (radarChart) radarChart.dispose()
- })
- </script>
- <style lang="scss" scoped>
- .radar-section {
- display: flex;
- gap: 20px;
- min-height: 400px;
- .radar-chart {
- flex: 1;
- min-width: 300px;
- height: 380px;
- }
- .radar-list {
- flex: 1;
- display: flex;
- flex-direction: column;
- gap: 16px;
- padding: 10px 0;
- .radar-item {
- display: flex;
- flex-direction: column;
- gap: 6px;
- font-size: 13px;
- .item-label {
- color: #a0c4ff;
- }
- .progress-row {
- display: flex;
- align-items: center;
- gap: 10px;
- .progress-bar {
- flex: 1;
- height: 5px;
- background: rgba(255, 255, 255, 0.1);
- border-radius: 0;
- overflow: visible;
- .progress-fill {
- height: 100%;
- border-radius: 0;
- transition: width 0.3s ease;
- position: relative;
- .progress-end {
- position: absolute;
- right: -4px;
- top: 50%;
- transform: translateY(-50%);
- width: 3px;
- height: 9px;
- background: #fff;
- border-radius: 2px;
- }
- }
- }
- .item-value {
- width: 45px;
- text-align: right;
- color: #fff;
- font-weight: bold;
- font-size: 13px;
- }
- }
- }
- }
- }
- </style>
|