FenXiNspUniapp/packDetail/pages/sjdyj/index.vue

773 lines
17 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="container">
<!-- 顶部选项卡 -->
<view class="topScroll">
<scroll-view scroll-x="true" class="scroll">
<view class="scroll-item" v-for="(item,index) in topItems" :key="index"
@click="chooseClick(item,index)" :class="{'scroll-item2':isActive == index}">
{{item.dictLabel}}
<view class="zliebs" v-show="isActive === index">
</view>
</view>
</scroll-view>
</view>
<!-- 异常趋势图 -->
<block v-if="isActive == 1">
<view class="liebiaos" v-if="resolt.length>0">
<view class="searchbox">
<view class="uni-px-8 uni-pb-8">
<text>设备选择:</text>
<uni-data-select v-model="value" :localdata="rangeList" @change="change"></uni-data-select>
</view>
<view class="example-body">
<text>时间区间:</text>
<uni-datetime-picker v-model="rangetime" type="daterange" @maskClick="maskClick" />
</view>
</view>
<!-- 趋势图 -->
<view class="qushicov" v-for="(item,index) in resolt" :key="index">
<text class="quname">{{item.itemName}}{{item.unit}}</text>
<view class="charts-box">
<qiun-data-charts type="area" :opts="opts" :chartData="item.chartData" :enableScroll="true" :ontouch="true" canvas2d />
</view>
</view>
</view>
<view class="zwsj" v-else>
<view class="inzwsj">
<image src="../../static/zwsj.png" mode="" class="zwsjimg"></image>
<view class="zwsjtext">
暂无数据
</view>
</view>
</view>
</block>
<!-- 监测站告警 -->
<block v-else-if="isActive == 0">
<view class="liebiaos" v-if="List.length != 0">
<view class="itembox" v-for="(item,index) in List" :key="index">
<view class="itembox_top" v-if="item.stationName">
<view class="itembox_lef">
<image src="../../static/fz.png" mode=""></image>
<view class="title">
{{item.stationName}}
</view>
</view>
<view class="itembox_right">
{{item.alertTime}}
</view>
</view>
<view class="itembox_bot">
<block v-if="item.alertContent.length != 0">
<view class="scrolltop">
<view class="tabitem" v-for="(it,i) in tabList" :key="i">
{{it}}
</view>
</view>
<view class="lists_item" v-for="(Item,Index) in item.alertContent" :key="Index">
<view class="jczbs" v-if="Item.name">
{{Item.name}}
</view>
<view class="zbz" v-if="Item.val">
{{Item.val}}
</view>
<view class="sbsj" v-if="Item.valHeight" style="color: #FF4242;">
{{Item.valHeight}}
<image class="zximg" src="../../../static/home_shuju_shang.png" mode="">
</image>
</view>
<view class="sbsj" v-if="Item.valLow" style="color: #19D58A;">
{{Item.valLow}}
<image class="zximg" src="../../../static/home_shuju_xia.png" mode="">
</image>
</view>
<view class="szqss" v-if="Item.unit">
{{Item.unit}}
</view>
</view>
</block>
</view>
</view>
<view class="load">
<uni-load-more :status="loadStatus"></uni-load-more>
</view>
</view>
<view class="zwsj" v-else>
<view class="inzwsj">
<image src="../../static/zwsj.png" mode="" class="zwsjimg"></image>
<view class="zwsjtext">
暂无数据
</view>
</view>
</view>
</block>
</view>
</template>
<script>
import api from "@/api/api"
import configService from '@/common/service/config.service.js';
export default {
data() {
const currentDate = this.getDate({
format: true
})
return {
List: [],
baseUrl: configService.apiUrl,
tabList: ['监测指标名称', '监测指标值', '高/低阈值', '计量单位'],
array: [],
index: '',
sampTime: '',
deviceNo: '',
allNum: '',
isLastpage: '',
intervalId: null,
loadStatus: 'more', //加载样式more-加载前样式loading-加载中样式nomore-没有数据样式
isLoadMore: false, //是否加载中
show: false,
show1: false,
top: 0,
pageNo: 1,
pageSize: 4,
deleteUrl: '/applet/survMulchRecord/delete',
stationName: '',
stationCode: '',
sampTime: '',
arrays: [],
isRefresher: false, //下拉刷新状态
reload: '',
topItems: [{
dictLabel: '监测站告警'
},
{
dictLabel: '异常趋势图'
}
],
value: 0,
rangeList: [],
isActive: 0,
rangetime: [currentDate, currentDate],
deployId: '',
resolt: [],
chartData: {},
opts: {
color: ["#1890FF", "#FF4242", "#19D58A", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272",
"#FC8452", "#9A60B4", "#ea7ccc"
],
padding: [15, 15, 10, 15],
legend: {
show: false, // 显示图例,方便区分各条线
position: "top",
float: "center",
itemGap: 20
},
enableScroll: true,
xAxis: {
disableGrid: true,
itemCount: 14,
scrollShow: true,
scrollAlign: 'left',
labelCount: 14,
boundaryGap: 'justify'
},
yAxis: {
gridType: "dash",
dashLength: 2,
// 添加数据格式化,显示数值
format: (val) => {
return val.toFixed(2);
}
},
extra: {
area: {
type: "curve",
opacity: 0.2,
addLine: true,
width: 2,
gradient: true,
activeType: "hollow"
},
tooltip: {
textStyle: {
fontSize: 12
},
// 自定义提示框内容
format: (item, category, index, opts) => {
return `${category}\n${item.seriesName}: ${item.data}`
}
},
markLine: {
// 可以添加标记线来更明显地显示阈值
data: []
}
}
},
}
},
onLoad() {
this.getList()
this.startTime = this.rangetime[0]
this.endTime = this.rangetime[1]
},
onShow() {
// 页面显示时重新获取数据
this.getList()
},
onReachBottom() {
// 页面触底加载更多
this.lower();
},
onPullDownRefresh() {
// 页面下拉刷新
this.refresherrefreshFun();
},
watch: {
rangetime(newval) {
this.startTime = this.rangetime[0]
this.endTime = this.rangetime[1]
this.qushiList()
},
},
methods: {
getDate(type) {
const date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
if (type === 'start') {
year = year - 10;
} else if (type === 'end') {
year = year + 10;
}
month = month > 9 ? month : '0' + month;
day = day > 9 ? day : '0' + day;
return `${year}-${month}-${day}`;
},
// 下拉刷新被触发
refresherrefreshFun() {
this.pageNo = 1
this.deviceNo = ''
this.getList().then(() => {
uni.stopPullDownRefresh();
});
},
// 切换类型
chooseClick(item, index) {
this.isActive = index;
this.pageNo = 1
this.deviceNo = ''
this.getList()
if (index == 1) {
this.sbeiList()
}
},
getList() {
return new Promise((resolve, reject) => {
var params = {}
params.pageNo = this.pageNo
params.pageSize = this.pageSize
uni.showLoading({
title: '加载中'
});
this.List = []
if (this.isActive == 0) {
var url = '/applet/wxclient/alertRecord'
} else if (this.isActive == 1) {
var url = '/applet/survPestlightAlert/list'
if (this.deviceNo) {
params.deviceNo = this.deviceNo
}
}
this.$http.get(url, {
params: params
}).then(res => {
if (res.data.code == 0) {
var data = res.data.data.records
this.List = this.List.concat(data)
if (res.data.data.total != 0) {
this.allNum = Number(res.data.data.total) / Number(this.pageSize) + '';
if (this.allNum.indexOf('.') == -1) {
this.allNum = this.allNum;
} else {
this.allNum = parseInt(Number(this.allNum) + 1);
}
if (this.pageNo == this.allNum) {
this.isLastpage = true;
this.loadStatus = 'nomore'
} else {
this.isLastpage = false;
this.loadStatus = 'more'
}
} else {
this.isLastpage = true;
this.loadStatus = 'nomore'
}
}
uni.hideLoading();
this.isRefresher = false
resolve()
}).catch(err => {
uni.hideLoading();
reject(err)
})
})
},
lower() {
// 最后一页了,取消下拉功能
if (this.isLastpage) {
return
}
clearInterval(this.intervalId);
var num = 1;
this.intervalId = setInterval(() => {
num = num + 1;
}, 1000)
this.pageNo = this.pageNo + 1;
var params = {}
params.pageNo = this.pageNo
params.pageSize = this.pageSize
if (this.isActive == 0) {
var url = '/applet/survPestlightAlert/list'
if (this.deviceNo) {
params.deviceNo = this.deviceNo
}
} else if (this.isActive == 1) {
var url = '/applet/wxclient/alertRecord'
}
this.$http.get(url, {
params: params
}).then(res => {
if (res.data.code == 0) {
var data = res.data.data.records
this.List = this.List.concat(data)
if (res.data.data.total != 0) {
if (this.pageNo == this.allNum) {
this.isLastpage = true;
this.loadStatus = 'nomore'
} else {
this.isLastpage = false;
this.loadStatus = 'more'
}
} else {
this.isLastpage = true;
this.loadStatus = 'nomore'
}
}
})
},
changenr() {
this.pageNo = 1
this.getList()
},
// 趋势图接口
async qushiList() {
try {
const data = {
deployId: this.deployId,
startTime: this.startTime,
endTime: this.endTime,
}
const res = await this.$http.post('/applet/survAlertRecord/alertSummary', data)
if (res.data.code === 0) {
let ovelit = res.data.data
this.resolt = ovelit.itemList.map(item => {
return {
...item,
data: ovelit.dataMap[item.entity] || []
}
})
this.timeList = ovelit.timeList || []
this.getServerData(this.resolt);
}
} catch (error) {
console.error("获取趋势图数据失败", error)
}
},
// 设备列表
async sbeiList() {
try {
uni.showLoading({
title: '加载中'
});
const res = await this.$http.get('/applet/survDeviceDeploy/deviceList?stationCode=')
if (res.data.code === 0) {
this.rangeList = res.data.data.map((lit, index) => {
return {
"value": index,
"text": lit.deployDes,
"id": lit.id,
}
})
if (this.rangeList.length > 0) {
this.deployId = this.rangeList[this.value].id
await this.qushiList();
}
}
uni.hideLoading();
} catch (error) {
console.error("获取设备列表失败", error)
uni.hideLoading();
}
},
// 选择deployid
change(e) {
this.deployId = this.rangeList[this.value].id
this.sbeiList()
},
// 选择日期范围
maskClick(e) {
this.startTime = e[0]
this.endTime = e[1]
},
// 处理图表数据(带高亮超出部分)
getServerData(val) {
const chartDataList = val.map(item => {
const series = [];
// 处理主要数据 - 确保都是Number格式
const mainData = (item.data.slice(0, 50) || Array(this.timeList?.length || 0).fill(0))
.map(value => Number(value) || 0);
const highValNum = item.highVal ? Number(item.highVal) || 0 : null;
const lowValNum = item.lowVal ? Number(item.lowVal) || 0 : null;
// 正常数据线
series.push({
name: item.itemName,
data: mainData,
color: "#1890FF"
});
// 阈值线(保持原来的虚线)
if (highValNum !== null) {
series.push({
name: '最高阈值',
data: Array(this.timeList?.length || 0).fill(highValNum),
color: "#FF4242",
lineType: "solid",
showLabel: false,
// 全局隐藏数据标签
dataLabel: {
fontSize: 0,
show: false
},
});
}
if (lowValNum !== null) {
series.push({
name: '最低阈值',
data: Array(this.timeList?.length || 0).fill(lowValNum),
color: "#19D58A",
lineType: "solid",
showLabel: false,
// 全局隐藏数据标签
dataLabel: {
fontSize: 0,
show: false
},
});
}
return {
categories: this.timeList.slice(0, 50) || [],
series: series
};
});
// 更新resolt数据
this.resolt = this.resolt.map((item, index) => {
return {
...item,
chartData: chartDataList[index] || this.getDefaultChartData(item.itemName)
};
});
console.log("处理后的趋势图数据", this.resolt);
},
// 获取默认图表数据
getDefaultChartData(itemName) {
return {
categories: [],
series: [{
name: itemName,
data: []
}]
};
},
}
}
</script>
<style lang="scss">
page {
height: 100%;
background: #fff;
/* 确保页面可以滚动 */
overflow: auto;
}
.container {
min-height: 100%;
/* 改为 min-height */
padding-bottom: 20rpx;
}
.searchbox {
height: 148rpx;
padding: 15rpx 30rpx;
background-color: white;
position: relative;
display: flex;
justify-content: space-between;
}
.search_input {
border: none;
height: 60rpx;
width: 86%;
font-size: 24rpx;
border-radius: 30rpx;
background-color: #F6F6F6;
padding-left: 50rpx;
}
.searchbox image {
width: 32rpx;
height: 32rpx;
position: absolute;
left: 40rpx;
top: 35%;
z-index: 99;
}
.searchbutton {
width: 10%;
height: 60rpx;
font-size: 26rpx;
text-align: center;
line-height: 60rpx;
}
.itembox {
background-color: white;
padding: 10rpx 30rpx;
margin-top: 20rpx;
}
.itembox:first-child {
margin-top: 0;
}
.itembox_top {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20rpx 0;
border-bottom: 2rpx solid #e4e4e4;
}
.itembox_lef image {
width: 40rpx;
height: 40rpx;
margin-right: 14rpx;
}
.itembox_lef {
display: flex;
align-items: center;
font-weight: 500;
width: 63%;
}
.title {
font-weight: bold;
}
.load {
height: 100rpx;
line-height: 100rpx;
text-align: center;
color: #c6c6c6;
}
.zwsj {
width: 100%;
display: flex;
padding: 60% 170rpx 0;
}
.inzwsj {
width: 100%;
}
.zwsjimg {
width: 100%;
height: 224rpx;
margin-bottom: 37rpx;
}
.zwsjtext {
width: 100%;
font-size: 26rpx;
font-family: Source Han Sans SC;
font-weight: 400;
color: #999999;
line-height: 31rpx;
text-align: center;
}
.topScroll {
width: 100%;
height: 85rpx;
background-color: #fff;
border-bottom: 1rpx solid #ededed;
position: sticky;
top: 0;
z-index: 999;
}
.scroll {
height: 85rpx;
display: flex;
white-space: nowrap;
justify-content: space-between;
padding-top: 12rpx;
background: #fff;
}
.scroll-item {
width: 50%;
text-align: center;
display: inline-block;
font-size: 28rpx;
font-family: Source Han Sans SC;
}
.scroll-item2 {
font-size: 30rpx;
font-family: Source Han Sans SC;
color: #0F6EFF;
}
.zliebs {
width: 100rpx;
height: 4rpx;
background-color: #0F6EFF;
margin: 12rpx auto 0;
border-radius: 20rpx;
}
.lists_item {
padding: 0rpx 0rpx 16rpx 0rpx;
box-sizing: border-box;
display: flex;
}
.lists_item {
padding-top: 16rpx;
}
.jczbs {
width: 32%;
font-size: 24rpx;
font-family: Source Han Sans SC;
font-weight: 400;
color: #667482;
}
.zbz {
width: 27%;
font-size: 24rpx;
font-family: DIN Next LT Pro;
font-weight: 400;
}
.sbsj {
font-size: 24rpx;
font-family: Source Han Sans SC;
font-weight: 400;
color: #667482;
width: 23%;
display: flex;
align-items: center;
}
.zximg {
width: 30rpx;
height: 30rpx;
margin-left: 6rpx;
}
.szqss {
flex: 1;
font-size: 24rpx;
font-family: Source Han Sans SC;
font-weight: 400;
}
.scrolltop {
padding: 20rpx 0rpx 16rpx 0rpx;
display: flex;
justify-content: space-between;
border-bottom: 2rpx solid #F6F8FB;
width: 100%;
}
.tabitem {
font-size: 26rpx;
font-family: Source Han Sans SC;
font-weight: 500;
color: #2F3841;
display: inline-block;
padding-bottom: 8rpx;
}
.tabitem:first-child {
width: 31%;
}
.tabitem:nth-child(2) {
width: 27%;
}
.tabitem:nth-child(3) {
width: 23%;
}
.tabitem:nth-child(4) {
flex: 1
}
.itembox_right {
font-size: 26rpx;
}
.charts-box {
width: 100%;
height: 400rpx;
/* 适当增加高度 */
overflow-x: auto;
/* 允许横向滚动 */
display: block;
}
.qushicov {
margin-bottom: 60rpx;
overflow: hidden;
.quname {
display: block;
text-align: center;
line-height: 60rpx;
font-weight: bold;
font-size: 28rpx;
margin-bottom: 10rpx;
}
}
</style>