Commit 08bf4d1f authored by huangcb's avatar huangcb

Merge branch 'master' into huangcb

parents 8de7a15e 681007cc
......@@ -3,7 +3,7 @@ import Common from '@/layout/common/index'
const router = {
menuId: 'DeviceMgr',
path: '/device-management',
name: '设备实例',
name: '实例管理',
component: Common,
redirect: '/device-management/device-instance',
meta: { title: '设备实例', icon: 'equipment-instance' },
......
......@@ -73,7 +73,7 @@
v-for="(property, index) in propertyList"
:key="index"
:label="property.propertyName"
:value="`${property.propertyValue} ${property.propertyUnit}`"
:value="formatProperty(property)"
/>
</descriptions>
</el-tab-pane>
......@@ -135,17 +135,37 @@ export default {
},
created() {
const { deviceTypeId, deviceInstanceId } = this.$route.query
getAllDeviceModel()
.then(res => {
this.deviceTypeList = res.data
this.form.deviceType = deviceTypeId || (this.deviceTypeList.length ? this.deviceTypeList[0].id : null)
this.getAllInstanceByDeviceTypeId(this.form.deviceType, deviceInstanceId)
this.getDataModelByDeviceTypeId(this.form.deviceType)
this.getDeviceInstanceDetail(this.form.deviceType)
})
.catch(_ => {})
// getAllDeviceModel()
// .then(res => {
// this.deviceTypeList = res.data
// this.form.deviceType = deviceTypeId || (this.deviceTypeList.length ? this.deviceTypeList[0].id : null)
// this.getAllInstanceByDeviceTypeId(this.form.deviceType, deviceInstanceId)
// this.getDataModelByDeviceTypeId(this.form.deviceType)
// this.getDeviceInstanceDetail(this.form.deviceType)
// })
// .catch(_ => {})
this.init(deviceTypeId, deviceInstanceId)
},
methods: {
async init(deviceTypeId, deviceInstanceId) {
const deviceTypeList = await getAllDeviceModel()
this.deviceTypeList = deviceTypeList.data
this.form.deviceType = deviceTypeId || (this.deviceTypeList.length ? this.deviceTypeList[0].id : null)
const deviceInstanceList = await getAllInstanceByDeviceTypeId({ deviceTypeId: this.form.deviceType })
this.deviceInstanceList = deviceInstanceList.data
this.form.deviceInstance = deviceInstanceId || this.deviceInstanceList.length ? this.deviceInstanceList[0].id : null
const dataModelList = await getDataModelByDeviceTypeId({ id: this.form.deviceType })
this.dataModelList = dataModelList.data
this.activeDataModel = this.dataModelList.length ? this.dataModelList[0].name : null
await this.getDeviceInstanceDetail(this.form.deviceType)
await this.getPropertyDetail(this.dataModelList[0].id, this.form.deviceInstance)
return {}
},
formatProperty(property) {
return property.propertyValue ? `${property.propertyValue} ${property.propertyUnit}` : ''
},
onTabClick() {
const dataModel = this.dataModelList.find(v => v.name === this.activeDataModel)
this.getPropertyDetail(dataModel.id, this.form.deviceInstance)
......@@ -187,7 +207,6 @@ export default {
this.dataModelList = res.data
if (this.dataModelList.length) {
this.activeDataModel = this.dataModelList[0].name
this.getPropertyDetail(this.dataModelList[0].id, this.form.deviceInstance)
}
})
.catch(_ => {})
......@@ -195,13 +214,14 @@ export default {
getPropertyDetail(dataModelId, deviceId) {
getPropertyDetail({ dataModelId, deviceId })
.then(res => {
this.propertyList = res.data.propertyList
this.propertyList = res.data.propertyList.length ? res.data.propertyList : []
})
.catch(_ => {})
},
queryData() {
this.getDataModelByDeviceTypeId(this.form.deviceType)
this.getDeviceInstanceDetail(this.form.deviceType)
this.getPropertyDetail(this.dataModelList[0].id, this.form.deviceInstance)
}
}
}
......
......@@ -47,6 +47,7 @@
</el-form-item>
<el-form-item>
<el-button type="primary" @click="queryData">查询</el-button>
<el-button v-if="false" @click="clearIntervalT">clear</el-button>
</el-form-item>
</el-form>
</el-card>
......@@ -74,7 +75,7 @@
v-for="(property, index) in dataModelDetail"
:key="index"
:label="property.propertyName"
:value="`${property.propertyValue} ${property.propertyUnit}`"
:value="formatProperty(property)"
/>
</el-card>
<el-card class="margin-top-20">
......@@ -195,6 +196,9 @@ export default {
this.timer && clearInterval(this.timer)
},
methods: {
clearIntervalT() {
this.timer && clearInterval(this.timer)
},
async init(deviceTypeId, deviceInstanceId) {
// 获取所有设备类型
const deviceTypeList = await getAllDeviceModel()
......@@ -243,15 +247,19 @@ export default {
}]
})
.then(params => {
const { dataMode, deviceInstance } = this.form
this.timer && clearInterval(this.timer)
this.timer = setInterval(async() => {
await this.getPropertyDetail(this.form.dataMode, this.form.deviceInstance)
await this.getPropertyDetail(dataMode, deviceInstance)
const chartData = await getModelInstanceChart(params)
this.tableData = chartData.data[0].dataList
this.property.data = [...this.getChartData(this.activeProperty)]
}, this.form.refresh * 1000)
})
.catch(_ => {})
.catch(e => console.error(e))
},
formatProperty(property) {
return property.propertyValue ? `${property.propertyValue} ${property.propertyUnit}` : ''
},
getDeviceInstanceDetail(id) {
getDeviceInstanceDetail({ id })
......@@ -270,8 +278,8 @@ export default {
getPropertyDetail(dataModelId, deviceId) {
getPropertyDetail({ dataModelId, deviceId })
.then(res => {
this.dataModelDetail = res.data.propertyList
this.dataModelReportTime = res.data.reportTime
this.dataModelDetail = res.data.propertyList.length ? res.data.propertyList : []
this.dataModelReportTime = res.data.reportTime ? res.data.reportTime : null
})
.catch(_ => {})
},
......
......@@ -73,7 +73,7 @@
<el-card class="margin-top-20">
<div slot="header" class="clearfix">
<span>详细</span>
<el-button style="float: right; padding: 3px 0" type="text">导出</el-button>
<el-button style="float: right; padding: 3px 0" type="text" @click="handleDownload">导出</el-button>
</div>
<el-table :data="tableDataPaged" border style="width: 100%">
<el-table-column type="index" label="序号" width="50" />
......@@ -257,6 +257,36 @@ export default {
await this.queryData()
return {}
},
formatJson(filterVal, jsonData) {
return jsonData.map(v => filterVal.map(j => {
if (j === 'time') {
return this.$moment(v[j], 'YYYY-MM-DD HH:mm:ss')
} else {
return v[j]
}
}))
},
handleDownload() {
this.downloadLoading = true
import('@/vendor/Export2Excel').then(excel => {
const tHeader = []
const filterVal = []
for (const key in this.tableDataPaged[0]) {
tHeader.push(key)
filterVal.push(key)
}
const list = this.tableData
const data = this.formatJson(filterVal, list)
excel.export_json_to_excel({
header: tHeader,
data,
filename: this.filename,
autoWidth: this.autoWidth,
bookType: this.bookType
})
this.downloadLoading = false
})
},
getChartData(propertyCode) {
return this.tableData.map(v => {
return {
......
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