Commit ee184c90 authored by wends's avatar wends

update 仪表盘

parent 768eb0e8
...@@ -36,3 +36,12 @@ export function getModelInstanceChart(data) { ...@@ -36,3 +36,12 @@ export function getModelInstanceChart(data) {
data data
}) })
} }
// 根据设备类型ID获取所有设备实例
export function getAllInstanceByDeviceTypeId(data) {
return request({
url: `${baseURL}/iot/deviceModel/instance/getInstanceByDeviceTypeId`,
method: 'post',
data
})
}
...@@ -4,9 +4,13 @@ ...@@ -4,9 +4,13 @@
<el-col :xs="8" :sm="8" :md="6" :lg="4"> <el-col :xs="8" :sm="8" :md="6" :lg="4">
<div class="left"> <div class="left">
<div class="search"> <div class="search">
<el-select v-model="eModel" style="width: 100%"> <el-select
v-model="deviceType"
style="width: 100%"
@change="onDeviceTypeChange"
>
<el-option <el-option
v-for="item in eModelList" v-for="item in deviceTypeList"
:key="item.value" :key="item.value"
:label="item.label" :label="item.label"
:value="item.value" :value="item.value"
...@@ -17,42 +21,38 @@ ...@@ -17,42 +21,38 @@
<div class="custom-menu"> <div class="custom-menu">
<el-menu <el-menu
ref="customMenu" ref="customMenu"
default-active="1" :default-active="defaultActive"
@select="onInstanceSelect"
> >
<el-menu-item <el-menu-item
v-for="(model, index) in eInstanceList" v-for="(instance, index) in deviceInstanceList"
:key="'model' + index" :id="'instance' + instance.id"
:index="model.id.toString()" :key="'instance' + index"
>{{ model.name }}</el-menu-item> :index="instance.id.toString()"
:class="'instance' + instance.id"
>{{ instance.name }}</el-menu-item>
</el-menu> </el-menu>
</div> </div>
</div> </div>
</el-col> </el-col>
<el-col :xs="16" :sm="16" :md="18" :lg="20"> <el-col :xs="16" :sm="16" :md="18" :lg="20">
<el-form <el-form
:ref="'form'+activeModel" ref="form"
:model="chartField" :model="chartField"
inline inline
label-width="100px" label-width="100px"
style="margin-top: 20px" style="margin-top: 20px"
:rules="rules"
> >
<div> <div v-if="dataModelList.length">
<el-form-item label="选择实例:" prop="instanceId"> <el-form-item
<el-radio-group v-model="chartField.instanceId"> v-for="(dataModel, index) in dataModelList"
<el-radio :key="index + 300"
v-for="(ins, index) in instanceList" :label='dataModel.name + ":"'
:key="300 + index" prop="yFields"
:label="ins.id" >
>{{ ins.instanceName }}</el-radio> <el-checkbox-group v-model="chartField.yFields[index]">
</el-radio-group>
</el-form-item>
</div>
<div>
<el-form-item label="Y轴:" prop="yFields">
<el-checkbox-group v-model="chartField.yFields">
<el-checkbox <el-checkbox
v-for="(prop, i) in propertyList" v-for="(prop, i) in dataModel.propertyList"
:key="200+i" :key="200+i"
:label="prop.propertyCode" :label="prop.propertyCode"
>{{ prop.propertyName }}</el-checkbox> >{{ prop.propertyName }}</el-checkbox>
...@@ -81,9 +81,13 @@ ...@@ -81,9 +81,13 @@
</el-form-item> </el-form-item>
</div> </div>
</el-form> </el-form>
<el-row :gutter="20"> <el-row
v-for="(chartGroup, index) in chartList"
:key="index + 1000"
:gutter="20"
>
<el-col <el-col
v-for="(chart) in chartList" v-for="(chart) in chartGroup"
:key="chart.id" :key="chart.id"
:span="12" :span="12"
style="height: 400px" style="height: 400px"
...@@ -91,7 +95,7 @@ ...@@ -91,7 +95,7 @@
<e-line <e-line
:id="'line-' + chart.propertyCode" :id="'line-' + chart.propertyCode"
:title="chart.propertyName" :title="chart.propertyName"
:line-data="setChartData(chart.propertyCode)" :line-data="setChartData(chart.propertyCode, index)"
:description="chart.propertyUnit" :description="chart.propertyUnit"
></e-line> ></e-line>
</el-col> </el-col>
...@@ -103,7 +107,10 @@ ...@@ -103,7 +107,10 @@
<script> <script>
import ELine from '@/components/Charts/ELine' import ELine from '@/components/Charts/ELine'
import { getAllModel, getModelDetail, getModelInstanceList, getModelInstanceChart } from '@/api/data-visible/dashboard' import { getModelInstanceChart } from '@/api/data-visible/dashboard'
import { getAllDeviceModel } from '@/api/equipment-management/equipment-instance'
import { getAllInstanceByDeviceTypeId } from '@/api/data-visible/dashboard'
import { getDataModelByDeviceTypeId } from '@/api/equipment-management/equipment-model'
export default { export default {
name: 'Dashboard', name: 'Dashboard',
...@@ -113,46 +120,21 @@ export default { ...@@ -113,46 +120,21 @@ export default {
data() { data() {
return { return {
chartField: { chartField: {
instanceId: null,
yFields: [], yFields: [],
refresh: 1 refresh: 1
}, },
activeModel: null, dataModelList: [],
deviceInstance: null,
modelList: [], modelList: [],
objectId: '1', objectId: '1',
defaultActive: null,
timer: 0, timer: 0,
count: 0, count: 0,
instanceList: [], instanceList: [],
propertyList: [], propertyList: [],
eModel: 1, deviceType: null,
eModelList: [ deviceTypeList: [],
{ deviceInstanceList: [],
value: 1,
label: '设备模型一'
},
{
value: 2,
label: '设备模型二'
}
],
eInstanceList: [
{
id: 1,
name: '设备实例一'
},
{
id: 2,
name: '设备实例二'
},
{
id: 3,
name: '设备实例三'
},
{
id: 4,
name: '设备实例四'
}
],
chartData: [], chartData: [],
chartList: [], chartList: [],
rules: { rules: {
...@@ -166,44 +148,81 @@ export default { ...@@ -166,44 +148,81 @@ export default {
} }
}, },
created() { created() {
getAllModel() // 初始化设备类型
getAllDeviceModel()
.then(res => { .then(res => {
this.modelList = res.data this.deviceTypeList = res.data.map(v => {
if (this.modelList.length > 0) { return {
this.activeModel = this.modelList[0].id.toString() value: v.id,
this.getDetail(parseInt(this.activeModel)) label: v.name
} }
}) })
.catch(err => console.error(err)) if (this.deviceTypeList.length) {
this.deviceType = this.deviceTypeList[0].value
// 获取该设备类型下的设备实例
this.getAllInstanceByDeviceTypeId(this.deviceType)
// 根据设备类型 ID 获取关联数据模型
this.getDataModelByDeviceTypeId(this.deviceType)
}
})
.catch(_ => {})
}, },
beforeDestroy() { beforeDestroy() {
clearInterval(this.timer) clearInterval(this.timer)
}, },
methods: { methods: {
onTabClick() { onDeviceTypeChange(val) {
this.dataModelList = []
this.chartField = { this.chartField = {
instanceId: null,
yFields: [], yFields: [],
refresh: 1 refresh: 1
} }
this.getDetail(parseInt(this.activeModel))
this.chartList = [] this.chartList = []
this.chartData = []
clearInterval(this.timer) clearInterval(this.timer)
this.getDataModelByDeviceTypeId(val)
this.getAllInstanceByDeviceTypeId(val)
},
onInstanceSelect(index) {
const id = parseInt(index)
const instance = this.deviceInstanceList.find(v => v.id === id)
this.deviceInstance = instance.id
},
getDataModelByDeviceTypeId(id) {
getDataModelByDeviceTypeId({ id })
.then(res => {
this.dataModelList = res.data
this.chartField.yFields = []
this.dataModelList.forEach(v => {
this.chartField.yFields.push([])
})
})
.catch(_ => {})
}, },
getDetail(id) { getAllInstanceByDeviceTypeId(val) {
Promise.all([getModelInstanceList({ id }), getModelDetail({ id })]) getAllInstanceByDeviceTypeId({ deviceTypeId: val })
.then(res => { .then(res => {
const [res1, res2] = res this.deviceInstanceList = res.data
this.instanceList = res1.data this.$nextTick()
this.propertyList = res2.data.propertyList .then(_ => {
if (this.deviceInstanceList.length) {
this.defaultActive = this.deviceInstanceList[0].id.toString()
this.deviceInstance = this.deviceInstanceList[0].id
this.$nextTick()
.then(_ => {
document.getElementById(`instance${this.deviceInstanceList[0].id}`).click()
}) })
.catch(err => console.error(err)) .catch(_ => {})
}
})
})
.catch(_ => {})
}, },
random(m, n) { random(m, n) {
return Math.round(Math.random() * (m - n) + n) return Math.round(Math.random() * (m - n) + n)
}, },
setChartData(yField) { setChartData(yField, index) {
return this.chartData.map(v => { return this.chartData[index].map(v => {
return { return {
time: v.time, time: v.time,
value: parseInt(v[yField]) value: parseInt(v[yField])
...@@ -211,41 +230,60 @@ export default { ...@@ -211,41 +230,60 @@ export default {
}) })
}, },
createCharts() { createCharts() {
const form = `form${this.activeModel}` // eslint-disable-next-line no-unused-vars
this.$refs[form].validate() let count = 0
.then(_ => { this.chartField.yFields.forEach(v => {
if (v.length) {
count += v.length
}
})
if (count > 0) {
const params = this.dataModelList.map((v, i) => {
return {
modelId: v.id,
deviceId: this.deviceInstance,
propertyCodeList: [...this.chartField.yFields[i]]
}
})
this.chartData = [] this.chartData = []
this.chartList = [] this.chartList = []
const params = {
modelId: parseInt(this.activeModel),
instanceId: this.chartField.instanceId,
propertyCodeList: [...this.chartField.yFields]
}
getModelInstanceChart(params) getModelInstanceChart(params)
.then(res => { .then(res => {
this.chartData = res.data.sort((a, b) => { this.chartData = res.data.map(v => {
const data = v.dataList.sort((a, b) => {
return (a > b) ? 1 : -1 return (a > b) ? 1 : -1
}) })
return [...data]
})
this.dataModelList.forEach((dataModel, i) => {
const arr = [] const arr = []
this.propertyList.forEach(v => { dataModel.propertyList.forEach(v => {
const index = this.chartField.yFields.findIndex(item => item === v.propertyCode) const index = this.chartField.yFields[i].findIndex(item => item === v.propertyCode)
index !== -1 && arr.push({ ...v }) index !== -1 && arr.push({ ...v })
}) })
this.chartList = [...arr] this.chartList.push(arr)
})
}) })
.then(_ => { .then(_ => {
this.timer && clearInterval(this.timer) this.timer && clearInterval(this.timer)
this.timer = setInterval(async() => { this.timer = setInterval(async() => {
const chartData = await getModelInstanceChart(params) const chartData = await getModelInstanceChart(params)
this.chartData = chartData.data.sort((a, b) => { // this.chartData = chartData.data.sort((a, b) => {
// return (a > b) ? 1 : -1
// })
this.chartData = chartData.data.map(v => {
const data = v.dataList.sort((a, b) => {
return (a > b) ? 1 : -1 return (a > b) ? 1 : -1
}) })
return [...data]
})
this.count++ this.count++
}, this.chartField.refresh * 1000) }, this.chartField.refresh * 1000)
}) })
.catch(_ => {}) .catch(_ => {})
}) } else {
.catch(err => console.error(err)) this.$message.warning('请至少选择 1 个属性')
}
} }
} }
} }
......
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