ProfileRadar.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <InfoCard :title="title">
  3. <div class="radar-section">
  4. <div ref="radarChartRef" class="radar-chart"></div>
  5. <div class="radar-list">
  6. <div class="radar-item" v-for="(item, index) in computedRadarData" :key="index">
  7. <span class="item-label">{{ item.name }}</span>
  8. <div class="progress-row">
  9. <div class="progress-bar">
  10. <div class="progress-fill"
  11. :style="{ width: ((item.finalScore || 0) / (computedMaxScore || 1) * 100) + '%', background: `linear-gradient(90deg, ${item.color}33, ${item.color})` }">
  12. <span class="progress-end" :style="{ background: item.color }"></span>
  13. </div>
  14. </div>
  15. <span class="item-value">{{ item.finalScore || 0 }}</span>
  16. </div>
  17. </div>
  18. </div>
  19. </div>
  20. </InfoCard>
  21. </template>
  22. <script setup>
  23. import { ref, computed, watch, onMounted, onUnmounted, nextTick } from 'vue'
  24. import * as echarts from 'echarts'
  25. import InfoCard from './card.vue'
  26. const props = defineProps({
  27. title: {
  28. type: String,
  29. default: '七维得分一览'
  30. },
  31. chartData: {
  32. type: Array,
  33. default: () => []
  34. }
  35. })
  36. const getScoreColor = (score) => {
  37. if (score < 75) return '#ff4d4f'
  38. if (score >= 90) return '#52c41a'
  39. return '#ffffff'
  40. }
  41. const freshColors = [
  42. '#00e5ff', '#36d399', '#fbbf24', '#f472b6', '#a78bfa',
  43. '#34d399', '#f97316', '#2dd4bf', '#e879f9', '#38bdf8'
  44. ]
  45. const defaultRadarData = []
  46. const computedRadarData = computed(() => {
  47. const data = props.chartData.length > 0 ? props.chartData : defaultRadarData
  48. return data.map((item, index) => ({
  49. ...item,
  50. color: item.color || freshColors[index % freshColors.length],
  51. itemColor: getScoreColor(item.finalScore || 0)
  52. }))
  53. })
  54. const computedIndicators = computed(() => {
  55. const data = computedRadarData.value
  56. const allScores = data.map(item => item.finalScore || 0)
  57. const maxValue = allScores.length > 0 ? Math.max(...allScores) : 100
  58. return data.map(item => ({
  59. name: item.name + '\n\n' + (item.finalScore || 0),
  60. max: Math.max(maxValue, 1)
  61. }))
  62. })
  63. const computedMaxScore = computed(() => {
  64. const data = computedRadarData.value
  65. const allScores = data.map(item => item.finalScore || 0)
  66. return allScores.length > 0 ? Math.max(...allScores) : 100
  67. })
  68. const computedSeries = computed(() => {
  69. return computedRadarData.value.map(item => item.finalScore || 0)
  70. })
  71. const radarChartRef = ref(null)
  72. let radarChart = null
  73. const updateRadarChart = () => {
  74. if (!radarChartRef.value) return
  75. if (!radarChart) {
  76. radarChart = echarts.init(radarChartRef.value)
  77. }
  78. const radarData = computedRadarData.value
  79. const indicators = computedIndicators.value
  80. const pointColors = radarData.map(item => item.itemColor)
  81. const pointValues = radarData.map(item => item.finalScore || 0)
  82. const option = {
  83. grid: {
  84. top: 40,
  85. bottom: 40,
  86. left: 50,
  87. right: 50
  88. },
  89. radar: {
  90. indicator: indicators,
  91. center: ['50%', '52%'],
  92. radius: '50%',
  93. splitNumber: 8,
  94. axisLine: { lineStyle: { color: '#ccc' } },
  95. splitLine: { lineStyle: { color: ['#ccc', '#ccc', '#ccc', '#ccc', '#ccc', '#ccc', '#fe4322', '#8EC742', '#ccc'], width: 3 } },
  96. splitArea: { show: false },
  97. axisName: {
  98. color: '#fff',
  99. fontSize: 13
  100. }
  101. },
  102. series: [
  103. {
  104. type: 'radar',
  105. symbol: 'circle',
  106. symbolSize: 13,
  107. data: [
  108. {
  109. value: pointValues,
  110. name: '综合得分',
  111. opacity: 0,
  112. lineStyle: {
  113. color: '#4DC8FE',
  114. width: 2
  115. },
  116. itemStyle: { color: '#fff', borderWidth: 1, borderColor: '#00C8DA', borderJoin: 'round' }
  117. }
  118. ],
  119. label: {
  120. show: false,
  121. formatter: (p) => p.value,
  122. color: '#fff',
  123. fontSize: 16,
  124. fontWeight: 'bold'
  125. }
  126. }
  127. ],
  128. tooltip: {
  129. trigger: 'item',
  130. backgroundColor: 'rgba(13, 80, 122, 0.95)',
  131. borderColor: '#70CFE7',
  132. textStyle: {
  133. color: '#fff'
  134. }
  135. }
  136. }
  137. radarChart.setOption(option)
  138. }
  139. const handleResize = () => {
  140. if (radarChart) radarChart.resize()
  141. }
  142. watch(() => props.chartData, () => {
  143. updateRadarChart()
  144. }, { deep: true })
  145. onMounted(() => {
  146. nextTick(() => {
  147. setTimeout(() => {
  148. updateRadarChart()
  149. window.addEventListener('resize', handleResize)
  150. }, 100)
  151. })
  152. })
  153. onUnmounted(() => {
  154. window.removeEventListener('resize', handleResize)
  155. if (radarChart) radarChart.dispose()
  156. })
  157. </script>
  158. <style lang="scss" scoped>
  159. .radar-section {
  160. display: flex;
  161. gap: 20px;
  162. min-height: 400px;
  163. .radar-chart {
  164. flex: 1;
  165. min-width: 300px;
  166. height: 380px;
  167. }
  168. .radar-list {
  169. flex: 1;
  170. display: flex;
  171. flex-direction: column;
  172. gap: 16px;
  173. padding: 10px 0;
  174. .radar-item {
  175. display: flex;
  176. flex-direction: column;
  177. gap: 6px;
  178. font-size: 13px;
  179. .item-label {
  180. color: #a0c4ff;
  181. }
  182. .progress-row {
  183. display: flex;
  184. align-items: center;
  185. gap: 10px;
  186. .progress-bar {
  187. flex: 1;
  188. height: 5px;
  189. background: rgba(255, 255, 255, 0.1);
  190. border-radius: 0;
  191. overflow: visible;
  192. .progress-fill {
  193. height: 100%;
  194. border-radius: 0;
  195. transition: width 0.3s ease;
  196. position: relative;
  197. .progress-end {
  198. position: absolute;
  199. right: -4px;
  200. top: 50%;
  201. transform: translateY(-50%);
  202. width: 3px;
  203. height: 9px;
  204. background: #fff;
  205. border-radius: 2px;
  206. }
  207. }
  208. }
  209. .item-value {
  210. width: 45px;
  211. text-align: right;
  212. color: #fff;
  213. font-weight: bold;
  214. font-size: 13px;
  215. }
  216. }
  217. }
  218. }
  219. }
  220. </style>