Browse Source

需求优化

master
xuhuajiao 1 month ago
parent
commit
676c8050ee
  1. 10
      src/views/archiveUtilize/archiveSearch/index.vue
  2. 187
      src/views/home.vue

10
src/views/archiveUtilize/archiveSearch/index.vue

@ -34,7 +34,7 @@
<div class="history-keyword">
<h4>历史检索</h4>
<div class="history-tag">
<span v-for="(item,index) in historyKeyword" :key="index">{{ item }}</span>
<span v-for="(item,index) in historyKeyword" :key="index" style="cursor: pointer;" @click="historySearch(item)">{{ item }}</span>
</div>
</div>
</div>
@ -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;
}
}
}
}

187
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
// archivescount
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
// singlescount
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. 1212
const currentDate = new Date()
const currentYear = currentDate.getFullYear() // 2026
const currentMonth = currentDate.getMonth() + 1 // 1-122
const result = [] // {year, month, archivesCount, singlesCount}
const xResult = [] // "/""2026/2"
// 1112
let tempYear = currentYear
let tempMonth = currentMonth
for (let i = 0; i < 12; i++) {
// 022"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
})
// 112
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()
// 3. countmonth0"02"
// archiveskey"-"valuecount
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
}
})
data.statisNumJSON.singles.forEach(single => {
if (parseInt(single.month) === yearMonthObj.month) {
yearMonthObj.singlesCount = single.count
return
// 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.addArcivesMonth = xResult
this.addArcivesData.addArcivesNum = result.map(function(obj) {
return obj.archivesCount
})
this.addArcivesData.addArcivesNumFile = result.map(function(obj) {
return obj.singlesCount
// 4. count0
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) // archives12
this.addArcivesData.addArcivesNumFile = result.map(obj => obj.singlesCount) // singles12
console.log('生成的12个月数据:', result)
console.log('时间轴:', xResult)
console.log('最终赋值数据:', this.addArcivesData)
//
for (const type in data.typeGroupBy) {
if (data.typeGroupBy.hasOwnProperty(type)) {

Loading…
Cancel
Save