From 6f79cf1f9c9522d0902841490d06b7234a384f92 Mon Sep 17 00:00:00 2001 From: d266377 Date: Wed, 28 Jan 2026 17:20:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=81=E5=8A=BF=E6=84=9F=E7=9F=A5=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0-=E5=BC=80=E6=BA=90=E7=94=9F=E6=80=81=E4=B8=8E?= =?UTF-8?q?=E8=B4=A1=E7=8C=AE=E4=BB=B7=E5=80=BC=E5=85=A8=E6=99=AF-?= =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E6=B2=BB=E7=90=86=E5=81=A5=E5=BA=B7=E5=BA=A6?= =?UTF-8?q?=E5=AF=B9=E6=AF=94=E6=8E=A5=E5=8F=A3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CommunityGovernanceHealthChart.vue | 71 +++++++++++++------ 1 file changed, 49 insertions(+), 22 deletions(-) diff --git a/src/views/Jyh/ecosystem/components/CommunityGovernanceHealthChart.vue b/src/views/Jyh/ecosystem/components/CommunityGovernanceHealthChart.vue index 4fa8095..f0d89d1 100644 --- a/src/views/Jyh/ecosystem/components/CommunityGovernanceHealthChart.vue +++ b/src/views/Jyh/ecosystem/components/CommunityGovernanceHealthChart.vue @@ -2,7 +2,7 @@

社区治理健康度对比

-
+
加载中...
@@ -12,26 +12,52 @@ import { onMounted, ref, nextTick, watch, onUnmounted, computed } from 'vue'; import * as echarts from 'echarts'; import { usePageResize } from '@/utils/hooks/usePageResize'; +import { communityHealthPage2 } from '@/api/jyh/situation'; -// 不再接收外部数据,组件内部管理数据 -const communityHealthData = ref({ - indicators: ['PR 合并率', 'Issue 响应时间', 'CI/CD 使用率', '平均代码质量得分', '安全审计频率', '贡献者多样性'], - github: [82, 88, 78, 85, 75, 80], - gitcode: [68, 75, 55, 72, 60, 65] -}); +// 定义数据结构 +interface CommunityHealthItem { + indicators: string; + github: number; + gitcode: number; +} -// 未来用于API调用的方法 +// 响应式数据存储 +const communityHealthData = ref([]); +const loading = ref(true); + +// 从API获取数据 const fetchDataFromApi = async () => { try { - // 这里是预留的API调用位置,例如: - // const response = await fetch('/api/community-health-data'); - // const apiData = await response.json(); - // communityHealthData.value = apiData; + loading.value = true; + const response = await communityHealthPage2(); - // 暂时保留默认数据,实际使用时替换为API返回的数据 - console.log('Fetching community health data from API...'); + if (response.code === 200 && response.data) { + communityHealthData.value = response.data; + } else { + console.error('获取社区治理健康度数据失败:', response.msg || '未知错误'); + // 设置默认数据 + communityHealthData.value = [ + { indicators: 'PR 合并率', github: 82, gitcode: 68 }, + { indicators: 'Issue 响应时间', github: 88, gitcode: 75 }, + { indicators: 'CI/CD 使用率', github: 78, gitcode: 55 }, + { indicators: '平均代码质量得分', github: 85, gitcode: 72 }, + { indicators: '安全审计频率', github: 75, gitcode: 60 }, + { indicators: '贡献者多样性', github: 80, gitcode: 65 } + ]; + } } catch (error) { - console.error('Failed to fetch community health data:', error); + console.error('获取社区治理健康度数据异常:', error); + // 设置默认数据 + communityHealthData.value = [ + { indicators: 'PR 合并率', github: 82, gitcode: 68 }, + { indicators: 'Issue 响应时间', github: 88, gitcode: 75 }, + { indicators: 'CI/CD 使用率', github: 78, gitcode: 55 }, + { indicators: '平均代码质量得分', github: 85, gitcode: 72 }, + { indicators: '安全审计频率', github: 75, gitcode: 60 }, + { indicators: '贡献者多样性', github: 80, gitcode: 65 } + ]; + } finally { + loading.value = false; } }; @@ -45,9 +71,7 @@ const { widthType } = usePageResize(); // 空数据标识 const isEmpty = computed(() => { - return communityHealthData.value.indicators.length === 0 || - communityHealthData.value.github.length === 0 || - communityHealthData.value.gitcode.length === 0; + return communityHealthData.value.length === 0; }); // 图表实例存储(用于resize时销毁重绘) @@ -67,7 +91,10 @@ const initCommunityHealthChart = () => { const myChart = echarts.init(el); chartInstances.value.communityHealthChart = myChart; - const data = communityHealthData.value; + // 提取数据以适应图表需求 + const indicators = communityHealthData.value.map(item => item.indicators); + const githubValues = communityHealthData.value.map(item => item.github); + const gitcodeValues = communityHealthData.value.map(item => item.gitcode); myChart.setOption({ tooltip: { @@ -133,7 +160,7 @@ const initCommunityHealthChart = () => { }, xAxis: { type: 'category', - data: data.indicators, + data: indicators, axisLabel: { fontSize: 11, color: '#666', @@ -176,7 +203,7 @@ const initCommunityHealthChart = () => { { name: 'GitHub 社区', type: 'bar', - data: data.github, + data: githubValues, barWidth: '35%', itemStyle: { color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [ @@ -206,7 +233,7 @@ const initCommunityHealthChart = () => { { name: 'GitCode 社区', type: 'bar', - data: data.gitcode, + data: gitcodeValues, barWidth: '35%', itemStyle: { color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [