Commit 08bf4d1f authored by huangcb's avatar huangcb

Merge branch 'master' into huangcb

parents 8de7a15e 681007cc
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
"driver.js": "0.9.5", "driver.js": "0.9.5",
"echarts": "4.2.1", "echarts": "4.2.1",
"element-ui": "2.13.0", "element-ui": "2.13.0",
"file-saver": "^2.0.2",
"fuse.js": "^3.6.1", "fuse.js": "^3.6.1",
"js-cookie": "2.2.0", "js-cookie": "2.2.0",
"jsoneditor": "^9.0.3", "jsoneditor": "^9.0.3",
......
...@@ -3,7 +3,7 @@ import Common from '@/layout/common/index' ...@@ -3,7 +3,7 @@ import Common from '@/layout/common/index'
const router = { const router = {
menuId: 'DeviceMgr', menuId: 'DeviceMgr',
path: '/device-management', path: '/device-management',
name: '设备实例', name: '实例管理',
component: Common, component: Common,
redirect: '/device-management/device-instance', redirect: '/device-management/device-instance',
meta: { title: '设备实例', icon: 'equipment-instance' }, meta: { title: '设备实例', icon: 'equipment-instance' },
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
v-for="(property, index) in propertyList" v-for="(property, index) in propertyList"
:key="index" :key="index"
:label="property.propertyName" :label="property.propertyName"
:value="`${property.propertyValue} ${property.propertyUnit}`" :value="formatProperty(property)"
/> />
</descriptions> </descriptions>
</el-tab-pane> </el-tab-pane>
...@@ -135,17 +135,37 @@ export default { ...@@ -135,17 +135,37 @@ export default {
}, },
created() { created() {
const { deviceTypeId, deviceInstanceId } = this.$route.query const { deviceTypeId, deviceInstanceId } = this.$route.query
getAllDeviceModel() // getAllDeviceModel()
.then(res => { // .then(res => {
this.deviceTypeList = res.data // this.deviceTypeList = res.data
this.form.deviceType = deviceTypeId || (this.deviceTypeList.length ? this.deviceTypeList[0].id : null) // this.form.deviceType = deviceTypeId || (this.deviceTypeList.length ? this.deviceTypeList[0].id : null)
this.getAllInstanceByDeviceTypeId(this.form.deviceType, deviceInstanceId) // this.getAllInstanceByDeviceTypeId(this.form.deviceType, deviceInstanceId)
this.getDataModelByDeviceTypeId(this.form.deviceType) // this.getDataModelByDeviceTypeId(this.form.deviceType)
this.getDeviceInstanceDetail(this.form.deviceType) // this.getDeviceInstanceDetail(this.form.deviceType)
}) // })
.catch(_ => {}) // .catch(_ => {})
this.init(deviceTypeId, deviceInstanceId)
}, },
methods: { 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() { onTabClick() {
const dataModel = this.dataModelList.find(v => v.name === this.activeDataModel) const dataModel = this.dataModelList.find(v => v.name === this.activeDataModel)
this.getPropertyDetail(dataModel.id, this.form.deviceInstance) this.getPropertyDetail(dataModel.id, this.form.deviceInstance)
...@@ -187,7 +207,6 @@ export default { ...@@ -187,7 +207,6 @@ export default {
this.dataModelList = res.data this.dataModelList = res.data
if (this.dataModelList.length) { if (this.dataModelList.length) {
this.activeDataModel = this.dataModelList[0].name this.activeDataModel = this.dataModelList[0].name
this.getPropertyDetail(this.dataModelList[0].id, this.form.deviceInstance)
} }
}) })
.catch(_ => {}) .catch(_ => {})
...@@ -195,13 +214,14 @@ export default { ...@@ -195,13 +214,14 @@ export default {
getPropertyDetail(dataModelId, deviceId) { getPropertyDetail(dataModelId, deviceId) {
getPropertyDetail({ dataModelId, deviceId }) getPropertyDetail({ dataModelId, deviceId })
.then(res => { .then(res => {
this.propertyList = res.data.propertyList this.propertyList = res.data.propertyList.length ? res.data.propertyList : []
}) })
.catch(_ => {}) .catch(_ => {})
}, },
queryData() { queryData() {
this.getDataModelByDeviceTypeId(this.form.deviceType) this.getDataModelByDeviceTypeId(this.form.deviceType)
this.getDeviceInstanceDetail(this.form.deviceType) this.getDeviceInstanceDetail(this.form.deviceType)
this.getPropertyDetail(this.dataModelList[0].id, this.form.deviceInstance)
} }
} }
} }
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" @click="queryData">查询</el-button> <el-button type="primary" @click="queryData">查询</el-button>
<el-button v-if="false" @click="clearIntervalT">clear</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-card> </el-card>
...@@ -74,7 +75,7 @@ ...@@ -74,7 +75,7 @@
v-for="(property, index) in dataModelDetail" v-for="(property, index) in dataModelDetail"
:key="index" :key="index"
:label="property.propertyName" :label="property.propertyName"
:value="`${property.propertyValue} ${property.propertyUnit}`" :value="formatProperty(property)"
/> />
</el-card> </el-card>
<el-card class="margin-top-20"> <el-card class="margin-top-20">
...@@ -195,6 +196,9 @@ export default { ...@@ -195,6 +196,9 @@ export default {
this.timer && clearInterval(this.timer) this.timer && clearInterval(this.timer)
}, },
methods: { methods: {
clearIntervalT() {
this.timer && clearInterval(this.timer)
},
async init(deviceTypeId, deviceInstanceId) { async init(deviceTypeId, deviceInstanceId) {
// 获取所有设备类型 // 获取所有设备类型
const deviceTypeList = await getAllDeviceModel() const deviceTypeList = await getAllDeviceModel()
...@@ -243,15 +247,19 @@ export default { ...@@ -243,15 +247,19 @@ export default {
}] }]
}) })
.then(params => { .then(params => {
const { dataMode, deviceInstance } = this.form
this.timer && clearInterval(this.timer) this.timer && clearInterval(this.timer)
this.timer = setInterval(async() => { this.timer = setInterval(async() => {
await this.getPropertyDetail(this.form.dataMode, this.form.deviceInstance) await this.getPropertyDetail(dataMode, deviceInstance)
const chartData = await getModelInstanceChart(params) const chartData = await getModelInstanceChart(params)
this.tableData = chartData.data[0].dataList this.tableData = chartData.data[0].dataList
this.property.data = [...this.getChartData(this.activeProperty)] this.property.data = [...this.getChartData(this.activeProperty)]
}, this.form.refresh * 1000) }, this.form.refresh * 1000)
}) })
.catch(_ => {}) .catch(e => console.error(e))
},
formatProperty(property) {
return property.propertyValue ? `${property.propertyValue} ${property.propertyUnit}` : ''
}, },
getDeviceInstanceDetail(id) { getDeviceInstanceDetail(id) {
getDeviceInstanceDetail({ id }) getDeviceInstanceDetail({ id })
...@@ -270,8 +278,8 @@ export default { ...@@ -270,8 +278,8 @@ export default {
getPropertyDetail(dataModelId, deviceId) { getPropertyDetail(dataModelId, deviceId) {
getPropertyDetail({ dataModelId, deviceId }) getPropertyDetail({ dataModelId, deviceId })
.then(res => { .then(res => {
this.dataModelDetail = res.data.propertyList this.dataModelDetail = res.data.propertyList.length ? res.data.propertyList : []
this.dataModelReportTime = res.data.reportTime this.dataModelReportTime = res.data.reportTime ? res.data.reportTime : null
}) })
.catch(_ => {}) .catch(_ => {})
}, },
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
<el-card class="margin-top-20"> <el-card class="margin-top-20">
<div slot="header" class="clearfix"> <div slot="header" class="clearfix">
<span>详细</span> <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> </div>
<el-table :data="tableDataPaged" border style="width: 100%"> <el-table :data="tableDataPaged" border style="width: 100%">
<el-table-column type="index" label="序号" width="50" /> <el-table-column type="index" label="序号" width="50" />
...@@ -257,6 +257,36 @@ export default { ...@@ -257,6 +257,36 @@ export default {
await this.queryData() await this.queryData()
return {} 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) { getChartData(propertyCode) {
return this.tableData.map(v => { return this.tableData.map(v => {
return { 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