From 676c8050eeeb99fadfd9e85a457192b9d5d48097 Mon Sep 17 00:00:00 2001 From: xuhuajiao <13476289682@163.com> Date: Wed, 4 Feb 2026 15:50:41 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9C=80=E6=B1=82=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../archiveUtilize/archiveSearch/index.vue | 10 +- src/views/home.vue | 191 ++++++++++++++---- 2 files changed, 158 insertions(+), 43 deletions(-) diff --git a/src/views/archiveUtilize/archiveSearch/index.vue b/src/views/archiveUtilize/archiveSearch/index.vue index edd238f..8f2b04f 100644 --- a/src/views/archiveUtilize/archiveSearch/index.vue +++ b/src/views/archiveUtilize/archiveSearch/index.vue @@ -34,7 +34,7 @@

历史检索

- {{ item }} + {{ item }}
@@ -377,6 +377,10 @@ export default { }, dimSearch() { }, + historySearch(item) { + this.keywords = item + this.handleSearch() + }, handleSearch() { if (this.keywords) { this.isResult = true @@ -566,6 +570,10 @@ export default { background: #E6E8ED; border-radius: 3px; cursor:default; + &:hover{ + background: #0348F3; + color: #fff; + } } } } diff --git a/src/views/home.vue b/src/views/home.vue index ff483b7..8be2875 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -309,64 +309,171 @@ export default { ] // 档案类别 + // let maxCount = 0 + // data.statisNumJSON.archives.forEach(archive => { + // if (archive.count > maxCount) { + // maxCount = archive.count + // } + // }) + + // data.statisNumJSON.singles.forEach(single => { + // if (single.count > maxCount) { + // maxCount = single.count + // } + // }) + // this.addArcivesData.addArcivesMaxCount = maxCount + + // const currentDate = new Date() // 获取当前日期 + // const currentYear = currentDate.getFullYear() // 获取当前年份 + // const currentMonth = currentDate.getMonth() // 获取当前月份(从 0 到 11,所以要加 1) + + // let startYear = currentYear - 1 // 去年的年份 + // let startMonth = currentMonth + 1 // 当前月份加上 1 + + // const result = [] // 存储每个年份和月份的组合 + // const xResult = [] + // while (startYear < currentYear || startMonth <= currentMonth) { + // xResult.push(startYear + '/' + startMonth) + // result.push({ year: startYear, month: startMonth, archivesCount: 0, singlesCount: 0 }) + // // 计算下一个月份 + // startMonth += 1 + // if (startMonth > 12) { + // startYear += 1 + // startMonth = 1 + // } + // } + + // result.forEach(yearMonthObj => { + // data.statisNumJSON.archives.forEach(archive => { + // if (parseInt(archive.month) === yearMonthObj.month) { + // yearMonthObj.archivesCount = archive.count + // return + // } + // }) + + // data.statisNumJSON.singles.forEach(single => { + // if (parseInt(single.month) === yearMonthObj.month) { + // yearMonthObj.singlesCount = single.count + // return + // } + // }) + // }) + + // this.addArcivesData.addArcivesMonth = xResult + // this.addArcivesData.addArcivesNum = result.map(function(obj) { + // return obj.archivesCount + // }) + // this.addArcivesData.addArcivesNumFile = result.map(function(obj) { + // return obj.singlesCount + // }) + + // console.log(result) + // console.log(' this.addArcivesData', this.addArcivesData) + + const { statisNumJSON = { archives: [], singles: [] }} = data || {} + const { archives = [], singles = [] } = statisNumJSON + + // 1. 计算所有count中的最大值(处理空数组情况) let maxCount = 0 - data.statisNumJSON.archives.forEach(archive => { - if (archive.count > maxCount) { - maxCount = archive.count + // 处理archives的count + archives.forEach(archive => { + const count = Number(archive.count) + if (!isNaN(count) && count > maxCount) { + maxCount = count } }) - - data.statisNumJSON.singles.forEach(single => { - if (single.count > maxCount) { - maxCount = single.count + // 处理singles的count + singles.forEach(single => { + const count = Number(single.count) + if (!isNaN(count) && count > maxCount) { + maxCount = count } }) this.addArcivesData.addArcivesMaxCount = maxCount - const currentDate = new Date() // 获取当前日期 - const currentYear = currentDate.getFullYear() // 获取当前年份 - const currentMonth = currentDate.getMonth() // 获取当前月份(从 0 到 11,所以要加 1) - - let startYear = currentYear - 1 // 去年的年份 - let startMonth = currentMonth + 1 // 当前月份加上 1 - - const result = [] // 存储每个年份和月份的组合 - const xResult = [] - while (startYear < currentYear || startMonth <= currentMonth) { - xResult.push(startYear + '/' + startMonth) - result.push({ year: startYear, month: startMonth, archivesCount: 0, singlesCount: 0 }) - // 计算下一个月份 - startMonth += 1 - if (startMonth > 12) { - startYear += 1 - startMonth = 1 + // 2. 生成近12个月的时间维度(包含当月,共12个月) + const currentDate = new Date() + const currentYear = currentDate.getFullYear() // 当前年(如2026) + const currentMonth = currentDate.getMonth() + 1 // 当前月(1-12,如2) + + const result = [] // 存储{year, month, archivesCount, singlesCount} + const xResult = [] // 存储"年/月"格式的时间轴(如"2026/2") + + // 从当前月往前推11个月,加上当前月,共12个月 + let tempYear = currentYear + let tempMonth = currentMonth + + for (let i = 0; i < 12; i++) { + // 拼接时间轴文本(统一格式,比如02月显示为2,避免"2026/02"和"2026/2"不匹配) + const monthStr = tempMonth // 去掉前置0,统一为数字格式 + const timeText = `${tempYear}/${monthStr}` + xResult.push(timeText) + + // 初始化当月数据,计数默认0 + result.push({ + year: tempYear, + month: tempMonth, + archivesCount: 0, + singlesCount: 0 + }) + + // 计算上一个月(处理跨年,比如1月的上一个月是去年12月) + tempMonth -= 1 + if (tempMonth < 1) { + tempMonth = 12 + tempYear -= 1 } } - result.forEach(yearMonthObj => { - data.statisNumJSON.archives.forEach(archive => { - if (parseInt(archive.month) === yearMonthObj.month) { - yearMonthObj.archivesCount = archive.count - return - } - }) + // 反转数组,让时间轴从"最早的月"到"当前月"排列(比如2025/3 → 2026/2) + result.reverse() + xResult.reverse() - data.statisNumJSON.singles.forEach(single => { - if (parseInt(single.month) === yearMonthObj.month) { - yearMonthObj.singlesCount = single.count - return - } - }) + // 3. 构建映射表,快速匹配年月对应的count(处理后台返回的month带前置0的情况,如"02") + // archives映射表:key为"年-月",value为count + const archivesMap = {} + archives.forEach(item => { + const year = Number(item.year) + const month = Number(item.month) // 把"02"转为2,统一格式 + const count = Number(item.count) || 0 + if (!isNaN(year) && !isNaN(month)) { + archivesMap[`${year}-${month}`] = count + } }) - this.addArcivesData.addArcivesMonth = xResult - this.addArcivesData.addArcivesNum = result.map(function(obj) { - return obj.archivesCount + // singles映射表 + const singlesMap = {} + singles.forEach(item => { + const year = Number(item.year) + const month = Number(item.month) + const count = Number(item.count) || 0 + if (!isNaN(year) && !isNaN(month)) { + singlesMap[`${year}-${month}`] = count + } }) - this.addArcivesData.addArcivesNumFile = result.map(function(obj) { - return obj.singlesCount + + // 4. 填充对应月份的count(无数据则保持0) + result.forEach(item => { + const key = `${item.year}-${item.month}` + // 填充archivesCount + if (archivesMap[key] !== undefined) { + item.archivesCount = archivesMap[key] + } + // 填充singlesCount + if (singlesMap[key] !== undefined) { + item.singlesCount = singlesMap[key] + } }) + // 5. 赋值最终数据到页面变量 + this.addArcivesData.addArcivesMonth = xResult // 12个月的时间轴数组 + this.addArcivesData.addArcivesNum = result.map(obj => obj.archivesCount) // archives的12个月计数 + this.addArcivesData.addArcivesNumFile = result.map(obj => obj.singlesCount) // singles的12个月计数 + + console.log('生成的12个月数据:', result) + console.log('时间轴:', xResult) + console.log('最终赋值数据:', this.addArcivesData) + // 档案类型 for (const type in data.typeGroupBy) { if (data.typeGroupBy.hasOwnProperty(type)) {