|
@@ -3,37 +3,43 @@
|
|
|
<div class="l-flex--row l-flex__none">
|
|
<div class="l-flex--row l-flex__none">
|
|
|
<i
|
|
<i
|
|
|
class="l-flex__none c-sibling-item o-icon"
|
|
class="l-flex__none c-sibling-item o-icon"
|
|
|
- :class="type"
|
|
|
|
|
|
|
+ :class="sensorType"
|
|
|
/>
|
|
/>
|
|
|
<span class="l-flex__fill c-sibling-item near u-color--info u-ellipsis">{{ title }}</span>
|
|
<span class="l-flex__fill c-sibling-item near u-color--info u-ellipsis">{{ title }}</span>
|
|
|
<i
|
|
<i
|
|
|
v-if="enough"
|
|
v-if="enough"
|
|
|
- class="l-flex__none u-font-size--md u-color--blue el-icon-s-operation u-pointer"
|
|
|
|
|
|
|
+ class="l-flex__none c-sibling-item u-font-size--md u-color--blue el-icon-s-operation has-active"
|
|
|
@click="onShowAll"
|
|
@click="onShowAll"
|
|
|
/>
|
|
/>
|
|
|
</div>
|
|
</div>
|
|
|
<div class="l-flex__fill l-flex--row center u-font-size--md u-color--black u-bold">
|
|
<div class="l-flex__fill l-flex--row center u-font-size--md u-color--black u-bold">
|
|
|
<div
|
|
<div
|
|
|
class="u-text--center"
|
|
class="u-text--center"
|
|
|
- :style="{ color: tipColor }"
|
|
|
|
|
|
|
+ :style="{ color }"
|
|
|
>
|
|
>
|
|
|
- {{ tip }}
|
|
|
|
|
- <div
|
|
|
|
|
- v-if="sensor"
|
|
|
|
|
- class="o-sensor__current"
|
|
|
|
|
- >
|
|
|
|
|
- {{ sensor }}
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <template v-if="sensor">
|
|
|
|
|
+ {{ tip }}
|
|
|
|
|
+ <div class="o-sensor__current">
|
|
|
|
|
+ {{ sensor }}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ <i
|
|
|
|
|
+ v-else-if="loading"
|
|
|
|
|
+ class="el-icon-loading"
|
|
|
|
|
+ />
|
|
|
|
|
+ <template v-else>
|
|
|
|
|
+ 未知
|
|
|
|
|
+ </template>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<div
|
|
<div
|
|
|
v-for="item in more"
|
|
v-for="item in more"
|
|
|
- :key="item.key"
|
|
|
|
|
|
|
+ :key="item.port"
|
|
|
class="l-flex__none l-flex--row o-sensor__more"
|
|
class="l-flex__none l-flex--row o-sensor__more"
|
|
|
>
|
|
>
|
|
|
<div class="l-flex__none">{{ item.time }}</div>
|
|
<div class="l-flex__none">{{ item.time }}</div>
|
|
|
- <div class="l-flex__none o-sensor__name">{{ item.name }}</div>
|
|
|
|
|
- <div class="l-flex__fill u-text--right">{{ item.value }}</div>
|
|
|
|
|
|
|
+ <div class="l-flex__none o-sensor__name">传感器{{ item.port }}</div>
|
|
|
|
|
+ <div class="l-flex__fill u-text--right">{{ item.info }}</div>
|
|
|
</div>
|
|
</div>
|
|
|
<table-dialog
|
|
<table-dialog
|
|
|
ref="tableDialog"
|
|
ref="tableDialog"
|
|
@@ -45,17 +51,18 @@
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
import {
|
|
import {
|
|
|
- Type,
|
|
|
|
|
- addListener,
|
|
|
|
|
- removeListener
|
|
|
|
|
-} from '../../../monitor'
|
|
|
|
|
|
|
+ ThirdPartyDevice,
|
|
|
|
|
+ ThirdPartyDeviceInfo
|
|
|
|
|
+} from '@/constant'
|
|
|
|
|
+import { parseTime } from '@/utils'
|
|
|
|
|
+import { getSensorRecords } from '@/api/external'
|
|
|
|
|
|
|
|
export default {
|
|
export default {
|
|
|
name: 'Sensor',
|
|
name: 'Sensor',
|
|
|
props: {
|
|
props: {
|
|
|
type: {
|
|
type: {
|
|
|
- type: String,
|
|
|
|
|
- default: ''
|
|
|
|
|
|
|
+ type: Number,
|
|
|
|
|
+ required: true
|
|
|
},
|
|
},
|
|
|
title: {
|
|
title: {
|
|
|
type: String,
|
|
type: String,
|
|
@@ -64,17 +71,22 @@ export default {
|
|
|
color: {
|
|
color: {
|
|
|
type: String,
|
|
type: String,
|
|
|
default: ''
|
|
default: ''
|
|
|
|
|
+ },
|
|
|
|
|
+ deviceId: {
|
|
|
|
|
+ type: String,
|
|
|
|
|
+ required: true
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
data () {
|
|
data () {
|
|
|
return {
|
|
return {
|
|
|
|
|
+ loading: false,
|
|
|
list: [],
|
|
list: [],
|
|
|
schema: {
|
|
schema: {
|
|
|
nonPagination: true,
|
|
nonPagination: true,
|
|
|
list: this.getSensors,
|
|
list: this.getSensors,
|
|
|
cols: [
|
|
cols: [
|
|
|
- { prop: 'name', label: '传感器名称' },
|
|
|
|
|
- { prop: 'value', label: this.title },
|
|
|
|
|
|
|
+ { prop: 'port', label: '端口' },
|
|
|
|
|
+ { prop: 'info', label: '数据' },
|
|
|
{ prop: 'time', label: '采集时间' }
|
|
{ prop: 'time', label: '采集时间' }
|
|
|
]
|
|
]
|
|
|
}
|
|
}
|
|
@@ -82,22 +94,23 @@ export default {
|
|
|
},
|
|
},
|
|
|
computed: {
|
|
computed: {
|
|
|
listTitle () {
|
|
listTitle () {
|
|
|
- return `${this.title}传感器详情`
|
|
|
|
|
|
|
+ return ThirdPartyDeviceInfo[this.type]
|
|
|
},
|
|
},
|
|
|
sorted () {
|
|
sorted () {
|
|
|
- return this.list.slice().sort((a, b) => b.sensorValue - a.sensorValue)
|
|
|
|
|
|
|
+ return this.list.slice().sort((a, b) => Number(a.value) < Number(b.value) ? 1 : -1)
|
|
|
},
|
|
},
|
|
|
- tipColor () {
|
|
|
|
|
- return this.list.length ? this.color : ''
|
|
|
|
|
|
|
+ sensorType () {
|
|
|
|
|
+ return `sensor_${this.type}`
|
|
|
},
|
|
},
|
|
|
tip () {
|
|
tip () {
|
|
|
- return this.list.length ? this.sorted[0].value : '未知'
|
|
|
|
|
|
|
+ return this.sorted.length ? this.sorted[0].info : null
|
|
|
},
|
|
},
|
|
|
sensor () {
|
|
sensor () {
|
|
|
- return this.list.length
|
|
|
|
|
- ? this.list.length === 1
|
|
|
|
|
|
|
+ const length = this.sorted.length
|
|
|
|
|
+ return length
|
|
|
|
|
+ ? length === 1
|
|
|
? this.sorted[0].time
|
|
? this.sorted[0].time
|
|
|
- : `${this.sorted[0].time} 传感器${this.sorted[0].key}`
|
|
|
|
|
|
|
+ : `${this.sorted[0].time} 传感器${this.sorted[0].port}`
|
|
|
: null
|
|
: null
|
|
|
},
|
|
},
|
|
|
more () {
|
|
more () {
|
|
@@ -108,15 +121,69 @@ export default {
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
created () {
|
|
created () {
|
|
|
- addListener(this.type, this.onUpdate, { type: Type.CACHE, value: [] })
|
|
|
|
|
|
|
+ this.$running = true
|
|
|
|
|
+ this.$timer = -1
|
|
|
|
|
+ this.startRun()
|
|
|
},
|
|
},
|
|
|
beforeDestroy () {
|
|
beforeDestroy () {
|
|
|
- removeListener(this.type, this.onUpdate)
|
|
|
|
|
|
|
+ this.$running = false
|
|
|
|
|
+ clearTimeout(this.$timer)
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
- onUpdate (list) {
|
|
|
|
|
- this.list = list
|
|
|
|
|
- this.$refs.tableDialog?.getTable()?.pageTo()
|
|
|
|
|
|
|
+ startRun () {
|
|
|
|
|
+ if (!this.$running) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ const now = Date.now()
|
|
|
|
|
+ this.loading = true
|
|
|
|
|
+ getSensorRecords({
|
|
|
|
|
+ deviceId: this.deviceId,
|
|
|
|
|
+ sensorType: this.type,
|
|
|
|
|
+ startTime: parseTime(now - 30000, '{y}-{m}-{d} {h}:{i}:{s}'),
|
|
|
|
|
+ endTime: parseTime(now, '{y}-{m}-{d} {h}:{i}:{s}')
|
|
|
|
|
+ }, { custom: true }).then(({ data }) => {
|
|
|
|
|
+ this.list = this.transfromData(data)
|
|
|
|
|
+ this.$refs.tableDialog?.getTable()?.pageTo()
|
|
|
|
|
+ }).finally(() => {
|
|
|
|
|
+ this.loading = false
|
|
|
|
|
+ if (this.$running) {
|
|
|
|
|
+ this.$timer = setTimeout(this.startRun, 10000)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ transfromData (data) {
|
|
|
|
|
+ const map = {}
|
|
|
|
|
+ const arr = []
|
|
|
|
|
+ data.forEach(sensor => {
|
|
|
|
|
+ if (!map[sensor.port]) {
|
|
|
|
|
+ map[sensor.port] = 1
|
|
|
|
|
+ arr.push(this.transformSensorData(sensor))
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ return arr
|
|
|
|
|
+ },
|
|
|
|
|
+ transformSensorData (data) {
|
|
|
|
|
+ const { port, type, value, time } = data
|
|
|
|
|
+ return {
|
|
|
|
|
+ port,
|
|
|
|
|
+ value,
|
|
|
|
|
+ time,
|
|
|
|
|
+ info: this.transformValue(type, value)
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ transformValue (type, value) {
|
|
|
|
|
+ switch (type) {
|
|
|
|
|
+ case ThirdPartyDevice.SMOKE_SENSOR:
|
|
|
|
|
+ return `${value}ppm`
|
|
|
|
|
+ case ThirdPartyDevice.TEMPERATURE_SENSOR:
|
|
|
|
|
+ return `${value}℃`
|
|
|
|
|
+ case ThirdPartyDevice.LIGHT_SENSOR:
|
|
|
|
|
+ return `${value}Lux`
|
|
|
|
|
+ case ThirdPartyDevice.FLOODING_SENSOR:
|
|
|
|
|
+ return value ? '是' : '否'
|
|
|
|
|
+ default:
|
|
|
|
|
+ return value
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
getSensors () {
|
|
getSensors () {
|
|
|
return Promise.resolve({ data: this.list })
|
|
return Promise.resolve({ data: this.list })
|
|
@@ -130,21 +197,21 @@ export default {
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|
|
|
.o-icon {
|
|
.o-icon {
|
|
|
- &.temperature {
|
|
|
|
|
- background-image: url("~@/assets/icon_temperature.png");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- &.smoke {
|
|
|
|
|
|
|
+ &.sensor_9 {
|
|
|
background-image: url("~@/assets/icon_smoke.png");
|
|
background-image: url("~@/assets/icon_smoke.png");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- &.flooding {
|
|
|
|
|
- background-image: url("~@/assets/icon_flooding.png");
|
|
|
|
|
|
|
+ &.sensor_10 {
|
|
|
|
|
+ background-image: url("~@/assets/icon_temperature.png");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- &.light {
|
|
|
|
|
|
|
+ &.sensor_11 {
|
|
|
background-image: url("~@/assets/icon_light.png");
|
|
background-image: url("~@/assets/icon_light.png");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ &.sensor_12 {
|
|
|
|
|
+ background-image: url("~@/assets/icon_flooding.png");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
.o-sensor {
|
|
.o-sensor {
|