首页路由修改、首页top5数据补齐
This commit is contained in:
@@ -62,19 +62,19 @@ export const constantRoutes = [
|
||||
component: () => import('@/views/error/401'),
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '',
|
||||
component: Layout,
|
||||
redirect: 'index',
|
||||
children: [
|
||||
{
|
||||
path: 'index',
|
||||
component: () => import('@/views/index'),
|
||||
name: 'Index',
|
||||
meta: { title: '首页', icon: 'dashboard', affix: true }
|
||||
}
|
||||
]
|
||||
},
|
||||
// {
|
||||
// path: '',
|
||||
// component: Layout,
|
||||
// redirect: 'index',
|
||||
// children: [
|
||||
// {
|
||||
// path: 'index',
|
||||
// component: () => import('@/views/index'),
|
||||
// name: 'Index',
|
||||
// meta: { title: '首页', icon: 'dashboard', affix: true }
|
||||
// }
|
||||
// ]
|
||||
// },
|
||||
{
|
||||
path: '/user',
|
||||
component: Layout,
|
||||
@@ -98,6 +98,19 @@ export const constantRoutes = [
|
||||
|
||||
// 动态路由,基于用户权限动态去加载
|
||||
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',
|
||||
component: Layout,
|
||||
|
||||
@@ -237,14 +237,88 @@ export default {
|
||||
countDeviceNumTop5().then(res => {
|
||||
let lineXData = [];
|
||||
let dataList = [];
|
||||
res && res.data.forEach(item => {
|
||||
if (res && res.data) {
|
||||
let newArr = res.data;
|
||||
if (res.data && res.data.length < 5) {
|
||||
newArr = this.sortedNum(res.data);
|
||||
}
|
||||
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() {
|
||||
listBandWidth(this.serQueryParams).then(response => {
|
||||
this.serTableList = response.rows;
|
||||
|
||||
@@ -73,8 +73,8 @@ export default {
|
||||
title: process.env.VUE_APP_TITLE,
|
||||
codeUrl: "",
|
||||
loginForm: {
|
||||
username: "admin",
|
||||
password: "admin123",
|
||||
username: "",
|
||||
password: "",
|
||||
rememberMe: false,
|
||||
code: "",
|
||||
uuid: ""
|
||||
|
||||
Reference in New Issue
Block a user