Commit d064713f authored by wends's avatar wends

update 实时监控

parent 48da2443
import request from '@/utils/request'
// const baseURL = process.env.VUE_APP_BASE_API
const baseURL = ''
// 获取图表数据
export function getModelInstanceChart(data) {
return request({
url: `${baseURL}iot/dashboard/modelData`,
method: 'post',
data
})
}
<template> <template>
<div> <div>
<el-card class="no-bottom"> <el-card class="no-bottom">
<el-form :model="form" inline> <el-form ref="form" :model="form" inline :rules="rules">
<el-form-item label="设备类型:"> <el-form-item label="设备类型:" prop="deviceType">
<el-select v-model="form.a" placeholder="请选择"> <el-select v-model="form.deviceType" @change="onDeviceTypeChange">
<el-option label="类型一" :value="null" /> <el-option
<el-option label="类型二" :value="1" /> v-for="(deviceType, index) in deviceTypeList"
:key="index"
:label="deviceType.name"
:value="deviceType.id"
/>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="设备实例:"> <el-form-item label="设备实例:" prop="deviceInstance">
<el-select v-model="form.a" placeholder="请选择"> <el-select v-model="form.deviceInstance" placeholder="请选择">
<el-option label="实例一" :value="null" /> <el-option
<el-option label="实例二" :value="1" /> v-for="(deviceInstance, index) in deviceInstanceList"
:key="index"
:label="deviceInstance.name"
:value="deviceInstance.id"
/>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="数据模型:"> <el-form-item label="数据模型:" prop="dataMode">
<el-select v-model="form.a" placeholder="请选择"> <el-select v-model="form.dataMode" placeholder="请选择">
<el-option label="模型一" :value="null" /> <el-option
<el-option label="模型二" :value="1" /> v-for="(dataMode, index) in dataModelList"
:key="index"
:label="dataMode.name"
:value="dataMode.id"
/>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="时间轴:"> <el-form-item label="时间轴:">
...@@ -34,7 +46,7 @@ ...@@ -34,7 +46,7 @@
/> />
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary">查询</el-button> <el-button type="primary" @click="queryData">查询</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-card> </el-card>
...@@ -71,30 +83,202 @@ ...@@ -71,30 +83,202 @@
</descriptions> </descriptions>
</el-card> </el-card>
<el-card class="margin-top-20"> <el-card class="margin-top-20">
<el-tabs v-model="secondActiveName"> <div v-if="!propertyList.length" slot="header" class="clearfix">
<el-tab-pane label="温度:" name="first"> <span>图表</span>
<div style="width: 100%;height: 400px;background: #0a76a4;margin-bottom: 20px"></div> </div>
</el-tab-pane> <el-tabs v-model="activeProperty">
<el-tab-pane label="湿度" name="second"> <el-tab-pane
<div style="width: 100%;height: 400px;background: #4ab7bd;margin-bottom: 20px"></div> v-for="(property, index) in propertyList"
</el-tab-pane> :key="index"
:label="property.propertyName"
:name="property.propertyCode"
/>
</el-tabs> </el-tabs>
<e-line
v-if="propertyList.length"
:id="'line-' + property.propertyCode"
:title="property.propertyName"
:line-data="property.data"
:description="property.propertyUnit"
format="MM-DD HH:mm:ss"
/>
<div v-else class="el-table__empty-text" style="text-align: center;margin: 0 auto">暂无数据</div>
</el-card> </el-card>
</div> </div>
</template> </template>
<script> <script>
import { getAllDeviceModel } from '@/api/equipment-management/equipment-instance'
import { getAllInstanceByDeviceTypeId } from '@/api/equipment-management/equipment-model'
import { getDataModelByDeviceTypeId } from '@/api/equipment-management/equipment-model'
import { getModelInstanceChart } from '@/api/device-management/device-monitoring'
import ELine from '@/components/Charts/ELine'
export default { export default {
name: 'DeviceDetail', name: 'DeviceDetail',
components: {
ELine
},
data() { data() {
return { return {
form: { form: {
a: null, deviceType: null,
c: [], deviceInstance: null,
dataMode: null,
refresh: 1 refresh: 1
}, },
activeName: 'first', property: {
secondActiveName: 'first' propertyCode: null,
propertyName: null,
propertyUnit: null,
data: []
},
rules: {
deviceType: [
{ required: true, message: '', trigger: 'blur' }
],
deviceInstance: [
{ required: true, message: '', trigger: 'blur' }
],
dataMode: [
{ required: true, message: '', trigger: 'blur' }
]
},
deviceInstanceList: [],
dataModelList: [],
propertyList: [],
activeProperty: null,
deviceTypeList: [],
tableData: [],
timer: 0
}
},
watch: {
activeProperty(newVal) {
if (newVal !== null) {
const property = this.propertyList.find(v => v.propertyCode === newVal)
if (property) {
const { propertyCode, propertyName, propertyUnit } = property
this.property = {
propertyCode,
propertyName,
propertyUnit,
data: [...this.getChartData(this.activeProperty)]
}
}
} else {
this.propertyList = []
}
},
form: {
deep: true,
handler: function() {
this.$refs.form.clearValidate()
}
}
},
created() {
this.timer && clearInterval(this.timer)
this.init()
},
beforeDestroy() {
this.timer && clearInterval(this.timer)
},
methods: {
async init() {
// 获取所有设备类型
const deviceTypeList = await getAllDeviceModel()
this.deviceTypeList = deviceTypeList.data
if (this.deviceTypeList.length) {
this.form.deviceType = this.deviceTypeList[0].id
}
// 获取该设备类型下的设备实例
const deviceInstanceList = await getAllInstanceByDeviceTypeId({ deviceTypeId: this.form.deviceType })
this.deviceInstanceList = deviceInstanceList.data
if (this.deviceInstanceList.length) {
this.form.deviceInstance = this.deviceInstanceList[0].id
}
// 根据设备类型 ID 获取关联数据模型
const dataModelList = await getDataModelByDeviceTypeId({ id: this.form.deviceType })
this.dataModelList = dataModelList.data
if (this.dataModelList.length) {
this.form.dataMode = this.dataModelList[0].id
this.propertyList = this.dataModelList[0].propertyList
if (this.propertyList.length) {
this.activeProperty = this.propertyList[0].propertyCode
}
}
// // 查询图表数据
await this.queryData()
return {}
},
queryData() {
this.$refs.form.validate()
.then(_ => {
const index = this.dataModelList.findIndex(i => i.id === this.form.dataMode)
this.propertyList = [...this.dataModelList[index].propertyList]
if (this.propertyList.length) {
this.activeProperty = this.propertyList[0].propertyCode
}
return [{
modelId: this.form.dataMode,
deviceId: this.form.deviceInstance,
propertyCodeList: this.propertyList.map(v => v.propertyCode)
}]
})
.then(params => getModelInstanceChart(params))
.then(res => {
this.tableData = res.data[0].dataList
this.property.data = [...this.getChartData(this.activeProperty)]
return [{
modelId: this.form.dataMode,
deviceId: this.form.deviceInstance,
propertyCodeList: this.propertyList.map(v => v.propertyCode)
}]
})
.then(params => {
this.timer && clearInterval(this.timer)
this.timer = setInterval(async() => {
const chartData = await getModelInstanceChart(params)
this.tableData = chartData.data[0].dataList
this.property.data = [...this.getChartData(this.activeProperty)]
}, this.form.refresh * 1000)
})
.catch(_ => {})
},
onDeviceTypeChange(val) {
this.form.deviceInstance = null
this.form.dataMode = null
this.getAllInstanceByDeviceTypeId(val)
this.getDataModelByDeviceTypeId(val)
},
getChartData(propertyCode) {
return this.tableData.map(v => {
return {
time: v.time,
value: v[propertyCode]
}
})
},
getAllInstanceByDeviceTypeId(val) {
getAllInstanceByDeviceTypeId({ deviceTypeId: val })
.then(res => {
this.deviceInstanceList = res.data
if (this.deviceInstanceList.length) {
this.form.deviceInstance = this.deviceInstanceList[0].id
}
})
.catch(_ => {})
},
getDataModelByDeviceTypeId(id) {
getDataModelByDeviceTypeId({ id })
.then(res => {
this.dataModelList = res.data
if (this.dataModelList.length) {
this.form.dataMode = this.dataModelList[0].id
}
})
.catch(_ => {})
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment