Commit 3e9e3014 authored by pangjh's avatar pangjh

Merge remote-tracking branch 'origin/master'

parents 13149244 980e8162
...@@ -20,6 +20,10 @@ export default { ...@@ -20,6 +20,10 @@ export default {
title: { title: {
type: String, type: String,
default: 'line' default: 'line'
},
description: {
type: String,
default: ''
} }
}, },
data() { data() {
...@@ -40,16 +44,34 @@ export default { ...@@ -40,16 +44,34 @@ export default {
visible: true, visible: true,
text: this.title text: this.title
}, },
description: {
visible: true,
text: '用平滑的曲线代替折线'
},
xField: 'time', xField: 'time',
yField: 'value', yField: 'value',
xAxis: { xAxis: {
type: 'time', type: 'time',
mask: 'HH:mm:ss' mask: 'HH:mm:ss'
},
tooltip: {
visible: true,
shared: true,
showCrosshairs: true,
crosshairs: {
type: 'y'
},
offset: 20
},
description: {
visible: true,
text: `单位为: ${this.description}`
},
guideLine: [
{
type: 'mean',
lineStyle: {},
text: {
content: '中位数'
}
} }
]
}) })
this.line.render() this.line.render()
} }
......
...@@ -13,13 +13,15 @@ ...@@ -13,13 +13,15 @@
> >
<div v-if="activeModel === model.id.toString()"> <div v-if="activeModel === model.id.toString()">
<el-form <el-form
:ref="'form'+activeModel"
:model="chartField" :model="chartField"
inline inline
label-width="100px" label-width="100px"
style="margin-top: 20px" style="margin-top: 20px"
:rules="rules"
> >
<div> <div>
<el-form-item label="选择实例:"> <el-form-item label="选择实例:" prop="instanceId">
<el-radio-group v-model="chartField.instanceId"> <el-radio-group v-model="chartField.instanceId">
<el-radio <el-radio
v-for="(ins, index) in instanceList" v-for="(ins, index) in instanceList"
...@@ -30,7 +32,7 @@ ...@@ -30,7 +32,7 @@
</el-form-item> </el-form-item>
</div> </div>
<div> <div>
<el-form-item label="Y轴:"> <el-form-item label="Y轴:" prop="yFields">
<el-checkbox-group v-model="chartField.yFields"> <el-checkbox-group v-model="chartField.yFields">
<el-checkbox <el-checkbox
v-for="(prop, i) in propertyList" v-for="(prop, i) in propertyList"
...@@ -64,15 +66,16 @@ ...@@ -64,15 +66,16 @@
</el-form> </el-form>
<el-row :gutter="20"> <el-row :gutter="20">
<el-col <el-col
v-for="(chart, index) in charts" v-for="(chart, index) in chartList"
:key="100 + index" :key="100 + index"
:span="12" :span="12"
style="height: 400px" style="height: 400px"
> >
<g2-line <g2-line
:id="'line-' + index" :id="'line-' + index"
:title="chart" :title="chart.propertyName"
:line-data="setChartData(chart)" :line-data="setChartData(chart.propertyCode)"
:description="chart.propertyUnit"
style="min-width: 500px;height: 400px" style="min-width: 500px;height: 400px"
/> />
</el-col> </el-col>
...@@ -102,13 +105,20 @@ export default { ...@@ -102,13 +105,20 @@ export default {
activeModel: null, activeModel: null,
modelList: [], modelList: [],
objectId: '1', objectId: '1',
lineData: [],
chartData: [],
timer: 0, timer: 0,
count: 0, count: 0,
instanceList: [], instanceList: [],
propertyList: [], propertyList: [],
charts: [] chartData: [],
chartList: [],
rules: {
instanceId: [
{ required: true, message: '请选择实例', trigger: 'change' }
],
yFields: [
{ type: 'array', required: true, message: '请至少选择一个属性', trigger: 'change' }
]
}
} }
}, },
created() { created() {
...@@ -122,24 +132,16 @@ export default { ...@@ -122,24 +132,16 @@ export default {
}) })
.catch(err => console.error(err)) .catch(err => console.error(err))
}, },
mounted() {
// this.timer = setInterval(() => {
// this.chartData.push({
// time: new Date().getTime(),
// value: {
// power: this.random(100, 120),
// temperature: this.random(20, 30),
// humidity: this.random(200, 300)
// }
// })
// this.count++
// }, this.chartField.refresh * 1000)
},
beforeDestroy() { beforeDestroy() {
clearInterval(this.timer) clearInterval(this.timer)
}, },
methods: { methods: {
onTabClick() { onTabClick() {
this.chartField = {
instanceId: null,
yFields: [],
refresh: 1
}
this.getDetail(parseInt(this.activeModel)) this.getDetail(parseInt(this.activeModel))
}, },
getDetail(id) { getDetail(id) {
...@@ -162,7 +164,38 @@ export default { ...@@ -162,7 +164,38 @@ export default {
} }
}) })
}, },
createCharts() {} createCharts() {
const form = `form${this.activeModel}`
this.$refs[form][0].validate()
.then(_ => {
this.chartList = this.chartField.yFields.map(v => {
const prop = this.propertyList.find(item => item.id === v)
return {
...prop
}
})
this.chartData = []
this.timer && clearInterval(this.timer)
this.timer = setInterval(async() => {
await this.mockData()
this.count++
}, this.chartField.refresh * 1000)
})
.catch(err => console.error(err))
},
mockData() {
return new Promise(resolve => {
// this.chartData.pop()
this.chartData.push({
time: new Date().getTime(),
value: {
inpressure: this.random(100, 120),
outpressure: this.random(20, 30)
}
})
resolve()
})
}
} }
} }
</script> </script>
......
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