Files
Situation-Awareness-Platfor…/src/views/Jyh/ecosystem/components/StatsGlass.vue

206 lines
5.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="stats-glass-bar">
<div class="stat-node">
<span class="stat-value">{{ activeDevelopers }}</span>
<span class="stat-desc">活跃开发者</span>
</div>
<div class="stat-separator"></div>
<div class="stat-node">
<span class="stat-value">{{ openSourceProjects }}</span>
<span class="stat-desc">开源项目</span>
</div>
<div class="stat-separator"></div>
<div class="stat-node">
<span class="stat-value">{{ openSourceCompanies }}</span>
<span class="stat-desc">开源企业</span>
</div>
<div class="stat-separator"></div>
<div class="stat-node">
<span class="stat-value">{{ industryValuation }}</span>
<span class="stat-desc">产业估值</span>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref, onMounted } from 'vue';
import { overviewDataPage2 } from '@/api/jyh/situation';
// 定义响应式数据
const activeDevelopers = ref<string>('加载中...');
const openSourceProjects = ref<string>('加载中...');
const openSourceCompanies = ref<string>('加载中...');
const industryValuation = ref<string>('加载中...');
// 加载状态
const loading = ref(true);
// 格式化数字的工具函数
const formatNumber = (num: number, unit: string = ''): string => {
if (num >= 100000000) {
return Math.floor(num / 100000000) + '亿';
} else if (num >= 10000) {
return Math.floor(num / 10000) + '万';
} else if (num >= 1000) {
return Math.floor(num / 1000) + '千';
}
return num.toString();
};
// 格式化估值的工具函数
const formatValuation = (num: number): string => {
if (num >= 100000000) {
return Math.floor(num / 100000000) + '亿';
} else if (num >= 10000) {
return Math.floor(num / 10000) + '万';
}
return num.toString() + '亿';
};
// 获取统计数据
const fetchStats = async () => {
try {
loading.value = true;
const response = await overviewDataPage2();
const businessData = response.data; // Axios响应格式,业务数据在response.data中
if (businessData?.code === 200 && businessData.data) {
const { developer, project, company, valuation } = businessData.data;
// 格式化数据显示
activeDevelopers.value = `${formatNumber(developer)}+`;
openSourceProjects.value = `${formatNumber(project)}+`;
openSourceCompanies.value = `${formatNumber(company)}+`;
industryValuation.value = `${formatValuation(valuation)}`;
} else {
console.error('获取统计数据失败:', businessData?.msg || '未知错误');
// 设置默认值
activeDevelopers.value = '200万+';
openSourceProjects.value = '300万+';
openSourceCompanies.value = '500+';
industryValuation.value = '2800亿';
}
} catch (error) {
console.error('获取统计数据异常:', error);
// 设置默认值
activeDevelopers.value = '200万+';
openSourceProjects.value = '300万+';
openSourceCompanies.value = '500+';
industryValuation.value = '2800亿';
} finally {
loading.value = false;
}
};
onMounted(() => {
fetchStats();
});
</script>
<style lang="scss" scoped>
.stats-glass-bar {
display: flex;
align-items: center;
justify-content: space-between;
/* 布局控制:撑满容器并增加内边距 */
width: 100%;
padding: 2rem 4rem;
//margin: 2rem 0;
/* 深色玻璃拟态背景 */
background: rgba(255, 255, 255, 0.02);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
/* 极细微的边框勾勒 */
border-radius: 1rem;
border: 1px solid rgba(255, 255, 255, 0.08);
/* 外阴影与内发光,增加悬浮感 */
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3),
inset 0 0 20px rgba(255, 255, 255, 0.02);
transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
&:hover {
border-color: rgba(56, 189, 248, 0.4);
background: rgba(255, 255, 255, 0.04);
transform: translateY(-2px);
}
}
.stat-node {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
gap: 0.75rem;
transition: transform 0.3s ease;
&:hover {
transform: scale(1.05);
.stat-value {
text-shadow: 0 0 25px rgba(56, 189, 248, 0.8);
}
}
}
.stat-value {
/* 科技感亮蓝渐变 */
font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
font-size: 2.25rem;
font-weight: 800;
background: linear-gradient(180deg, #fff 0%, #38bdf8 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
/* 基础发光效果 */
filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.3));
letter-spacing: -1px;
}
.stat-desc {
/* 在黑底上使用半透明白色,更有高级感 */
color: rgba(255, 255, 255, 0.6);
font-size: 0.875rem;
font-weight: 500;
letter-spacing: 0.1rem;
text-transform: uppercase;
}
.stat-separator {
/* 渐隐分割线 */
width: 1px;
height: 3rem;
background: linear-gradient(
to bottom,
rgba(255, 255, 255, 0),
rgba(255, 255, 255, 0.2),
rgba(255, 255, 255, 0)
);
margin: 0 1rem;
}
/* 响应式适配 */
@media (max-width: 1024px) {
.stats-glass-bar {
padding: 2rem;
}
.stat-value {
font-size: 1.75rem;
}
}
@media (max-width: 768px) {
.stats-glass-bar {
flex-direction: column;
gap: 2rem;
}
.stat-separator {
width: 50%;
height: 1px;
background: linear-gradient(to right, transparent, rgba(255,255,255,0.2), transparent);
}
}
</style>