@@ -248,6 +251,16 @@ defineOptions({
name: 'StatsDashboard',
});
+// 生成随机十六进制颜色的工具函数
+const generateRandomColor = () => {
+ // 生成0-255的随机RGB值,转换为十六进制并补零
+ const randomHex = () =>
+ Math.floor(Math.random() * 256)
+ .toString(16)
+ .padStart(2, '0');
+ return `#${randomHex()}${randomHex()}${randomHex()}`;
+};
+
// 加载数据和切换标签逻辑
onMounted(() => {
loadDashboardData();
@@ -268,27 +281,27 @@ const loadDashboardData = async () => {
totalAuthors.value = res.data.authorCount;
categoryTotal.value = res.data.categoryCount;
totalVideos.value = res.data.videoCount;
- fileSizeTotal.value = res.data.videoSizeTotal || 0.0;
- totalDiskSize.value = res.data.totalDiskSize || 0.0;
+ fileSizeTotal.value = res.data.videoSizeTotal || '0.00';
+ totalDiskSize.value = res.data.totalDiskSize || '0.00';
favoriteCount.value = res.data.favoriteCount;
collectCount.value = res.data.collectCount;
followCount.value = res.data.followCount || 0;
graphicVideoCount.value = res.data.graphicVideoCount || 0;
- favoriteSize.value = res.data.videoFavoriteSize || 0.0;
- collectSize.value = res.data.videoCollectSize || 0.0;
- followSize.value = res.data.videoFollowSize || 0.0;
- graphicVideoSize.value = res.data.graphicVideoSize || 0.0;
+ favoriteSize.value = res.data.videoFavoriteSize || '0.00';
+ collectSize.value = res.data.videoCollectSize || '0.00';
+ followSize.value = res.data.videoFollowSize || '0.00';
+ graphicVideoSize.value = res.data.graphicVideoSize || '0.00';
categories.value = res.data.categories;
authors.value = res.data.authors;
- const cates = getRandomElements(categoriessss.value, categories.value.length);
- const colors = getRandomElements(colorArray, categories.value.length);
- categories.value.forEach((item, index) => {
- item.icon = cates[index];
- item.color = colors[index];
+ // 移除categoriessss相关逻辑,直接给分类设置固定图标cup(保证显示)
+ // 动态为每个分类生成随机颜色,替代原有的colorArray
+ categories.value.forEach((item) => {
+ item.icon = 'cup'; // 固定使用已定义的cup图标,确保显示正常
+ item.color = generateRandomColor(); // 随机生成颜色
});
} catch (err) {
console.error('加载仪表盘数据失败:', err);
@@ -300,46 +313,7 @@ const getRandomElements = (arr: any[], n: number) => {
if (n >= arr.length) return [...arr];
return [...arr].sort(() => Math.random() - 0.5).slice(0, n);
};
-
-const categoriessss = ref
([
- 'cup',
- 'spoon',
- 'fork',
- 'knife',
- 'plate',
- 'bottle',
- 'toothbrush',
- 'comb',
- 'mirror',
- 'soap',
- 'mobile',
- 'tablet',
- 'camera',
- 'headphones',
- 'speaker',
- 'tv',
- 'watch',
- 'charger',
-]);
-
-const colorArray = [
- '#3A7CA5',
- '#D9A566',
- '#6B4226',
- '#829399',
- '#A63446',
- '#4F6367',
- '#FE5F55',
- '#C7EFCF',
- '#78C0E0',
- '#49BEAA',
- '#49DCB1',
- '#FF9999',
- '#66B2FF',
- '#99FF99',
-];
-