统计分析接口联调

This commit is contained in:
ym1026
2025-09-04 16:04:37 +08:00
parent 61ed4f355f
commit 1cc916c53c
18 changed files with 517 additions and 959 deletions

View File

@@ -57,6 +57,8 @@ import Pv from '@/components/Home/Pv.vue'
import Alarm from '@/components/Home/Alarm.vue'
import Map from '@/components/Home/Map.vue'
import { getReq, postReq } from '@/request/api'
import {getRunDays,getDateDaysAgo} from '@/utils/dealWithData'
export default {
name: 'Home',
components: { Map },
@@ -355,7 +357,7 @@ export default {
const res = await getReq('/api/queryStatSystem')
if (res.errcode === 0) {
this.deviceInfo.onLine = JSON.parse(JSON.stringify(res.data))
this.deviceInfo.onLine.runDays = this.getRunDays(res.data.launch_date)
this.deviceInfo.onLine.runDays = getRunDays(res.data.launch_date)
console.log(JSON.parse(JSON.stringify(res.data)), this.deviceInfo.onLine, '111111111111')
} else {
throw res
@@ -364,17 +366,7 @@ export default {
this.deviceInfo.onLine = {}
}
},
getRunDays(date) {
const launchDate = new Date(date)
const today = new Date() // 替换为当前日期
const timeDiff = today - launchDate // 毫秒差
const daysRun = Math.ceil(timeDiff / (1000 * 60 * 60 * 24)) // 转换为天数
console.log(`从 2023-01-01 到今天已经运行了 ${daysRun}`)
return daysRun
},
// 查询系统累计统计信息
async getStatTotalList() {
try {
@@ -417,16 +409,7 @@ export default {
this.deviceInfo.allTotal.incomeCharge + this.deviceInfo.allTotal.incomeElect
}
},
getDateDaysAgo(daysAgo) {
const date = new Date()
date.setDate(date.getDate() - daysAgo)
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
},
// 示例获取7天前的日期
// 查询场站日统计信息
@@ -439,8 +422,8 @@ export default {
const query = {
stationId: this.stationId,
category,
start_date: this.getDateDaysAgo(7 - 1),
end_date: this.getDateDaysAgo(0)
start_date: getDateDaysAgo(7 - 1),
end_date: getDateDaysAgo(0)
}
const arr = { 1: 'energy', 2: 'charge', 3: 'pv' }
const res = await getReq('/api/queryStatDayList', query)