修改统计数据

This commit is contained in:
978184212@qq.com 2026-08-24 18:10:09 +08:00
parent feac3406f9
commit 597540f977
1 changed files with 324 additions and 180 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<view class="container"> <view class="container" ref="pageContainer">
<!-- <image src="../../static/sjfx.png" mode="" class="bgimg"></image> --> <!-- <image src="../../static/sjfx.png" mode="" class="bgimg"></image> -->
<view class="pj"> <view class="pj">
<view class="pjtitle"> <view class="pjtitle">
@ -28,8 +28,8 @@
</view> </view>
<view class="sxbox wrwCov"> <view class="sxbox wrwCov">
<view class="leftsxbox"> <view class="leftsxbox">
<picker @change="bindPickerChange" :value="index" :range="array"> <picker @change="bindPickerChange" :value="index" :range="stationNameList">
<view class="uni-input">{{array[index]}} <view class="uni-input">{{stationNameList[index]}}
<image src="../../static/data_btn_sanjiao_xia.png"></image> <image src="../../static/data_btn_sanjiao_xia.png"></image>
</view> </view>
</picker> </picker>
@ -49,15 +49,23 @@
</label> </label>
</radio-group> </radio-group>
</view> </view>
<view class="qstcontent"> <view class="qstcontent" id="chartContainer" ref="chartContainer">
<!-- 有数据时显示图表 -->
<qiun-data-charts <qiun-data-charts
:key="chartKey"
v-if="hasChartData && chartData.series && chartData.series.length > 0"
type="line" type="line"
:opts="opts" :opts="opts"
:chartData="chartData" :chartData="chartData"
:enableScroll="true" :enableScroll="true"
:ontouch="true" :ontouch="true"
canvas2d canvas2d
@finished="onChartFinished"
/> />
<!-- 无数据时显示占位 -->
<view v-else class="empty-chart">
<text class="empty-text">暂无数据</text>
</view>
</view> </view>
</view> </view>
<view class="znyj"> <view class="znyj">
@ -71,8 +79,8 @@
</view> </view>
<view class="sxbox"> <view class="sxbox">
<view class="leftsxbox"> <view class="leftsxbox">
<picker @change="bindPickerChange1" :value="index1" :range="array1"> <picker @change="bindPickerChange1" :value="index1" :range="deviceNameList">
<view class="uni-input1">{{array1[index1]}} <view class="uni-input1">{{deviceNameList[index1]}}
<image src="../../static/data_btn_sanjiao_xia.png"></image> <image src="../../static/data_btn_sanjiao_xia.png"></image>
</view> </view>
</picker> </picker>
@ -127,11 +135,22 @@
scorllheight: 0, scorllheight: 0,
zt: '', zt: '',
date: new Date().getFullYear().toString(), date: new Date().getFullYear().toString(),
array: [],
index: 0, // ===== =====
index1: 0, stationNameList: [], //
array1: [], stationList: [], // [{label, value: stationCode}]
arrays: [], index: 0, //
stationCode: '', //
// ===== =====
deviceNameList: ['全部监测设备'], //
deviceList: [{ // [{label, value: deployId}]
label: '全部监测设备',
value: ''
}],
index1: 0, //
deployId: '', // ID
list: [], list: [],
tabList: ['站点名称', '告警指标', '指标值', '告警时间'], tabList: ['站点名称', '告警指标', '指标值', '告警时间'],
pjlist: [], pjlist: [],
@ -185,11 +204,6 @@
top: 0, top: 0,
total: 0, total: 0,
yearStr: null, yearStr: null,
stationName1: '',
stationCode1: null,
stationCode: '',
arrays1: [],
zxtdata: [],
timList: [{ timList: [{
value: 'yearMonth', value: 'yearMonth',
name: '年' name: '年'
@ -208,7 +222,12 @@
datetwo: currentDate, datetwo: currentDate,
riqinumber: 'yearMonth', riqinumber: 'yearMonth',
startDate: '2000-01-01', startDate: '2000-01-01',
endDate: '2030-12-31' endDate: '2030-12-31',
//
isLoadingTrend: false,
hasChartData: false,
chartKey: 0,
isChartRendered: false,
} }
}, },
onLoad() { onLoad() {
@ -224,78 +243,75 @@
this.index = 0 this.index = 0
this.index1 = 0 this.index1 = 0
this.getpj() this.getpj()
this.importWyw() this.getStationList() //
this.getazsurvMulchRecord() this.getDeviceList() //
this.getyjList() this.getyjList()
}, },
//
onShow() {
this.$nextTick(() => {
this.resetAllScroll()
})
},
methods: { methods: {
// //
cutMoneyFiter(val) { cutMoneyFiter(val) {
if (!val && val !== 0) return 0 if (!val && val !== 0) return 0
return val return val
}, },
//
importWyw() { // ===== =====
this.array = [] getStationList() {
this.arrays = [] this.stationNameList = []
this.arrays1 = [{ this.stationList = []
label: '全部监测设备',
value: ''
}]
this.$http.get('/applet/survStationInfo/list').then(res => { this.$http.get('/applet/survStationInfo/list').then(res => {
for (var i = 0; i < res.data.data.length; i++) { const data = res.data.data || []
this.arrays.push({ for (var i = 0; i < data.length; i++) {
label: res.data.data[i].stationName, this.stationList.push({
value: res.data.data[i].stationCode label: data[i].stationName,
value: data[i].stationCode //
}) })
this.arrays1.push({ this.stationNameList.push(data[i].stationName)
label: res.data.data[i].stationName,
value: res.data.data[i].stationCode
})
this.array.push(res.data.data[i].stationName)
} }
// //
if (this.array.length > 0) { if (this.stationList.length > 0) {
this.stationCode = this.arrays[0]?.value || '' this.stationCode = this.stationList[0]?.value || ''
// this.$nextTick(() => {
setTimeout(() => {
this.qushicov() this.qushicov()
}, 300) })
} }
}).catch(err => { }).catch(err => {
console.log('获取站点列表失败', err) console.log('获取站点列表失败', err)
}) })
}, },
//
getazsurvMulchRecord() { // ===== =====
this.arrays = [] getDeviceList() {
this.array1 = ['全部监测设备'] this.deviceNameList = ['全部监测设备']
this.arrays1 = [{ this.deviceList = [{
label: '全部监测设备', label: '全部监测设备',
value: '' value: ''
}] }]
this.$http.get('/applet/survDeviceDeploy/survDeviceList').then(res => { this.$http.get('/applet/survDeviceDeploy/survDeviceList').then(res => {
for (var i = 0; i < res.data.data.length; i++) { const data = res.data.data || []
this.arrays.push({ for (var i = 0; i < data.length; i++) {
label: res.data.data[i].fullDeviceName, this.deviceList.push({
value: res.data.data[i].id label: data[i].fullDeviceName,
value: data[i].id // ID
}) })
this.arrays1.push({ this.deviceNameList.push(data[i].fullDeviceName)
label: res.data.data[i].fullDeviceName,
value: res.data.data[i].id
})
this.array1.push(res.data.data[i].fullDeviceName)
} }
}).catch(err => { }).catch(err => {
console.log('获取设备列表失败', err) console.log('获取设备列表失败', err)
}) })
}, },
//
// ===== =====
getyjList() { getyjList() {
let params = {} let params = {}
params.pageNo = this.pageNo params.pageNo = this.pageNo
params.pageSize = this.pageSize params.pageSize = this.pageSize
params.deployId = this.stationCode1 params.deployId = this.deployId // 使ID
params.yearStr = this.yearStr params.yearStr = this.yearStr
uni.showLoading({ uni.showLoading({
title: '加载中' title: '加载中'
@ -318,7 +334,6 @@
if (data[i].alertContent && data[i].alertContent.indexOf('监测数据名称:') != -1) { if (data[i].alertContent && data[i].alertContent.indexOf('监测数据名称:') != -1) {
data[i].alertContent = data[i].alertContent.replace('监测数据名称:', '') data[i].alertContent = data[i].alertContent.replace('监测数据名称:', '')
} }
// alertContent
if (typeof data[i].alertContent === 'string') { if (typeof data[i].alertContent === 'string') {
data[i].alertContent = [{ data[i].alertContent = [{
name: '告警', name: '告警',
@ -355,7 +370,8 @@
console.log('获取预警列表失败', err) console.log('获取预警列表失败', err)
}) })
}, },
//
// ===== =====
lower() { lower() {
if (this.isLastpage) { if (this.isLastpage) {
return return
@ -369,7 +385,7 @@
let params = {} let params = {}
params.pageNo = this.pageNo params.pageNo = this.pageNo
params.pageSize = this.pageSize params.pageSize = this.pageSize
params.deployId = this.stationCode1 params.deployId = this.deployId // 使ID
params.yearStr = this.yearStr params.yearStr = this.yearStr
this.$http.get('/applet/wxclient/alertRecord', { this.$http.get('/applet/wxclient/alertRecord', {
params: params params: params
@ -414,7 +430,8 @@
console.log('加载更多预警失败', err) console.log('加载更多预警失败', err)
}) })
}, },
//
// ===== =====
getpj() { getpj() {
this.$http.post('/applet/wxclient/displayInfo?infoType=' + 'effect_assess').then(res => { this.$http.post('/applet/wxclient/displayInfo?infoType=' + 'effect_assess').then(res => {
let data = res.data.data.effect_assess.detailList let data = res.data.data.effect_assess.detailList
@ -428,16 +445,15 @@
console.log('获取评价失败', err) console.log('获取评价失败', err)
}) })
}, },
//
// ===== =====
radioChange(e) { radioChange(e) {
this.riqinumber = e.detail.value this.riqinumber = e.detail.value
//
this.timList.forEach((item, index) => { this.timList.forEach((item, index) => {
if (item.value === e.detail.value) { if (item.value === e.detail.value) {
this.current = index this.current = index
} }
}) })
//
let currentDate = new Date() let currentDate = new Date()
let year = currentDate.getFullYear() let year = currentDate.getFullYear()
let month = String(currentDate.getMonth() + 1).padStart(2, '0') let month = String(currentDate.getMonth() + 1).padStart(2, '0')
@ -452,7 +468,8 @@
} }
this.qushicov() this.qushicov()
}, },
//
// ===== =====
bindDateqsChange(e) { bindDateqsChange(e) {
let selectedDate = e.detail.value let selectedDate = e.detail.value
if (this.riqinumber === 'yearMonth') { if (this.riqinumber === 'yearMonth') {
@ -464,68 +481,177 @@
} }
this.qushicov() this.qushicov()
}, },
//
qushicov() { // ===== =====
// 使 onChartFinished() {
if (!this.stationCode) { this.isChartRendered = true
console.log('站点编码为空,使用默认站点') this.$nextTick(() => {
if (this.arrays.length > 0) { this.resetAllScroll()
this.stationCode = this.arrays[0].value })
} else { },
//
// ===== =====
resetAllScroll() {
// 1.
uni.pageScrollTo({
scrollTop: 0,
duration: 0
})
// 2. H5 DOM
// #ifdef H5
setTimeout(() => { setTimeout(() => {
if (this.arrays.length > 0) { //
this.stationCode = this.arrays[0].value window.scrollTo(0, 0)
//
const scrollableElements = document.querySelectorAll('.scroll-view, .qstcontent, .container, .qiun-data-charts')
scrollableElements.forEach(el => {
if (el.scrollTop !== undefined && el.scrollTop !== 0) {
el.scrollTop = 0
}
if (el.scrollLeft !== undefined && el.scrollLeft !== 0) {
el.scrollLeft = 0
}
})
// canvas
const chartContainer = document.querySelector('.qstcontent .qiun-data-charts')
if (chartContainer) {
chartContainer.scrollLeft = 0
chartContainer.scrollTop = 0
// canvas
const canvasWrapper = chartContainer.querySelector('.qiun-charts')
if (canvasWrapper) {
canvasWrapper.scrollLeft = 0
canvasWrapper.scrollTop = 0
}
// canvas
const canvas = chartContainer.querySelector('canvas')
if (canvas && canvas.parentElement) {
canvas.parentElement.scrollLeft = 0
canvas.parentElement.scrollTop = 0
}
}
}, 150)
// #endif
// 3. 使 API
// #ifdef MP-WEIXIN
setTimeout(() => {
const query = uni.createSelectorQuery().in(this)
query.select('#chartContainer').boundingClientRect()
query.exec((res) => {
if (res && res[0]) {
//
uni.pageScrollTo({
scrollTop: 0,
duration: 0
})
}
})
}, 150)
// #endif
},
// ===== =====
qushicov() {
if (this.isLoadingTrend) return
//
if (!this.stationCode) {
if (this.stationList.length > 0) {
this.stationCode = this.stationList[0].value
} else {
console.log('等待站点数据加载...')
setTimeout(() => {
if (this.stationList.length > 0) {
this.stationCode = this.stationList[0].value
this.qushicov() this.qushicov()
} }
}, 500) }, 1000)
return return
} }
} }
let data = { if (!this.dateqs) {
summrayMode: this.riqinumber, this.dateqs = new Date().getFullYear().toString()
startTime: this.dateqs,
stationCode: this.stationCode,
} }
this.isLoadingTrend = true
let data = {
summrayMode: this.riqinumber || 'yearMonth',
startTime: this.dateqs,
stationCode: this.stationCode, //
}
console.log('请求趋势数据参数:', data) console.log('请求趋势数据参数:', data)
this.$http.post('/applet/survDeviceDeploy/waterIntegrateStatistic', data).then(iem => { //
this.chartData = {
categories: [],
series: []
}
this.hasChartData = false
this.$http.post('/applet/survDeviceDeploy/waterIntegrateStatistic', data)
.then(iem => {
let lynum = iem.data.data let lynum = iem.data.data
console.log('趋势数据返回:', lynum) console.log('趋势数据返回:', lynum)
//
if (!lynum || !lynum.tableHead || !lynum.tableData2 || lynum.tableHead.length === 0) { if (!lynum || !lynum.tableHead || !lynum.tableData2 || lynum.tableHead.length === 0) {
console.log('趋势数据为空') console.log('趋势数据为空')
this.chartData = { this.chartData = {
categories: [], categories: [],
series: [] series: []
} }
this.hasChartData = false
this.chartKey = Date.now()
return return
} }
setTimeout(() => { this.processChartData(lynum)
this.hasChartData = true
// key
this.chartKey = Date.now()
//
this.$nextTick(() => {
this.resetAllScroll()
})
})
.catch(err => {
console.log('趋势数据请求失败', err)
this.chartData = {
categories: [],
series: []
}
this.hasChartData = false
this.chartKey = Date.now()
})
.finally(() => {
this.isLoadingTrend = false
})
},
// ===== =====
processChartData(lynum) {
let categories = [] let categories = []
let displayCategories = [] let displayCategories = []
let series = [] let series = []
let allValues = [] let allValues = []
// X
categories = lynum.tableIndex || [] categories = lynum.tableIndex || []
if (categories.length > 0) { if (categories.length > 0) {
const first = categories[0] const middle = Math.floor(categories.length / 2)
const middle = categories[Math.floor(categories.length / 2)]
const last = categories[categories.length - 1]
displayCategories = categories.map((item, index) => { displayCategories = categories.map((item, index) => {
if (index === 0 || index === Math.floor(categories.length / 2) || index === categories.length - 1) { if (index === 0 || index === middle || index === categories.length - 1) {
return item return item
} }
return '' return ''
}) })
} }
// series
lynum.tableHead.forEach((header, index) => { lynum.tableHead.forEach((header, index) => {
const seriesData = (lynum.tableData2 || []).map(row => { const seriesData = (lynum.tableData2 || []).map(row => {
const value = row[index] === "0" ? 0 : parseFloat(row[index]) || 0 const value = row[index] === "0" ? 0 : parseFloat(row[index]) || 0
@ -539,11 +665,10 @@
}) })
}) })
// Y
if (allValues.length > 0) { if (allValues.length > 0) {
const maxValue = Math.max(...allValues) const maxValue = Math.max(...allValues)
const minValue = Math.min(...allValues) const minValue = Math.min(...allValues)
const padding = maxValue * 0.1 || 10 const padding = (maxValue - minValue) * 0.1 || 10
const yAxisMax = maxValue + padding const yAxisMax = maxValue + padding
const yAxisMin = Math.max(0, minValue - padding) const yAxisMin = Math.max(0, minValue - padding)
@ -566,51 +691,36 @@
categories: displayCategories, categories: displayCategories,
series: series series: series
} }
console.log('图表数据:', this.chartData) console.log('图表数据更新:', this.chartData)
}, 300)
}).catch(err => {
console.log('趋势数据请求失败', err)
this.chartData = {
categories: [],
series: []
}
})
}, },
// 线
// ===== 线 =====
bindPickerChange: function(e) { bindPickerChange: function(e) {
this.index = e.detail.value this.index = e.detail.value
let stationName = this.array[this.index] if (this.stationList[this.index]) {
for (var i = 0; i < this.arrays.length; i++) { this.stationCode = this.stationList[this.index].value
if (stationName == this.arrays[i].label) {
this.stationCode = this.arrays[i].value
break
}
}
this.qushicov() this.qushicov()
}
}, },
//
// ===== =====
bindPickerChange1: function(e) { bindPickerChange1: function(e) {
this.index1 = e.detail.value this.index1 = e.detail.value
this.stationName1 = this.array1[this.index1] if (this.deviceList[this.index1]) {
for (var i = 0; i < this.arrays1.length; i++) { this.deployId = this.deviceList[this.index1].value // ID
if (this.stationName1 == this.arrays1[i].label) {
this.stationCode1 = this.arrays1[i].value
break
}
}
if (this.stationName1 == '全部监测设备') {
this.stationCode1 = null
} }
this.pageNo = 1 this.pageNo = 1
this.getyjList() this.getyjList()
}, },
//
// ===== =====
bindDateChange: function(e) { bindDateChange: function(e) {
this.yearStr = e.detail.value this.yearStr = e.detail.value
this.date = e.detail.value this.date = e.detail.value
this.pageNo = 1 this.pageNo = 1
this.getyjList() this.getyjList()
}, },
getDate(type) { getDate(type) {
const date = new Date(); const date = new Date();
let year = date.getFullYear(); let year = date.getFullYear();
@ -735,6 +845,8 @@
height: 400rpx; height: 400rpx;
width: 98%; width: 98%;
padding-left: 20rpx; padding-left: 20rpx;
position: relative;
overflow: hidden;
} }
.uni-ec-canvas { .uni-ec-canvas {
@ -1065,4 +1177,36 @@
width: 44rpx; width: 44rpx;
height: 44rpx; height: 44rpx;
} }
//
.empty-chart {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background: #f8f9fc;
border-radius: 16rpx;
.empty-text {
font-size: 28rpx;
color: #999;
font-family: Source Han Sans SC;
}
}
//
.qstcontent {
.qiun-data-charts {
overflow: hidden !important;
.qiun-charts {
overflow: hidden !important;
}
canvas {
overflow: hidden !important;
}
}
}
</style> </style>