单体电池
This commit is contained in:
178
pages/work/dtdc/Chart.vue
Normal file
178
pages/work/dtdc/Chart.vue
Normal file
@ -0,0 +1,178 @@
|
||||
<template>
|
||||
<uni-popup ref="popup" type="center" @maskClick="show = false">
|
||||
<view class="chart-popup">
|
||||
<uni-datetime-picker v-model="range" type="daterange" start="2000-01-01" :end="end" rangeSeparator="至"
|
||||
@change="changeTime" />
|
||||
<view class="button-group" style="text-align: center;margin-top:20px;">
|
||||
<button type="default" size="mini" @click="onReset">重置</button>
|
||||
<button type="primary" size="mini" @click="onSearch" style="margin-left: 20px;">搜索</button>
|
||||
</view>
|
||||
<view class="chart-container">
|
||||
<qiun-data-charts type="line" :reload="show" :chartData="chartsData" :canvas2d="true"
|
||||
canvasId="componentsinit" :optsWatch='false' :inScrollView="true" :pageScrollTop="pageScrollTop"
|
||||
:opts="options" />
|
||||
</view>
|
||||
</view>
|
||||
</uni-popup>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import QiunDataCharts from '@/uni_modules/qiun-data-charts/components/qiun-data-charts/qiun-data-charts.vue'
|
||||
import {
|
||||
getSingleBatteryData
|
||||
} from '@/api/ems/site.js'
|
||||
export default {
|
||||
components: {
|
||||
QiunDataCharts
|
||||
},
|
||||
props: {
|
||||
pageScrollTop: {
|
||||
type: Number,
|
||||
default: 0
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
options: {
|
||||
update: true,
|
||||
duration: 0,
|
||||
animation: false,
|
||||
// enableScroll: true,
|
||||
// padding: [10, 15, 10, 15]
|
||||
},
|
||||
show: false,
|
||||
range: [],
|
||||
end: "",
|
||||
siteId: '',
|
||||
deviceId: '',
|
||||
clusterDeviceId: '',
|
||||
dataType: '', //展示的数据类型 空值展示所有数据
|
||||
loading: false,
|
||||
chartsData: {},
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
open({
|
||||
siteId,
|
||||
clusterDeviceId,
|
||||
deviceId
|
||||
}, dataType) {
|
||||
this.$refs.popup.open()
|
||||
this.loading = false
|
||||
this.siteId = siteId
|
||||
this.clusterDeviceId = clusterDeviceId
|
||||
this.deviceId = deviceId
|
||||
this.dataType = dataType
|
||||
this.range = []
|
||||
setTimeout(() => {
|
||||
this.show = true
|
||||
this.getData()
|
||||
}, 300)
|
||||
},
|
||||
changeTime(val) {
|
||||
this.range = val || []
|
||||
},
|
||||
onReset() {
|
||||
this.range = []
|
||||
this.getData()
|
||||
},
|
||||
onSearch() {
|
||||
this.getData()
|
||||
},
|
||||
getData() {
|
||||
if (this.loading) return
|
||||
this.loading = true;
|
||||
const {
|
||||
siteId,
|
||||
deviceId,
|
||||
clusterDeviceId,
|
||||
range: [startDate = '', endDate = '']
|
||||
} = this;
|
||||
this.chartsData?.series && (this.chartsData.series = [])
|
||||
return getSingleBatteryData({
|
||||
siteId,
|
||||
deviceId,
|
||||
clusterDeviceId,
|
||||
startDate,
|
||||
endDate
|
||||
}).then(response => {
|
||||
console.log('单体电池图表返回数据', response.data)
|
||||
this.handledata(response?.data || [])
|
||||
}).finally(() => {
|
||||
this.loading = false;
|
||||
})
|
||||
},
|
||||
handledata(data) {
|
||||
let obj = {
|
||||
voltage: '电压',
|
||||
temperature: '温度',
|
||||
soc: 'SOC',
|
||||
soh: 'SOH',
|
||||
},
|
||||
categories = [],
|
||||
dataTypeList = []
|
||||
if (this.dataType) {
|
||||
dataTypeList = [{
|
||||
attr: this.dataType,
|
||||
title: obj[this.dataType],
|
||||
data: []
|
||||
}]
|
||||
} else {
|
||||
dataTypeList = Object.entries(obj).map(([key, value]) => {
|
||||
return {
|
||||
attr: key,
|
||||
title: value,
|
||||
data: []
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
data.forEach(item => {
|
||||
categories.push(item.dataTimestamp)
|
||||
dataTypeList.forEach(i => {
|
||||
i.data.push(item[i.attr] || undefined)
|
||||
})
|
||||
})
|
||||
const series = dataTypeList.map(item => {
|
||||
return {
|
||||
"name": item.title,
|
||||
"data": item.data
|
||||
}
|
||||
})
|
||||
this.chartsData = JSON.parse(JSON.stringify({
|
||||
categories,
|
||||
series
|
||||
}))
|
||||
console.log('this.chartsData', this.chartsData)
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
const now = new Date(),
|
||||
year = now.getFullYear(),
|
||||
month = now.getMonth() + 1,
|
||||
day = now.getDate()
|
||||
this.end = year + '-' + month + '-' + day
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.chart-popup {
|
||||
width: 360px;
|
||||
background-color: #fff;
|
||||
padding: 10px 15px;
|
||||
|
||||
.chart-container {
|
||||
width: 100%;
|
||||
height: 250px;
|
||||
}
|
||||
|
||||
::v-deep {
|
||||
uni-canvas {
|
||||
height: 250px;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@ -24,7 +24,7 @@
|
||||
<template v-slot:header>
|
||||
<view class="list-header">
|
||||
单体编号:{{item.deviceId}}
|
||||
<button type="warn" size="mini" class="charts">图表</button>
|
||||
<button type="warn" size="mini" class="charts" @click="toDetail(item)">图表</button>
|
||||
</view>
|
||||
</template>
|
||||
<template v-slot:body>
|
||||
@ -42,7 +42,7 @@
|
||||
<view>电压(V)</view>
|
||||
</uni-col>
|
||||
<uni-col :span="14">
|
||||
<view class="right color">{{item.voltage}}
|
||||
<view class="right color" @click="toDetail(item,'voltage')">{{item.voltage}}
|
||||
</view>
|
||||
</uni-col>
|
||||
</uni-row>
|
||||
@ -51,7 +51,7 @@
|
||||
<view>温度(℃)</view>
|
||||
</uni-col>
|
||||
<uni-col :span="14">
|
||||
<view class="right color">
|
||||
<view class="right color" @click="toDetail(item,'temperature')">
|
||||
{{item.temperature}}
|
||||
</view>
|
||||
</uni-col>
|
||||
@ -61,7 +61,7 @@
|
||||
<view>SOC(%)</view>
|
||||
</uni-col>
|
||||
<uni-col :span="14">
|
||||
<view class="right color">{{item.soc}}</view>
|
||||
<view class="right color" @click="toDetail(item,'soc')">{{item.soc}}</view>
|
||||
</uni-col>
|
||||
</uni-row>
|
||||
<uni-row>
|
||||
@ -69,7 +69,7 @@
|
||||
<view>SOH(%)</view>
|
||||
</uni-col>
|
||||
<uni-col :span="14">
|
||||
<view class="right color">{{item.soh}}</view>
|
||||
<view class="right color" @click="toDetail(item,'soh')">{{item.soh}}</view>
|
||||
</uni-col>
|
||||
</uni-row>
|
||||
</view>
|
||||
@ -77,10 +77,12 @@
|
||||
</uni-list-item>
|
||||
</uni-list>
|
||||
</view>
|
||||
<chart ref="chart" :pageScrollTop="pageScrollTop" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Chart from './Chart.vue'
|
||||
import {
|
||||
getStackNameList,
|
||||
getClusterNameList,
|
||||
@ -90,6 +92,9 @@
|
||||
mapState
|
||||
} from 'vuex'
|
||||
export default {
|
||||
components: {
|
||||
Chart
|
||||
},
|
||||
computed: {
|
||||
...mapState({
|
||||
workStatusOptions: (state) =>
|
||||
@ -111,9 +116,26 @@
|
||||
},
|
||||
list: [],
|
||||
siteId: '',
|
||||
pageScrollTop: 0,
|
||||
}
|
||||
},
|
||||
onPageScroll(e) {
|
||||
this.pageScrollTop = e.scrollTop
|
||||
},
|
||||
methods: {
|
||||
toDetail(item, dataType) {
|
||||
const {
|
||||
clusterDeviceId,
|
||||
deviceId
|
||||
} = item, {
|
||||
siteId
|
||||
} = this
|
||||
this.$refs.chart.open({
|
||||
siteId,
|
||||
clusterDeviceId,
|
||||
deviceId
|
||||
}, dataType)
|
||||
},
|
||||
onReachBottom() {
|
||||
console.log('触底了')
|
||||
this.pageNum += 1 //每次搜索从1开始搜索
|
||||
|
||||
Reference in New Issue
Block a user