首页路由修改、首页top5数据补齐

This commit is contained in:
康冉冉
2025-10-13 17:07:37 +08:00
parent 626e02ecc5
commit 1d45c16680
3 changed files with 108 additions and 21 deletions

View File

@@ -62,19 +62,19 @@ export const constantRoutes = [
component: () => import('@/views/error/401'), component: () => import('@/views/error/401'),
hidden: true hidden: true
}, },
{ // {
path: '', // path: '',
component: Layout, // component: Layout,
redirect: 'index', // redirect: 'index',
children: [ // children: [
{ // {
path: 'index', // path: 'index',
component: () => import('@/views/index'), // component: () => import('@/views/index'),
name: 'Index', // name: 'Index',
meta: { title: '首页', icon: 'dashboard', affix: true } // meta: { title: '首页', icon: 'dashboard', affix: true }
} // }
] // ]
}, // },
{ {
path: '/user', path: '/user',
component: Layout, component: Layout,
@@ -98,6 +98,19 @@ export const constantRoutes = [
// 动态路由,基于用户权限动态去加载 // 动态路由,基于用户权限动态去加载
export const dynamicRoutes = [ export const dynamicRoutes = [
{
path: '/index',
component: Layout,
redirect: 'index',
children: [
{
path: 'index',
component: () => import('@/views/index'),
name: 'Index',
meta: { title: '首页', icon: 'dashboard', affix: true }
}
]
},
{ {
path: '/system/user-auth', path: '/system/user-auth',
component: Layout, component: Layout,

View File

@@ -237,14 +237,88 @@ export default {
countDeviceNumTop5().then(res => { countDeviceNumTop5().then(res => {
let lineXData = []; let lineXData = [];
let dataList = []; let dataList = [];
res && res.data.forEach(item => { if (res && res.data) {
lineXData.push(item.businessName); let newArr = res.data;
dataList.push(item.total); if (res.data && res.data.length < 5) {
}); newArr = this.sortedNum(res.data);
this.lineDataParams['lineXData'] = lineXData; }
this.lineDataParams['data'] = dataList; newArr.forEach(item => {
lineXData.push(item.businessName);
dataList.push(item.total);
});
this.lineDataParams['lineXData'] = lineXData;
this.lineDataParams['data'] = dataList;
}
}); });
}, },
sortedNum(data){
// 提取value并转换为数字同时保存name映射
const valueMap = new Map(); // 存储 {value: name}
const values = [];
for (const item of data) {
const value = parseInt(item.total, 10);
// 校验value有效性
if (isNaN(value) || value <= 0) {
return "错误所有value必须是大于0的数字";
}
// 校验重复value
if (valueMap.has(value)) {
return "错误输入数组不能包含重复的value";
}
valueMap.set(value, item.businessName);
values.push(value);
}
// 对输入value排序降序
const sortedInputs = [...values].sort((a, b) => b - a);
// 生成目标value序列包含所有输入值的5个递减正数
let targetValues = [];
let start = sortedInputs[0];
while (true) {
const candidate = new Set();
// 先加入所有输入值
sortedInputs.forEach(v => candidate.add(v));
// 从start开始向下补充直到有5个值
let current = start;
while (candidate.size < 5) {
if (current <= 0) break;
candidate.add(current);
current--;
}
// 转换为数组并排序(降序)
const arr = [...candidate].sort((a, b) => b - a);
if (arr.length === 5 && arr.every(v => v > 0)) {
targetValues = arr;
break;
}
start++; // 若当前start无法生成有效序列增大start重试
}
// 生成每个value对应的name
const result = [];
for (const val of targetValues) {
if (valueMap.has(val)) {
// 已有value使用原name
result.push({ businessName: valueMap.get(val), total: val.toString() });
} else {
// 补充的value寻找对应的name前缀
// 找到小于当前val的最大输入value
const closestSmaller = sortedInputs.find(v => v < val);
if (closestSmaller !== undefined) {
const prefix = valueMap.get(closestSmaller);
result.push({ businessName: `${prefix}${val}`, total: val.toString() });
} else {
// 若所有输入值都大于当前val极端情况用最大输入值的name
const maxInput = sortedInputs[0];
const prefix = valueMap.get(maxInput);
result.push({ businessName: `${prefix}${val}`, total: val.toString() });
}
}
}
return result;
},
serverTableList() { serverTableList() {
listBandWidth(this.serQueryParams).then(response => { listBandWidth(this.serQueryParams).then(response => {
this.serTableList = response.rows; this.serTableList = response.rows;

View File

@@ -73,8 +73,8 @@ export default {
title: process.env.VUE_APP_TITLE, title: process.env.VUE_APP_TITLE,
codeUrl: "", codeUrl: "",
loginForm: { loginForm: {
username: "admin", username: "",
password: "admin123", password: "",
rememberMe: false, rememberMe: false,
code: "", code: "",
uuid: "" uuid: ""