wechat
lgyg 2023-08-28 23:43:22 +08:00
parent 07eca62897
commit b4cf2d5312
3 changed files with 625 additions and 83 deletions

View File

@ -459,4 +459,31 @@ export function testBank(bank){
export function testPhone(phone){
let reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
return reg.test(phone)
}
// 获取近一周的日期范围
export function getLastWeekRange() {
// 获取当前日期
let currentDate = new Date();
let lastWeekStartDate = new Date(currentDate);
lastWeekStartDate.setDate(currentDate.getDate() - 7);
let lastWeekEndDate = new Date(currentDate);
lastWeekEndDate.setDate(currentDate.getDate() - 1);
return {
startDate: lastWeekStartDate,
endDate: lastWeekEndDate,
};
}
// 获取近一月的日期范围
export function getLastMonthRange() {
let currentDate = new Date();
let lastMonthStartDate = new Date(currentDate);
lastMonthStartDate.setMonth(currentDate.getMonth() - 1);
let lastMonthEndDate = new Date(currentDate);
lastMonthEndDate.setDate(currentDate.getDate() - 1);
return {
startDate: lastMonthStartDate,
endDate: lastMonthEndDate,
};
}

View File

@ -71,6 +71,10 @@ const cfu = {
return series[index].name+''+series[index].data+'元'
}
},
"windDirection":function(val, index, series, opts){
let catenames = ['北风','东北风','东风','东南风','南风','西南风','西风','西北风'];
return catenames[val]
},
},
//这里演示了自定义您的图表类型的option可以随意命名之后在组件上 type="demotype" 后组件会调用这个花括号里的option如果组件上还存在opts参数会将demotype与opts中option合并后渲染图表。
"demotype":{

View File

@ -1,34 +1,195 @@
<template>
<view class="meteorological-page">
<qiun-data-charts
type="area"
:opts="opts"
:chartData="chart_air_temperature"
/>
<qiun-data-charts
type="area"
:opts="opts"
:chartData="chart_air_humidity"
/>
<qiun-data-charts
type="scatter"
:opts="opts"
:chartData="chart_illumination"
/>
<view class="content-box">
<!-- <view class="screen-box">筛选条件</view> -->
<view class="secreen-section">
<u-dropdown ref="uDropdown" @open="openDropDown">
<u-dropdown-item v-model="addressValue" title="基地"
:options="deviceAddressList" @change="change"></u-dropdown-item>
<u-dropdown-item v-model="device_id" title="检测点"
:options="options2" @change="change2"></u-dropdown-item>
<u-dropdown-item title="日期">
<view class="slot-content" style="background-color: #FFFFFF;">
<view class="select-date u-border-bottom" >
<view class="name" @click="calendarShow = true">
<u-icon name="calendar" color="#333" size="32"></u-icon>
<text style="margin-left: 6rpx;">选择日期</text>
</view>
<view class="time_box">
<view class="tip_txt" v-if="!start_date_c"
@click="calendarShow = true">开始日期-结束日期</view>
<view class="tile_val" v-else
@click="calendarShow = true">{{start_date_c}} ~ {{end_date_c}}</view>
<view class="delete_btn" v-if="start_date_c" @click="deleteDateFn()">
<u-icon name="close-circle" color="#333" size="34"></u-icon>
</view>
</view>
</view>
<u-button type="primary" @click="selectedDateConform()"></u-button>
</view>
</u-dropdown-item>
</u-dropdown>
<view class="quick_times">
<u-subsection :list="sublist" :animation="false"
:current="currentIndex" @change="subChange1"></u-subsection>
</view>
</view>
<!-- 空气温度 -->
<view class="chart_section">
<view class="top_box u-border-bottom">
<view class="tit">空气温度<text class="unit"></text></view>
<view class="name">{{addressName}}</view>
</view>
<view class="cart_box">
<qiun-data-charts
type="area"
:opts="opts"
:chartData="chart_air_temperature"
/>
</view>
</view>
<!-- 空气湿度 -->
<view class="chart_section">
<view class="top_box u-border-bottom">
<view class="tit">空气湿度<text class="unit">%RH</text></view>
<view class="name">{{addressName}}</view>
</view>
<view class="cart_box">
<qiun-data-charts
type="area"
:opts="opts"
:chartData="chart_air_humidity"
/>
</view>
</view>
<!-- 光照强度 -->
<view class="chart_section">
<view class="top_box u-border-bottom">
<view class="tit">光照强度<text class="unit">Lux</text></view>
<view class="name">{{addressName}}</view>
</view>
<view class="cart_box">
<qiun-data-charts
type="mix"
:opts="opts2"
:chartData="chart_illumination"
/>
</view>
</view>
<!-- 降雨量 -->
<view class="chart_section">
<view class="top_box u-border-bottom">
<view class="tit">降雨量<text class="unit">mm</text></view>
<view class="name">{{addressName}}</view>
</view>
<view class="cart_box">
<qiun-data-charts
type="mix"
:opts="opts2"
:chartData="chart_rainfall"
/>
</view>
</view>
<!-- 风速 -->
<view class="chart_section">
<view class="top_box u-border-bottom">
<view class="tit">风速<text class="unit">m/s</text></view>
<view class="name">{{addressName}}</view>
</view>
<view class="cart_box">
<qiun-data-charts
type="area"
:opts="opts3"
:chartData="chart_wind_speed"
/>
</view>
</view>
<!-- 风向 -->
<view class="chart_section">
<view class="top_box u-border-bottom">
<view class="tit">风向<text class="unit"></text></view>
<view class="name">{{addressName}}</view>
</view>
<view class="cart_box">
<qiun-data-charts
type="mix"
:opts="opts4"
:chartData="chart_wind_direction"
/>
</view>
</view>
<!-- 噪音 -->
<view class="chart_section">
<view class="top_box u-border-bottom">
<view class="tit">噪音<text class="unit">db</text></view>
<view class="name">{{addressName}}</view>
</view>
<view class="cart_box">
<qiun-data-charts
type="area"
:opts="opts3"
:chartData="chart_noise"
/>
</view>
</view>
<!-- pm10 -->
<view class="chart_section">
<view class="top_box u-border-bottom">
<view class="tit">PM10<text class="unit">ug/m3</text></view>
<view class="name">{{addressName}}</view>
</view>
<view class="cart_box">
<qiun-data-charts
type="area"
:opts="opts3"
:chartData="chart_pm10"
/>
</view>
</view>
<!-- pm25 -->
<view class="chart_section">
<view class="top_box u-border-bottom">
<view class="tit">PM25<text class="unit">ug/m3</text></view>
<view class="name">{{addressName}}</view>
</view>
<view class="cart_box">
<qiun-data-charts
type="area"
:opts="opts3"
:chartData="chart_pm25"
/>
</view>
</view>
<!-- co2 -->
<view class="chart_section">
<view class="top_box u-border-bottom">
<view class="tit">CO2<text class="unit">ppm</text></view>
<view class="name">{{addressName}}</view>
</view>
<view class="cart_box">
<qiun-data-charts
type="area"
:opts="opts3"
:chartData="chart_co2"
/>
</view>
</view>
</view>
<u-calendar v-model="calendarShow" :mode="'range'" @change="calendarChange"></u-calendar>
</view>
</template>
<script>
import QiunDataCharts from '@/components/qiun-data-charts/qiun-data-charts.vue'
import {showLoading,getLastWeekRange,getLastMonthRange} from '@/com/utils.js'
export default {
components: { QiunDataCharts },
data() {
return {
air_temperature:{},
chart_air_temperature:{},
opts: {
dataLabel:false,//
padding:[10,40,25,25],
xAxis: {
disableGrid: true,
labelCount:5
@ -46,119 +207,415 @@
},
}
},
opts2: {
dataLabel:false,//
padding:[10,40,25,25],
xAxis: {
disableGrid: true,
labelCount:5
},
yAxis: {
data: [
{
position: "left",
title: "",
textAlign: "left",
}
]
},
},
opts3: {
dataLabel:false,//
padding:[10,40,25,25],
xAxis: {
disableGrid: true,
labelCount:5
},
yAxis: {
data: [
{
position: "left",
title: "",
textAlign: "left",
}
]
},
extra: {
area: {
type: "curve",
opacity: 0.9,
addLine: true,
gradient: true,
},
}
},
opts4: {//
dataLabel:false,//
padding:[10,40,25,25],
xAxis: {
disableGrid: true,
labelCount:5
},
yAxis: {
splitNumber:7,
data: [
{
max:7,
min:0,
position: "left",
title: "",
textAlign: "left",
format:"windDirection"
}
]
},
},
air_temperature:{},
chart_air_temperature:{},
air_humidity:{},//湿
chart_air_humidity:{},
illumination:{},//
chart_illumination:{},
chart_rainfall:{},//
chart_wind_speed:{},//
chart_wind_direction:{},//
chart_noise:{},//
chart_pm10:{},//pm10
chart_pm25:{},//pm25
chart_co2:{},//co2
q_start_time:'',
q_end_time:'',
deviceAddressList:[],//
addressName:'',
addressValue:'',
device_id:'11',// - options2id
value3:'',//
options2:[],
calendarShow:false,//
start_date_c:'',
end_date_c:'',
sublist:[
{
name: '今天'
},
{
name: '近一周'
},
{
name: '近一月'
},
],
currentIndex:0,
};
},
onLoad(){
this.queryDeviceBasics();
},
onReady() {
this.queryMonitoringData();
},
methods:{
//
change(val){
console.log(val);
let narray = this.deviceAddressList.filter(item=>{
return item.value==val;
})
console.log(narray);
this.addressName = narray[0].name;
this.$refs.uDropdown.highlight(0);
this.queryAddressDevicePoints(val);
},
//id
change2(val){
this.$refs.uDropdown.highlight(1);
this.queryMonitoringData();
},
//
calendarChange(e){
console.log(e,'日期范围')
this.start_date_c = e.startDate;
this.end_date_c = e.endDate;
},
selectedDateConform(){
this.q_start_time = this.start_date_c;
this.q_end_time = this.end_date_c;
this.queryMonitoringData();
this.$refs.uDropdown.close();
},
//
deleteDateFn(){
this.start_date_c = '';
this.end_date_c = '';
},
//
openDropDown(index){
console.log(index,'openDropDown');
if(index==2){//
this.start_date_c = this.q_start_time;
this.end_date_c = this.q_end_time;
}
},
//
subChange1(index){
console.log(index)
this.currentIndex = index;
if(index==1){
let lastWeekDate = getLastWeekRange();
let startDate = this.$u.timeFormat(lastWeekDate.startDate, 'yyyy-mm-dd');
let endDate = this.$u.timeFormat(lastWeekDate.endDate, 'yyyy-mm-dd');
console.log(startDate,endDate);
this.q_start_time = startDate;
this.q_end_time = endDate;
}else if(index==2){
let lastMonthRange = getLastMonthRange();
let startDate = this.$u.timeFormat(lastMonthRange.startDate, 'yyyy-mm-dd');
let endDate = this.$u.timeFormat(lastMonthRange.endDate, 'yyyy-mm-dd');
console.log(startDate,endDate);
this.q_start_time = startDate;
this.q_end_time = endDate;
}else{
this.q_start_time = '';
this.q_end_time = '';
}
this.queryMonitoringData();
},
//
queryDeviceBasics(){
let params = {
device_type:4,
_t: new Date().getTime()
}
this.$http.get('/api/agricultural-device-basic',{params:params}).then(({data})=>{
console.log(data);
if(data.code==200){
let _data = data.data;
for(let item of _data){
item['label'] = item.name;
item['value'] = item.id;
}
this.deviceAddressList = _data;
this.addressValue = _data[0].id;
this.addressName = _data[0].name;
this.$refs.uDropdown.highlight(0);
this.queryAddressDevicePoints(this.addressValue);
}
}).catch(()=>{
})
},
//
queryAddressDevicePoints(id){
let params = {
device_type:4,
agricultural_basic:id,
_t: new Date().getTime()
}
this.$http.get(`/api/agricultural-device-point/${id}`,{params:params}).then(({data})=>{
console.log(data);
if(data.code==200){
let _data = data.data;
let options = [];
for(let k in _data){
let item = {};
item['label'] = _data[k];
item['value'] = k;
options.push(item);
}
this.options2 = options;
this.device_id = options[0].value;
console.log(this.options2,this.device_id,'this.options2')
this.queryMonitoringData();
}
}).catch(()=>{
})
},
//
queryMonitoringData(){
let params = {
device_id:11,
start_time:'',
end_time:'',
device_id:this.device_id,
start_time:this.q_start_time,
end_time:this.q_end_time,
_t: new Date().getTime()
}
this.$http.get('/api/monitoring-data',{params:params}).then(({data})=>{
if(data.code==200){
let _data = data.data;
//start air_temperature
this.air_temperature = _data.air_temperature;
let categories1 = [];
let sdata1 = [];
for(let k in this.air_temperature){
console.log(new Date(k),'---');
let timestamp = new Date(k).getTime();
// let time1 = k.split(/\s+/);
if(params.start_time!=params.end_time){
let time1 = this.$u.timeFormat(timestamp, 'yyyy-mm-dd');
categories1.push(time1);
}else{
let time2 = this.$u.timeFormat(timestamp, 'hh:ss');
categories1.push(time2);
}
sdata1.push(this.air_temperature[k]);
let info = data.data;
let chartInfo = {};
if(params.start_time!=params.end_time){//
this.opts.xAxis.labelCount = 4;
this.opts2.xAxis.labelCount = 4;
this.opts3.xAxis.labelCount = 4;
this.opts4.xAxis.labelCount = 4;
}
for(let fk in info){
let _item = {
categories: [],
data:[]
}
for(let k in info[fk]){
let timestamp = new Date(k).getTime();
// let time1 = k.split(/\s+/);
if(params.start_time!=params.end_time){
let time1 = this.$u.timeFormat(timestamp, 'yyyy-mm-dd');
_item.categories.push(time1);
}else{
let time2 = this.$u.timeFormat(timestamp, 'hh:ss');
_item.categories.push(time2);
}
_item.data.push(info[fk][k]);
}
chartInfo[fk] = _item;
}
console.log(chartInfo,'chartDatas--')
//start air_temperature
this.air_temperature = chartInfo.air_temperature;
let res = {
categories: categories1,
categories: this.air_temperature.categories,
series: [
{
name:'空气温度',
data: sdata1
legendShape:'circle',
data: this.air_temperature.data
}
]
};
this.chart_air_temperature = JSON.parse(JSON.stringify(res));
//end air_temperature
//start 湿
this.air_humidity = _data.air_humidity;
let categories2 = [];
let sdata2 = [];
for(let k in this.air_humidity){
console.log(new Date(k),'---');
let timestamp = new Date(k).getTime();
// let time1 = k.split(/\s+/);
if(params.start_time!=params.end_time){
let time1 = this.$u.timeFormat(timestamp, 'yyyy-mm-dd');
categories2.push(time1);
}else{
let time2 = this.$u.timeFormat(timestamp, 'hh:ss');
categories2.push(time2);
}
sdata2.push(this.air_humidity[k]);
}
this.air_humidity = chartInfo.air_humidity;
let res2 = {
categories: categories2,
categories: this.air_humidity.categories,
series: [
{
name:'空气湿度',
type: "point",
data: sdata2
legendShape:'circle',
data: this.air_humidity.data
}
]
};
this.chart_air_humidity = JSON.parse(JSON.stringify(res2));
//end 湿
//start illumination
this.illumination = _data.illumination;
let categories3 = [];
let sdata3 = [];
for(let k in this.illumination){
console.log(new Date(k),'---');
let timestamp = new Date(k).getTime();
// let time1 = k.split(/\s+/);
if(params.start_time!=params.end_time){
let time1 = this.$u.timeFormat(timestamp, 'yyyy-mm-dd');
categories3.push(time1);
}else{
let time2 = this.$u.timeFormat(timestamp, 'hh:ss');
categories3.push(time2);
}
sdata3.push(this.illumination[k]);
}
this.illumination = chartInfo.illumination;
let res3 = {
categories: categories3,
categories: this.illumination.categories,
series: [
{
index: 0,
type: "point",
pointShape:'circle',
legendShape:'circle',
name:'光照强度',
data: sdata3
data: this.illumination.data,
}
]
};
this.chart_illumination = JSON.parse(JSON.stringify(res3));
//end
//start rainfall
// this.air_temperature = chartInfo.rainfall;
let res4 = {
categories: chartInfo.rainfall.categories,
series: [
{
index: 0,
type: "point",
pointShape:'square',//triangle
legendShape:'square',
name:'降雨量',
data: chartInfo.rainfall.data,
}
]
};
this.chart_rainfall = JSON.parse(JSON.stringify(res4));
//start wind_speed
let res5 = {
categories: chartInfo.wind_speed.categories,
series: [
{
name:'风速',
legendShape:'circle',
data: chartInfo.wind_speed.data,
}
]
};
this.chart_wind_speed = JSON.parse(JSON.stringify(res5));
//end wind_speed
//start wind_direction
let res6 = {
categories: chartInfo.wind_direction.categories,
series: [
{
index: 0,
type: "point",
pointShape:'triangle',
legendShape:'triangle',
name:'风向',
data: chartInfo.wind_direction.data,
format:"windDirection"
}
]
};
this.chart_wind_direction = JSON.parse(JSON.stringify(res6));
//end wind_direction
//start noise
let res7 = {
categories: chartInfo.noise.categories,
series: [
{
name:'噪音',
legendShape:'circle',
data: chartInfo.noise.data,
}
]
};
this.chart_noise = JSON.parse(JSON.stringify(res7));
//end noise
//start pm10 pm10
let res8 = {
categories: chartInfo.pm10.categories,
series: [
{
name:'pm10',
legendShape:'circle',
data: chartInfo.pm10.data,
}
]
};
this.chart_pm10 = JSON.parse(JSON.stringify(res8));
//end pm10
//start pm25
let res9 = {
categories: chartInfo.pm25.categories,
series: [
{
name:'pm25',
legendShape:'circle',
data: chartInfo.pm25.data,
}
]
};
this.chart_pm25 = JSON.parse(JSON.stringify(res9));
//end pm25
//start co2
let res10 = {
categories: chartInfo.co2.categories,
series: [
{
name:'co2',
legendShape:'circle',
data: chartInfo.co2.data,
}
]
};
this.chart_co2 = JSON.parse(JSON.stringify(res10));
//end co2
}
}).catch(()=>{
@ -169,5 +626,59 @@
</script>
<style lang="scss" scoped>
.content-box{
padding-bottom: 60rpx;
}
.screen-box{
// height: 96rpx;
// display: flex;
// align-items: center;
// padding: 0 24rpx;
}
.secreen-section{
.slot-content{
padding: 30rpx;
}
.select-date{
padding: 30rpx;
display: flex;
align-items: center;
font-size: 28rpx;
margin-bottom: 40rpx;
.time_box{
display: flex;
align-items: center;
.tip_txt{
color: #ccc;
}
.delete_btn{
padding: 15rpx;
margin-left: 15rpx;
}
}
}
.quick_times{
padding: 18rpx 24rpx 24rpx 24rpx;
}
}
.chart_section{
.top_box{
display: flex;
align-items: center;
justify-content: space-between;
padding: 24rpx 30rpx;
margin-bottom: 20rpx;
font-size: 28rpx;
.tit{
font-size: 28rpx;
font-weight: bold;
.unit{
font-weight: 500;
margin-left: 16rpx;
font-size: 24rpx;
}
}
}
}
</style>