算力使用情况
@@ -95,36 +107,47 @@ export default {
name: 'RightPanel',
data() {
return {
+ // X轴刻度(根据图片描述)
+ xTicks: ['7月','8月','9月','10月', '11月', '12月'],
+ // Y轴刻度(根据图片描述)
+ yTicks: ['100', '80', '60', '40', '20', '0'],
scrollBoardConfig: {
- data: [],
- index: false,
- columnWidth: [50, 100, 90],
- rowHeight: 28,
- align: ['center', 'center', 'center'],
- rowNum: 5,
- oddRowBGC: '#040c45',
- evenRowBGC: '#17264f',
- waitTime: 1500, // 缩短等待时间,加快滚动
- carousel: 'single',
- hoverPause: false, // 鼠标悬停时不暂停,确保持续滚动
- autoPlay: true // 确保自动播放
+ data: [], // 用户消费排行数据
+ index: false, // 不显示序号
+ columnWidth: [50, 100, 90], // 列宽:头像、用户名、消费金额
+ rowHeight: 28, // 行高
+ align: ['center', 'center', 'center'], // 列对齐方式
+ rowNum: 5, // 显示行数
+ oddRowBGC: '#040c45', // 奇数行背景色
+ evenRowBGC: '#17264f', // 偶数行背景色
+ waitTime: 1500, // 滚动间隔时间(毫秒)
+ carousel: 'single', // 单行滚动
+ hoverPause: false, // 鼠标悬停时不暂停
+ autoPlay: true // 自动播放
},
- scrollBoardKey: 0,
- resizeTimer: null,
- powerChart: null,
- currentData: null,
- appTypes: ['智能推理', '智能训练', '图形渲染', '蛋白质分析', '其他'],
- animationKey: 0
+ scrollBoardKey: 0, // 滚动表格的key,用于强制重新渲染
+ resizeTimer: null, // 窗口大小调整防抖定时器
+ powerChart: null, // 算力使用情况图表实例
+ userNumChart: null, // 用户数量图表实例
+ currentData: null, // 当前数据
+ appTypes: ['智能推理', '智能训练', '图形渲染', '蛋白质分析', '其他'], // 应用类型数据
+ animationKey: 0 // 动画key,用于触发重新渲染
};
},
created() {
+ // 初始化数据
this.currentData = dataManager.getData();
this.updateDisplay();
+ // 监听集群数据变化事件
dataManager.eventBus.$on('cluster-changed', this.handleClusterChanged);
},
mounted() {
+ // 初始化算力使用情况图表
this.initPowerUseChart();
+ // 初始化用户数量图表
+ this.initUserNumChart();
+ // 监听窗口大小变化
window.addEventListener('resize', this.handleResize);
// 确保滚动表格初始化后开始滚动
@@ -133,38 +156,55 @@ export default {
});
},
beforeDestroy() {
+ // 清理图表实例和事件监听
if (this.$refs.powerUseChart) {
const chart = echarts.getInstanceByDom(this.$refs.powerUseChart);
if (chart) chart.dispose();
}
+ if (this.$refs.userNumChart) {
+ const chart = echarts.getInstanceByDom(this.$refs.userNumChart);
+ if (chart) chart.dispose();
+ }
window.removeEventListener('resize', this.handleResize);
dataManager.eventBus.$off('cluster-changed', this.handleClusterChanged);
},
methods: {
+ // 处理集群数据变化
handleClusterChanged(event) {
+ // 更新当前数据
this.currentData = event.data;
- // 增加动画key,触发重新渲染和动画
+ // 增加动画key触发重新渲染
this.animationKey += 1;
- // 确保组件重新渲染后,图表能够被正确初始化和更新
+ // 确保组件重新渲染后更新图表
this.$nextTick(() => {
this.initPowerUseChart();
+ this.initUserNumChart();
this.updateDisplay();
});
},
+ // 更新显示数据
updateDisplay() {
if (!this.currentData) return;
+ // 更新应用类型数据
this.appTypes = this.currentData.right?.appTypes || this.appTypes;
+ // 更新滚动表格数据
this.updateScrollBoard();
+ // 更新算力使用情况图表
this.updatePowerChart();
+ // 更新用户数量图表
+ this.updateUserNumChart();
},
+ // 更新滚动表格数据
updateScrollBoard() {
if (!this.currentData?.right) return;
+ // 用户消费数据,格式:[{name: '用户名', amount: 消费金额}, ...]
const userData = this.currentData.right.userConsumption || [];
+ // 头像图片映射
const imgMap = {
1: img1,
2: img2,
@@ -176,21 +216,21 @@ export default {
8: img8,
9: img9,
10: img10
-
};
- // 确保数据至少有5条,不足时用空数据填充
+ // 构建表格数据,确保至少有5条数据
const tableData = [];
for (let i = 0; i < Math.max(5, userData.length); i++) {
if (userData[i]) {
tableData.push([
- `

`,
- userData[i].name,
- `¥${userData[i].amount.toLocaleString()}`
+ `
`, // 排名头像
+ userData[i].name, // 用户名
+ `¥${userData[i].amount.toLocaleString()}` // 消费金额(格式化显示)
]);
} else {
+ // 如果数据不足,用空数据填充
tableData.push([
- `
`,
+ `

`,
`用户${i + 1}`,
'¥0'
]);
@@ -205,7 +245,6 @@ export default {
// 更新配置
this.scrollBoardConfig = newConfig;
-
// 强制重新渲染滚动表格
this.scrollBoardKey += 1;
@@ -215,10 +254,10 @@ export default {
});
},
- // 启动滚动表格的方法
+ // 启动滚动表格
startScrollBoard() {
if (this.$refs.scrollBoardRef && this.$refs.scrollBoardRef.startRoll) {
- // 如果有startRoll方法,调用它开始滚动
+ // 调用startRoll方法开始滚动
this.$refs.scrollBoardRef.startRoll();
}
@@ -231,6 +270,7 @@ export default {
}
},
+ // 初始化算力使用情况图表
initPowerUseChart() {
const chartDom = this.$refs.powerUseChart;
if (!chartDom) return;
@@ -238,17 +278,35 @@ export default {
this.updatePowerChart();
},
+ // 更新算力使用情况图表
updatePowerChart() {
if (!this.powerChart || !this.currentData?.right) return;
+ // 算力使用数据,单位:p(算力单位)
const powerData = this.currentData.right.powerUsage || [];
+ // 日期数据(12月1日-12月7日)
const dates = ['12/01', '12/02', '12/03', '12/04', '12/05', '12/06', '12/07'];
+ // 计算最大值(转换为千单位)
const maxValue = Math.max(...powerData);
- const minValue = Math.min(...powerData);
- const yMax = Math.ceil(maxValue / 1000) * 1000 + 1000;
- const yMin = Math.floor(minValue / 1000) * 1000 - 1000;
+ const maxValueInK = maxValue / 1000;
+ // 根据最大值决定Y轴刻度和间隔
+ let yMax, interval;
+ if (maxValueInK >= 10) {
+ // 如果最大值大于等于10k,使用10k为间隔
+ yMax = Math.ceil(maxValueInK / 10) * 10 * 1000;
+ interval = 10 * 1000; // 10k间隔
+ } else {
+ // 如果最大值小于10k,使用1k为间隔
+ yMax = Math.ceil(maxValueInK) * 1000; // 向上取整,再转回原始单位
+ interval = 1000; // 1k间隔
+ }
+
+ // 确保Y轴最小值从0开始
+ const yMin = 0;
+
+ // 创建标记点数据(最高点)
const maxIndex = powerData.indexOf(maxValue);
const markPointData = powerData.map((value, index) => {
if (index === maxIndex) {
@@ -263,8 +321,9 @@ export default {
label: {
show: true,
position: 'top',
- formatter: function(params) {
- return (params.value / 10000).toFixed(1) + '万(p)';
+ formatter: function (params) {
+ // 显示为千单位,保留1位小数
+ return (params.value / 1000).toFixed(1) + 'k(P)';
},
color: '#fff',
fontWeight: 'bold',
@@ -282,11 +341,12 @@ export default {
backgroundColor: 'rgba(0,0,0,0.85)',
borderColor: '#1890ff',
textStyle: { color: '#fff' },
- formatter: function(params) {
+ formatter: function (params) {
const value = params[0].value;
+ // 显示日期和算力使用量(千为单位)
return params[0].name + '
' +
- params[0].marker + params[0].seriesName + ': ' +
- value.toLocaleString() + 'p';
+ params[0].marker + params[0].seriesName + ': ' +
+ (value / 1000).toFixed(1) + 'k';
}
},
grid: {
@@ -309,9 +369,9 @@ export default {
},
yAxis: {
type: 'value',
- min: yMin,
+ min: yMin, // 从0开始
max: yMax,
- splitNumber: 6,
+ interval: interval, // 根据数据大小动态设置间隔
splitLine: {
lineStyle: {
color: 'rgba(255,255,255,0.1)',
@@ -321,8 +381,9 @@ export default {
axisLabel: {
color: 'rgba(255,255,255,0.7)',
fontSize: 12,
- formatter: function(value) {
- return (value / 10000).toFixed(1) + '万';
+ formatter: function (value) {
+ // Y轴标签显示为千单位,去掉小数
+ return (value / 1000) + 'k';
}
},
axisLine: { lineStyle: { color: 'rgba(255,255,255,0.3)' } },
@@ -362,13 +423,135 @@ export default {
this.powerChart.setOption(option, true);
},
+ // 初始化用户数量图表
+ initUserNumChart() {
+ const chartDom = this.$refs.userNumChart;
+ if (!chartDom) return;
+ this.userNumChart = echarts.init(chartDom);
+ this.updateUserNumChart();
+ },
+
+ // 更新用户数量图表
+ updateUserNumChart() {
+ if (!this.userNumChart) return;
+
+ // 从数据管理器获取用户数量数据,如果没有则使用模拟数据
+ const userNumData = this.currentData?.right?.userNum || [12, 38, 55, 72, 85, 63, 47, 29];
+
+ const option = {
+ backgroundColor: 'transparent',
+ tooltip: {
+ trigger: 'axis',
+ axisPointer: {
+ type: 'shadow'
+ },
+ backgroundColor: 'rgba(0,0,0,0.85)',
+ borderColor: '#1890ff',
+ textStyle: { color: '#fff' },
+ formatter: function (params) {
+ const value = params[0].value;
+ return params[0].name + '
' +
+ params[0].marker + '用户数量: ' + value;
+ }
+ },
+ grid: {
+ left: '0%',
+ right: '0%',
+ top: '10%',
+ bottom: '15%',
+ containLabel: true
+ },
+ xAxis: {
+ type: 'category',
+ data: this.xTicks,
+ axisLabel: {
+ color: 'rgba(255,255,255,0.7)',
+ fontSize: 12,
+ interval: 0
+ },
+ axisLine: {
+ lineStyle: {
+ color: 'rgba(255,255,255,0.3)',
+ width: 2
+ }
+ },
+ axisTick: {
+ show: true,
+ alignWithLabel: true,
+ lineStyle: {
+ color: 'rgba(255,255,255,0.5)'
+ }
+ }
+ },
+ yAxis: {
+ type: 'value',
+ min: 0,
+ max: 100,
+ interval: 20,
+ splitLine: {
+ lineStyle: {
+ color: 'rgba(255,255,255,0.1)',
+ type: 'dashed'
+ }
+ },
+ axisLabel: {
+ color: 'rgba(255,255,255,0.7)',
+ fontSize: 12
+ },
+ axisLine: {
+ lineStyle: {
+ color: 'rgba(255,255,255,0.3)',
+ width: 2
+ }
+ },
+ axisTick: {
+ show: true,
+ lineStyle: {
+ color: 'rgba(255,255,255,0.5)'
+ }
+ }
+ },
+ series: [
+ {
+ name: '用户数量',
+ type: 'bar',
+ barWidth: '40%',
+ data: userNumData,
+ itemStyle: {
+ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
+ { offset: 0, color: '#1890ff' },
+ { offset: 1, color: '#005CCF' }
+ ]),
+ borderRadius: [4, 4, 0, 0]
+ },
+ emphasis: {
+ itemStyle: {
+ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
+ { offset: 0, color: '#40a9ff' },
+ { offset: 1, color: '#096dd9' }
+ ])
+ }
+ }
+ }
+ ]
+ };
+
+ this.userNumChart.setOption(option, true);
+ },
+
+ // 处理窗口大小调整
handleResize() {
clearTimeout(this.resizeTimer);
+ // 防抖处理,200ms后重新调整图表大小
this.resizeTimer = setTimeout(() => {
if (this.$refs.powerUseChart) {
const chart = echarts.getInstanceByDom(this.$refs.powerUseChart);
if (chart) chart.resize();
}
+ if (this.$refs.userNumChart) {
+ const chart = echarts.getInstanceByDom(this.$refs.userNumChart);
+ if (chart) chart.resize();
+ }
}, 200);
}
}
@@ -376,6 +559,7 @@ export default {