From 1d45c166801fc9d72542b1ec0f0d7ea5bd104b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=B7=E5=86=89=E5=86=89?= Date: Mon, 13 Oct 2025 17:07:37 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E8=B7=AF=E7=94=B1=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E3=80=81=E9=A6=96=E9=A1=B5top5=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=A1=A5=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 39 +++++++++++++------- src/views/index.vue | 86 +++++++++++++++++++++++++++++++++++++++++---- src/views/login.vue | 4 +-- 3 files changed, 108 insertions(+), 21 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 73ec479..0e79625 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -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, diff --git a/src/views/index.vue b/src/views/index.vue index 968bdab..a6c6129 100644 --- a/src/views/index.vue +++ b/src/views/index.vue @@ -237,14 +237,88 @@ export default { countDeviceNumTop5().then(res => { let lineXData = []; let dataList = []; - res && res.data.forEach(item => { - lineXData.push(item.businessName); - dataList.push(item.total); - }); - this.lineDataParams['lineXData'] = lineXData; - this.lineDataParams['data'] = dataList; + 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; diff --git a/src/views/login.vue b/src/views/login.vue index d51d907..d770364 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -73,8 +73,8 @@ export default { title: process.env.VUE_APP_TITLE, codeUrl: "", loginForm: { - username: "admin", - password: "admin123", + username: "", + password: "", rememberMe: false, code: "", uuid: ""