agri-app/pages/data/index.vue

191 lines
5.0 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<view class="charts-box">
<view>
<uni-row class="demo-uni-row" >
<uni-col :span="8">
<uni-data-select v-model="imei" :localdata="agriList" @change="changeAgri"></uni-data-select>
</uni-col>
<uni-col :span="16">
<uni-datetime-picker v-model="dateRange" type="datetimerange" @change="changeDate"/>
</uni-col>
</uni-row>
</view>
<qiun-data-charts
type="line"
:opts="opts"
background="#fff"
:chartData="chartData"
:canvas2d="true"
canvasId="nMPkeQGNEosMwoWKKNRBZBIEhguMoMWp"
:ontouch="true"
:disableScroll="true"
:onmovetip="true"
tooltipFormat="tooltipDemo"
/>
<!-- 暂无数据 -->
</view>
</template>
<script>
import { getHistoryData} from "../../api/system/data";
import {listAgri} from "../../api/system/assets/agri";
import store from "../../store";
import {parseTime} from "../../utils/agri";
export default {
data: function () {
return {
chartData: {},
//这里的 opts 是图表类型 type="line" 的全部配置参数,您可以将此配置复制到 config-ucharts.js 文件中下标为 ['line'] 的节点中来覆盖全局默认参数。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式,达到页面简洁的需求。
opts: {
legend: {
},
xAxis: {
rotateAngle: 75,
format: "xAxisDemo"
},
yAxis: {
gridType: "dash",
dashLength: 2,
disabled: false,
disableGrid: false,
splitNumber: 5,
gridColor: "#CCCCCC",
padding: 10,
showTitle: true,
data: [
{
type: "value",
position: "left",
disabled: false,
axisLine: true,
axisLineColor: "#CCCCCC",
calibration: true,
fontColor: "#666666",
fontSize: 13,
textAlign: "left",
title: "温度(℃)",
titleFontSize: 14,
titleOffsetY: -10,
titleOffsetX: 5,
titleFontColor: "#333333",
min: 0,
max: 50,
tofix: 1,
unit: "",
format: ""
},
{
type: "value",
position: "right",
disabled: false,
axisLine: true,
axisLineColor: "#CCCCCC",
calibration: true,
fontColor: "#666666",
fontSize: 13,
textAlign: "right",
title: "湿度(%RH",
titleFontSize: 14,
titleOffsetY: -10,
titleOffsetX: 0,
titleFontColor: "#333333",
min: 0,
max: 100,
tofix: 1,
unit: "",
format: ""
}
]
}
},
dateRange:[],
end:Date.now(),
agriList:[],
imei:null
};
},
onReady() {
this.getAgriList();
},
methods: {
getServerData() {
const param = {
imei: this.imei,
startTime: this.dateRange[0],
endTime: this.dateRange[1]
}
console.info("查询参数",param)
//模拟从服务器获取数据时的延时
getHistoryData(param).then(response => {
if (response.code === 200 && response.data) {
var data = response.data;
this.chartData = JSON.parse(JSON.stringify(data));
}
})
},
getAgriList() {
listAgri().then(response => {
if (response.code === 200) {
this.agriList = response.rows.map(item => ({
agriId: item.id,
text: item.agriName,
value: item.imei // 提取并改名
}));
if (store.getters && store.getters.name === 'admin') {
this.agriList.push(
{
text:"八方南棚",
value:"A"
},
{
text:"九方春棚",
value:"B"
},
{
text:"十二方棚",
value:"C"
}
)
}
this.imei = this.agriList[0].value;
this.getServerData();
}
})
},
changeAgri(imei) {
if (imei) {
this.getServerData();
}
},
changeDate(date) {
// date[0]-date[1]
console.info("日期选择器:",date)
if (date[0] === date[1]) {
this.dateRange[0] = parseTime(date[0], '{y}-{m}-{d} 00:00:00')
}
if (this.imei) {
this.getServerData();
}
}
}
};
</script>
<style scoped>
/* 请根据实际需求修改父元素尺寸,组件自动识别宽高 */
.charts-box {
width: 100%;
height: 500px;
}
/deep/ .uni-stat__select {
background: #fff !important;
}
</style>