态势感知平台-开源生态与贡献价值全景统计概览对接接口
This commit is contained in:
@@ -137,3 +137,12 @@ export function scatterDataPage1(params?: any): Promise<any> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 开源生态与贡献价值全景-统计概览
|
||||||
|
export function overviewDataPage2(params?: any): Promise<any> {
|
||||||
|
return request({
|
||||||
|
url: `/api/v1/page2/overviewData`,
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,26 +23,76 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { defineProps } from 'vue';
|
import { ref, onMounted } from 'vue';
|
||||||
|
import { overviewDataPage2 } from '@/api/jyh/situation';
|
||||||
|
|
||||||
// 定义props,便于从父组件或API获取数据
|
// 定义响应式数据
|
||||||
const props = defineProps({
|
const activeDevelopers = ref<string>('加载中...');
|
||||||
activeDevelopers: {
|
const openSourceProjects = ref<string>('加载中...');
|
||||||
type: String,
|
const openSourceCompanies = ref<string>('加载中...');
|
||||||
default: '200万+'
|
const industryValuation = ref<string>('加载中...');
|
||||||
},
|
|
||||||
openSourceProjects: {
|
// 加载状态
|
||||||
type: String,
|
const loading = ref(true);
|
||||||
default: '300万+'
|
|
||||||
},
|
// 格式化数字的工具函数
|
||||||
openSourceCompanies: {
|
const formatNumber = (num: number, unit: string = ''): string => {
|
||||||
type: String,
|
if (num >= 100000000) {
|
||||||
default: '500+'
|
return (num / 100000000).toFixed(1) + '亿';
|
||||||
},
|
} else if (num >= 10000) {
|
||||||
industryValuation: {
|
return (num / 10000).toFixed(1) + '万';
|
||||||
type: String,
|
} else if (num >= 1000) {
|
||||||
default: '2800亿'
|
return (num / 1000).toFixed(1) + '千';
|
||||||
}
|
}
|
||||||
|
return num.toString();
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化估值的工具函数
|
||||||
|
const formatValuation = (num: number): string => {
|
||||||
|
if (num >= 100000000) {
|
||||||
|
return (num / 100000000).toFixed(1) + '亿';
|
||||||
|
} else if (num >= 10000) {
|
||||||
|
return (num / 10000).toFixed(1) + '万';
|
||||||
|
}
|
||||||
|
return num.toString() + '亿';
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取统计数据
|
||||||
|
const fetchStats = async () => {
|
||||||
|
try {
|
||||||
|
loading.value = true;
|
||||||
|
const response = await overviewDataPage2();
|
||||||
|
|
||||||
|
if (response.code === 200 && response.data) {
|
||||||
|
const { developer, project, company, valuation } = response.data;
|
||||||
|
|
||||||
|
// 格式化数据显示
|
||||||
|
activeDevelopers.value = `${formatNumber(developer)}+`;
|
||||||
|
openSourceProjects.value = `${formatNumber(project)}+`;
|
||||||
|
openSourceCompanies.value = `${formatNumber(company)}+`;
|
||||||
|
industryValuation.value = `${formatValuation(valuation)}`;
|
||||||
|
} else {
|
||||||
|
console.error('获取统计数据失败:', response.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>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user