mkm
/
yanzhiAPP
Template
2
0
Fork 0
yanzhiAPP/pages/profile/index.vue

306 lines
6.1 KiB
Vue
Raw Normal View History

2023-10-21 18:02:06 +08:00
<template>
<view class="" style="padding: 30rpx;">
<view class="" style="padding: 20rpx;box-sizing: border-box;">
<view class="head">
<view class="subsection">
2023-10-29 22:36:02 +08:00
<view class="subsection-li" @click="changeDate('day')">
2023-10-21 18:02:06 +08:00
</view>
2023-10-29 22:36:02 +08:00
<view class="subsection-li" @click="changeDate('month')">
2023-10-21 18:02:06 +08:00
</view>
<view class="act" :style="{left:leftNum+'rpx'}">
</view>
</view>
2023-10-29 22:36:02 +08:00
<view class="set">
<view class="" style="margin: 0 10rpx;" @tap='choseDateFn'>
2023-10-21 18:02:06 +08:00
<u-icon name="setting" color="white" size="15"></u-icon>
</view> 自定义
</view>
</view>
<view class="">
<view class="tit">
土地检测数据
</view>
2023-10-26 19:02:26 +08:00
<view class="charts-box" v-for="(item,index) in baseData " :key="index">
2023-10-31 18:40:32 +08:00
<qiun-data-charts type="line" :opts="opts[index]" :chartData="chartData[index]" />
2023-10-21 18:02:06 +08:00
</view>
2023-10-26 19:02:26 +08:00
2023-10-21 18:02:06 +08:00
</view>
2023-10-23 17:57:19 +08:00
2023-10-21 18:02:06 +08:00
</view>
</view>
2023-10-31 18:40:32 +08:00
2023-10-29 22:36:02 +08:00
<uni-calendar :insert="false" ref="calendar" :range='true' :lunar="true" @confirm="confirm" />
2023-10-21 18:02:06 +08:00
</template>
<script>
2023-10-26 19:02:26 +08:00
import {
landEnvDataChartAPI
} from "@/api/plant.js"
2023-10-21 18:02:06 +08:00
export default {
data() {
return {
2023-10-29 22:36:02 +08:00
type: false,
showPicker: false,
2023-10-26 19:02:26 +08:00
leftNum: 10,
baseData: [],
xInfo: [{
name: "土壤温度(℃)",
data: 'soil_temp'
}, {
name: "土壤湿度(%RH)",
2023-10-21 18:02:06 +08:00
2023-10-26 19:02:26 +08:00
data: 'soil_mois'
}, {
name: "磷含量%)",
data: 'p_content'
}, {
name: "氮含量(mg/l)",
data: 'n_content'
}, {
name: "钾含量(%)",
data: 'k_content'
2023-10-21 18:02:06 +08:00
},
2023-10-26 19:02:26 +08:00
],
chartData: [],
2023-10-31 18:40:32 +08:00
opts: []
};
},
onReady() {
// console.log(this.getFiveDay())
this.initCharts(this.getFiveDay()[4], this.getFiveDay()[0])
},
methods: {
getOptFn() {
return {
2023-10-27 23:24:26 +08:00
dataLabel: false,
2023-10-26 19:02:26 +08:00
color: ["#1890FF"],
padding: [15, 15, 0, 15],
2023-10-21 18:02:06 +08:00
yAxis: {
gridType: "dash",
dashLength: 4,
gridColor: "#CCCCCC",
padding: 10,
data: [{
position: "left",
2023-10-26 19:02:26 +08:00
title: "",
min: 0,
2023-10-31 18:40:32 +08:00
max: 100,
2023-10-21 18:02:06 +08:00
},
{
position: "right",
min: 0,
2023-10-31 18:40:32 +08:00
max: 110,
2023-10-21 18:02:06 +08:00
title: "",
textAlign: "left"
},
]
},
2023-10-27 23:24:26 +08:00
xAxis: {
2023-10-29 22:36:02 +08:00
disabled: false
2023-10-27 23:24:26 +08:00
},
extra: {
line: {
type: "curve",
animation: "horizontal"
}
}
2023-10-31 18:40:32 +08:00
}
},
2023-10-29 22:36:02 +08:00
getFiveDay() {
const today = new Date();
const lastFiveDays = [];
for (let i = 0; i < 5; i++) {
const date = new Date(today.getTime() - (i + 1) * 24 * 60 * 60 * 1000);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
lastFiveDays.push(`${year}-${month}-${day}`);
}
return lastFiveDays;
},
choseDateFn() {
// console.log()
this.$refs.calendar.open()
},
confirm(e) {
// console.log(e)
2023-10-31 18:40:32 +08:00
this.opts.forEach(item => {
console.log(item)
item.xAxis.disabled = true
})
2023-10-29 22:36:02 +08:00
this.initCharts(e.range.before, e.range.after)
},
changeDate(type) {
if (type == 'day') {
2023-10-31 18:40:32 +08:00
this.opts.forEach(item => {
console.log(item)
item.xAxis.disabled = false
})
2023-10-29 22:36:02 +08:00
this.opts.xAxis.disabled = false
this.leftNum = 10
this.initCharts(this.getFiveDay()[4], this.getFiveDay()[0])
} else {
this.leftNum = 160
2023-10-31 18:40:32 +08:00
let date = new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-'
2023-10-29 22:36:02 +08:00
this.initCharts(date + '01', date + '30')
2023-10-31 18:40:32 +08:00
// this.opts.xAxis.disabled = true
this.opts.forEach(item => {
console.log(item)
item.xAxis.disabled = true
})
2023-10-29 22:36:02 +08:00
}
2023-10-26 19:02:26 +08:00
// this.initCharts('2023-10-23', '2023-10-27')
2023-10-21 18:02:06 +08:00
},
navgo() {
uni.navigateTo({
url: '/pages/index3/index'
})
},
backFn() {
uni.navigateBack()
},
2023-10-26 19:02:26 +08:00
initCharts(start_time, end_time) {
landEnvDataChartAPI({
user_id: 307,
start_time,
end_time
}).then(res => {
2023-10-31 18:40:32 +08:00
res.data.forEach((item, index) => {
this.opts.push(this.getOptFn())
// console.log()
this.opts[index].yAxis.data[0].max = item.max
this.opts[index].yAxis.data[1].max = item.max
})
// console.log(res.data[0].max)
2023-10-29 22:36:02 +08:00
this.baseData = res.data
2023-10-26 19:02:26 +08:00
let datas = this.baseData
this.baseData.forEach((item, index) => {
this.getServerData(item, index)
})
})
},
getServerData(datas, index) {
2023-10-21 18:02:06 +08:00
setTimeout(() => {
let res = {
2023-10-26 19:02:26 +08:00
categories: datas['create_time'],
2023-10-21 18:02:06 +08:00
series: [{
2023-10-26 19:02:26 +08:00
name: this.xInfo[index].name,
index: 1,
2023-10-27 23:24:26 +08:00
type: "lines",
2023-10-26 19:02:26 +08:00
data: datas[this.xInfo[index].data]
}]
2023-10-21 18:02:06 +08:00
};
2023-10-26 19:02:26 +08:00
this.chartData[index] = JSON.parse(JSON.stringify(res));
2023-10-21 18:02:06 +08:00
}, 500);
},
}
};
</script>
<style lang="less" scoped>
.head {
// height: 10vh;
display: flex;
justify-content: space-between;
align-items: center;
// background-color: red;
.subsection {
display: flex;
2023-10-23 17:57:19 +08:00
width: 300.12rpx;
2023-10-21 18:02:06 +08:00
height: 98.13rpx;
background-color: #F4F4F4;
border-radius: 50.82rpx 50.82rpx 50.82rpx 50.82rpx;
line-height: 5vh;
position: relative;
.subsection-li {
width: 150.7rpx;
height: 84.11rpx;
border-radius: 50.82rpx 50.82rpx 50.82rpx 50.82rpx;
text-align: center;
line-height: 94rpx;
z-index: 8;
// margin-top: 10rpx;
}
.act {
position: absolute;
width: 130.7rpx;
height: 84.11rpx;
border-radius: 50.82rpx 50.82rpx 50.82rpx 50.82rpx;
background-color: #fff;
top: 50%;
transform: translateY(-50%);
transition: .5s;
}
}
.set {
width: 159.46rpx;
height: 63.08rpx;
font-size: 29.79rpx;
background-color: #0BC677;
border-radius: 31.54rpx 31.54rpx 31.54rpx 31.54rpx;
color: white;
text-align: center;
line-height: 63rpx;
display: flex;
align-items: center;
}
}
.tit {
text-align: center;
margin: 30rpx 0;
font-size: 36.8rpx;
}
.charts-box {
width: 100%;
height: 300px;
border: 1px solid black;
margin-bottom: 40rpx;
}
.detect {
.line {
width: 7.01rpx;
height: 31.54rpx;
background-color: #4CC593;
display: inline-block;
margin-right: 10rpx;
}
.detecttit {
font-size: 31.54rpx;
display: flex;
align-items: center;
}
.content {
padding-top: 20rpx;
}
}
</style>