首页路由修改、首页top5数据补齐
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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: ""
|
||||||
|
|||||||
Reference in New Issue
Block a user