用户数量
@@ -84,21 +84,14 @@ import img2 from '../images/2.png'
import img3 from '../images/3.png'
import img4 from '../images/4.png'
import img5 from '../images/5.png'
+import { dataManager } from "@/utils/data-manager.js";
export default {
+ name: 'RightPanel',
data() {
return {
scrollBoardConfig: {
- data: [
- [`
`, '用户A', '¥520000'],
- [`
`, '用户B', '¥450000'],
- [`
`, '用户B', '¥186000'],
- [`
`, '用户D', '¥120000'],
- [`
`, '用户E', '¥56000'],
- [`
`, '用户F', '¥43000'],
- [`
`, '用户G', '¥35000'],
- [`

`, '用户H', '¥28000'],
- ],
+ data: [],
index: false,
columnWidth: [50, 100, 90],
rowHeight: 28,
@@ -106,39 +99,139 @@ export default {
rowNum: 5,
oddRowBGC: '#040c45',
evenRowBGC: '#17264f',
- waitTime: 2000,
+ waitTime: 1500, // 缩短等待时间,加快滚动
carousel: 'single',
- hoverPause: true
+ hoverPause: false, // 鼠标悬停时不暂停,确保持续滚动
+ autoPlay: true // 确保自动播放
},
- resizeTimer: null
- }
+ scrollBoardKey: 0,
+ resizeTimer: null,
+ powerChart: null,
+ currentData: null,
+ appTypes: ['智能推理', '智能训练', '图形渲染', '蛋白质分析', '其他']
+ };
+ },
+ created() {
+ this.currentData = dataManager.getData();
+ this.updateDisplay();
+
+ dataManager.eventBus.$on('cluster-changed', this.handleClusterChanged);
},
mounted() {
this.initPowerUseChart();
window.addEventListener('resize', this.handleResize);
+
+ // 确保滚动表格初始化后开始滚动
+ this.$nextTick(() => {
+ this.startScrollBoard();
+ });
+ },
+ beforeDestroy() {
+ if (this.$refs.powerUseChart) {
+ const chart = echarts.getInstanceByDom(this.$refs.powerUseChart);
+ if (chart) chart.dispose();
+ }
+ window.removeEventListener('resize', this.handleResize);
+ dataManager.eventBus.$off('cluster-changed', this.handleClusterChanged);
},
methods: {
+ handleClusterChanged(event) {
+ this.currentData = event.data;
+ this.updateDisplay();
+ },
+
+ updateDisplay() {
+ if (!this.currentData) return;
+
+ this.appTypes = this.currentData.right?.appTypes || this.appTypes;
+ this.updateScrollBoard();
+ this.updatePowerChart();
+ },
+
+ updateScrollBoard() {
+ if (!this.currentData?.right) return;
+
+ const userData = this.currentData.right.userConsumption || [];
+ const imgMap = {
+ 1: img1,
+ 2: img2,
+ 3: img3,
+ 4: img4,
+ 5: img5
+ };
+
+ // 确保数据至少有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()}`
+ ]);
+ } else {
+ tableData.push([
+ `

`,
+ `用户${i + 1}`,
+ '¥0'
+ ]);
+ }
+ }
+
+ // 创建新的配置对象,确保触发响应式更新
+ const newConfig = {
+ ...this.scrollBoardConfig,
+ data: tableData
+ };
+
+ // 更新配置
+ this.scrollBoardConfig = newConfig;
+
+ // 强制重新渲染滚动表格
+ this.scrollBoardKey += 1;
+
+ // 确保组件渲染完成后开始滚动
+ this.$nextTick(() => {
+ this.startScrollBoard();
+ });
+ },
+
+ // 启动滚动表格的方法
+ startScrollBoard() {
+ if (this.$refs.scrollBoardRef && this.$refs.scrollBoardRef.startRoll) {
+ // 如果有startRoll方法,调用它开始滚动
+ this.$refs.scrollBoardRef.startRoll();
+ }
+
+ // 如果没有startRoll方法,尝试访问内部方法
+ if (this.$refs.scrollBoardRef && this.$refs.scrollBoardRef.$children[0]) {
+ const child = this.$refs.scrollBoardRef.$children[0];
+ if (child.startAnimation) {
+ child.startAnimation();
+ }
+ }
+ },
+
initPowerUseChart() {
const chartDom = this.$refs.powerUseChart;
if (!chartDom) return;
- const myChart = echarts.init(chartDom);
+ this.powerChart = echarts.init(chartDom);
+ this.updatePowerChart();
+ },
- // 从图片中提取的数据,保持不变
+ updatePowerChart() {
+ if (!this.powerChart || !this.currentData?.right) return;
+
+ const powerData = this.currentData.right.powerUsage || [];
const dates = ['12/01', '12/02', '12/03', '12/04', '12/05', '12/06', '12/07'];
- const powerUsage = [12300, 11500, 11500, 13400, 12900, 13500, 13200];
- // 动态计算y轴范围
- const maxValue = Math.max(...powerUsage);
- const minValue = Math.min(...powerUsage);
-
- // 计算合适的y轴最大最小值(留出一些空间)
+ 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 maxIndex = powerUsage.indexOf(maxValue);
-
- const markPointData = powerUsage.map((value, index) => {
+ const maxIndex = powerData.indexOf(maxValue);
+ const markPointData = powerData.map((value, index) => {
if (index === maxIndex) {
return {
name: '最高',
@@ -147,16 +240,12 @@ export default {
yAxis: value,
symbol: 'circle',
symbolSize: 10,
- itemStyle: {
- color: '#fff',
- // borderColor: '#ff4d4f',
- // borderWidth: 2
- },
+ itemStyle: { color: '#fff' },
label: {
show: true,
position: 'top',
formatter: function(params) {
- return (params.value / 10000).toFixed(1) + '万'; // 转换为"万"单位
+ return (params.value / 10000).toFixed(1) + '万';
},
color: '#fff',
fontWeight: 'bold',
@@ -178,7 +267,7 @@ export default {
const value = params[0].value;
return params[0].name + '
' +
params[0].marker + params[0].seriesName + ': ' +
- value.toLocaleString() + '算力单位'; // 添加千分位分隔符
+ value.toLocaleString() + '算力单位';
}
},
grid: {
@@ -201,8 +290,8 @@ export default {
},
yAxis: {
type: 'value',
- min: yMin, // 使用动态计算的最小值
- max: yMax, // 使用动态计算的最大值
+ min: yMin,
+ max: yMax,
splitNumber: 6,
splitLine: {
lineStyle: {
@@ -214,7 +303,6 @@ export default {
color: 'rgba(255,255,255,0.7)',
fontSize: 12,
formatter: function(value) {
- // 将数值转换为"万"单位显示,保留1位小数
return (value / 10000).toFixed(1) + '万';
}
},
@@ -225,7 +313,7 @@ export default {
{
name: '算力使用',
type: 'line',
- data: powerUsage,
+ data: powerData,
symbol: 'none',
symbolSize: 8,
itemStyle: {
@@ -252,7 +340,7 @@ export default {
]
};
- myChart.setOption(option);
+ this.powerChart.setOption(option, true);
},
handleResize() {
@@ -264,13 +352,6 @@ export default {
}
}, 200);
}
- },
- beforeDestroy() {
- if (this.$refs.powerUseChart) {
- const chart = echarts.getInstanceByDom(this.$refs.powerUseChart);
- if (chart) chart.dispose();
- }
- window.removeEventListener('resize', this.handleResize);
}
};