|
|
@@ -0,0 +1,148 @@
|
|
|
+<template>
|
|
|
+ <schema-table
|
|
|
+ ref="table"
|
|
|
+ :schema="schema"
|
|
|
+ >
|
|
|
+ <confirm-dialog
|
|
|
+ ref="editDialog"
|
|
|
+ :title="dialogTitle"
|
|
|
+ :append-to-body="true"
|
|
|
+ @confirm="onConfirm"
|
|
|
+ >
|
|
|
+ <div class="c-grid-form u-align-self--center">
|
|
|
+ <span class="c-grid-form__label required">名称</span>
|
|
|
+ <el-input
|
|
|
+ v-model.trim="sensor.name"
|
|
|
+ placeholder="最多50个字符"
|
|
|
+ maxlength="50"
|
|
|
+ clearable
|
|
|
+ />
|
|
|
+ <span class="c-grid-form__label required">标识</span>
|
|
|
+ <el-input
|
|
|
+ v-model.trim="sensor.identifier"
|
|
|
+ placeholder="最多50个字符"
|
|
|
+ maxlength="50"
|
|
|
+ :disabled="!isAdd"
|
|
|
+ clearable
|
|
|
+ />
|
|
|
+ <span class="c-grid-form__label required">类型</span>
|
|
|
+ <schema-select
|
|
|
+ v-model="sensor.sensorType"
|
|
|
+ :schema="sensorTypeOptionsSchema"
|
|
|
+ :disabled="!isAdd"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </confirm-dialog>
|
|
|
+ </schema-table>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import {
|
|
|
+ getSensors,
|
|
|
+ addSensor,
|
|
|
+ updateSensor,
|
|
|
+ deleteSensor
|
|
|
+} from '@/api/external'
|
|
|
+import { Sensor } from '@/constant'
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'SensorList',
|
|
|
+ props: {
|
|
|
+ gateway: {
|
|
|
+ type: Object,
|
|
|
+ required: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ sensor: {},
|
|
|
+ sensorTypeOptionsSchema: {
|
|
|
+ options: [
|
|
|
+ { value: Sensor.SMOKE, label: '烟雾' },
|
|
|
+ { value: Sensor.TEMPERATURE, label: '温度' },
|
|
|
+ { value: Sensor.LIGHT, label: '光照' },
|
|
|
+ { value: Sensor.FLOODING, label: '水浸' }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ schema: {
|
|
|
+ list: this.getSensors,
|
|
|
+ buttons: [
|
|
|
+ { type: 'add', on: this.onAdd }
|
|
|
+ ],
|
|
|
+ cols: [
|
|
|
+ { prop: 'name', label: '名称' },
|
|
|
+ { prop: 'identifier', label: '标识' },
|
|
|
+ { prop: 'sensorType', label: '类型', render: ({ sensorType }) => ['烟雾', '温度', '光照', '水浸'][sensorType] },
|
|
|
+ { type: 'invoke', render: [
|
|
|
+ { label: '编辑', on: this.onEdit },
|
|
|
+ { label: '删除', on: this.onDel }
|
|
|
+ ] }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ isAdd () {
|
|
|
+ return !this.sensor.id
|
|
|
+ },
|
|
|
+ dialogTitle () {
|
|
|
+ return this.isAdd ? '新增传感器' : '编辑传感器'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ getSensors () {
|
|
|
+ return getSensors(this.gateway.id)
|
|
|
+ },
|
|
|
+ onAdd () {
|
|
|
+ this.sensor = {
|
|
|
+ name: '',
|
|
|
+ identifier: '',
|
|
|
+ sensorType: Sensor.TEMPERATURE
|
|
|
+ }
|
|
|
+ this.$refs.editDialog.show()
|
|
|
+ },
|
|
|
+ onEdit ({ id, gatewayId, name, identifier, sensorType }) {
|
|
|
+ this.sensor = { id, gatewayId, name, identifier, sensorType }
|
|
|
+ this.$refs.editDialog.show()
|
|
|
+ },
|
|
|
+ onConfirm (done) {
|
|
|
+ if (!this.sensor.name) {
|
|
|
+ this.$message({
|
|
|
+ type: 'warning',
|
|
|
+ message: '请填写传感器名称'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!this.sensor.identifier) {
|
|
|
+ this.$message({
|
|
|
+ type: 'warning',
|
|
|
+ message: '请填写传感器标识'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (this.isAdd) {
|
|
|
+ this.onConfirmAdd(this.sensor, done)
|
|
|
+ } else {
|
|
|
+ this.onConfirmEdit(this.sensor, done)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onConfirmAdd (sensor, done) {
|
|
|
+ addSensor(this.gateway.id, { ...sensor }).then(() => {
|
|
|
+ done()
|
|
|
+ this.$refs.table.resetCondition()
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onConfirmEdit (sensor, done) {
|
|
|
+ updateSensor(sensor).then(() => {
|
|
|
+ done()
|
|
|
+ this.$refs.table.pageTo()
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onDel (sensor) {
|
|
|
+ deleteSensor(sensor).then(() => {
|
|
|
+ this.$refs.table.decrease(1)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|