From 9c8b3b240e31c91898674ace1ac7666ffe6c1880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Czhuzihan=E2=80=9D=E2=80=83?= <“772644120@qq.com”> Date: Thu, 26 Jun 2025 14:10:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E7=A8=8B=E7=A0=94=E7=A9=B6=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=E5=88=97+=E8=AF=A6=E6=83=85=E9=A1=B5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Dashboard.vue | 112 ++++++++++++++++++++++-- src/components/LabDetail.vue | 160 ++++------------------------------- 2 files changed, 119 insertions(+), 153 deletions(-) diff --git a/src/components/Dashboard.vue b/src/components/Dashboard.vue index 53eb670..61d7b6e 100644 --- a/src/components/Dashboard.vue +++ b/src/components/Dashboard.vue @@ -213,6 +213,15 @@ const awardsChartRef = ref(null) const fundingChartRef = ref(null) const newsListRef = ref(null) + // 工程研究中心图表数据 + const labData = ref({ + datax: [], + datay: [] + }) + const labLineData = ref({ + datax: [], + datay: [] + }) // DeepSeek 智能助手相关变量 const chatMessagesRef = ref(null) @@ -363,7 +372,6 @@ const data = await response.json(); console.log("仪表盘数据:", data); dashboardData.value = data.data; - // 更新相应的UI数据 if (data) { // 如果有新闻数据,更新新闻列表 @@ -385,7 +393,92 @@ loading.value = false; } }; - + const fetchLabData = async () => { + try { + const res = await fetch(`${getApiBaseUrl()}/admin-api/pg/research-data-dashboard/get-release`); + if (res) { + const data = await res.json(); + // 处理 keyFields 数据 + const keyFields = data.data.keyFields || []; + const datax = keyFields.map(item => item.fieldName); + const datay = keyFields.map(item => item.quantity); + labData.value = { + datax, + datay + }; + // 数据更新后,手动更新图表 + updateLabBarChart(); + } else { + console.error('获取工程研究中心数据失败:', response.statusText); + } + } catch (error) { + console.error('获取工程研究中心数据出错:', error); + } finally { + loading.value = false; + } + }; + const fetchLabData2 = async () => { + try { + const res = await fetch(`${getApiBaseUrl()}/admin-api/pg/changes-in-achievements/get-release`); + if (res) { + const data = await res.json(); + // 处理 keyFields 数据 + const afterAnalysis = data.data.afterAnalysis || []; + const datax = []; + const datay = []; + + afterAnalysis.forEach(item => { + const year = Object.keys(item)[0]; // 获取年份 + const quantity = item[year]; // 获取对应的值 + datax.push(year); + datay.push(quantity); + }); + labLineData.value = { + datax, + datay + }; + // 数据更新后,手动更新图表 + updateLabLineChart(); + } else { + console.error('获取工程研究中心数据失败:', response.statusText); + } + } catch (error) { + console.error('获取工程研究中心数据出错:', error); + } finally { + loading.value = false; + } + }; + // 添加更新工程研究中心柱状图的函数 +const updateLabBarChart = () => { + const labBarChart = echarts.getInstanceByDom(labBarChartRef.value); + if (labBarChart) { + labBarChart.setOption({ + xAxis: { + data: labData.value.datax + }, + series: [ + { + data: labData.value.datay + } + ] + }); + } +} +const updateLabLineChart = () => { + const labLineChart = echarts.getInstanceByDom(labLineChartRef.value); + if (labLineChart) { + labLineChart.setOption({ + xAxis: { + data: labLineData.value.datax + }, + series: [ + { + data: labLineData.value.datay + } + ] + }); + } +}; // 使用仪表盘数据更新图表 const updateChartsWithDashboardData = () => { if (!dashboardData.value) return; @@ -468,7 +561,7 @@ }, xAxis: { type: 'category', - data: ['国家重点工程研究中心', '工程研究中心总数'], + data: labData.value.datax, axisLine: { lineStyle: { color: '#fff' } }, axisLabel: { color: '#fff' } }, @@ -488,7 +581,7 @@ series: [ { type: 'bar', - data: [20, 150], + data: labData.value.datay, itemStyle: { color: '#4080ff' }, barWidth: '15%', label: { @@ -523,7 +616,7 @@ }, xAxis: { type: 'category', - data: ['2023', '2024', '2025'], + data: labLineData.value.datax, axisLine: { lineStyle: { color: '#fff' } }, axisLabel: { color: '#fff' } }, @@ -543,7 +636,7 @@ series: [ { type: 'line', - data: [145, 160, 175], + data: labLineData.value.datay, lineStyle: { color: '#ffd700', width: 3 }, itemStyle: { color: '#ffd700' }, symbolSize: 8 @@ -715,9 +808,12 @@ } // 生命周期钩子 - 组件挂载后初始化 - onMounted(() => { + onMounted(async() => { + // 工程研究中心数据 + await fetchLabData(); + await fetchLabData2(); // 获取仪表盘数据 - fetchDashboardData(); + await fetchDashboardData(); // 初始化图表 nextTick(() => { diff --git a/src/components/LabDetail.vue b/src/components/LabDetail.vue index 348f492..e98e225 100644 --- a/src/components/LabDetail.vue +++ b/src/components/LabDetail.vue @@ -15,43 +15,6 @@