设备禁用bug处理

This commit is contained in:
kerwincui
2022-07-05 01:41:29 +08:00
parent 00240fa258
commit 37630007c2
2 changed files with 34 additions and 33 deletions

View File

@@ -98,7 +98,7 @@
<el-tab-pane name="runningStatus" :disabled="form.deviceId==0"> <el-tab-pane name="runningStatus" :disabled="form.deviceId==0">
<span slot="label">运行状态</span> <span slot="label">运行状态</span>
<running-status ref="runningStatus" :device="form" /> <running-status ref="runningStatus" :device="form" @statusEvent="getDeviceStatus($event)" />
</el-tab-pane> </el-tab-pane>
<el-tab-pane name="deviceTimer" :disabled="form.deviceId==0"> <el-tab-pane name="deviceTimer" :disabled="form.deviceId==0">
@@ -198,6 +198,26 @@ export default {
} }
} }
}, },
computed: {
deviceStatus: {
set(val) {
if (val == 1) {
// 1-未激活2-禁用3-在线4-离线
this.form.status = 2;
} else if (val == 0) {
this.form.status = 4;
} else {
this.form.status = this.oldDeviceStatus;
}
},
get() {
if (this.form.status == 2) {
return 1;
}
return 0
},
},
},
data() { data() {
return { return {
// 打开设备配置对话框 // 打开设备配置对话框
@@ -210,8 +230,8 @@ export default {
activeName: 'basic', activeName: 'basic',
// 遮罩层 // 遮罩层
loading: true, loading: true,
// 设备状态1=禁用0=不禁用) // 设备开始状态
deviceStatus: 0, oldDeviceStatus: null,
// 表单参数 // 表单参数
form: { form: {
productId: 0, productId: 0,
@@ -259,19 +279,17 @@ export default {
}, 2000); }, 2000);
}, },
methods: { methods: {
// 获取子组件订阅的设备状态
getDeviceStatus(status) {
this.form.status = status;
},
/** 数据同步*/ /** 数据同步*/
deviceSynchronization() { deviceSynchronization() {
deviceSynchronization(this.form.serialNumber).then(response => { deviceSynchronization(this.form.serialNumber).then(response => {
this.form = response.data; this.form = response.data;
// 选项卡切换 // 选项卡切换
this.activeName = 'runningStatus'; this.activeName = 'runningStatus';
// 禁用状态 this.oldDeviceStatus = this.form.status;
if (this.form.status == 2) {
this.deviceStatus = 1;
}
if (this.form.imgUrl != null && this.form.imgUrl != "") {
this.imageUrl = this.form.imgUrl;
}
this.loadMap(); this.loadMap();
}); });
}, },
@@ -279,16 +297,10 @@ export default {
getDevice(deviceId) { getDevice(deviceId) {
getDevice(deviceId).then(response => { getDevice(deviceId).then(response => {
this.form = response.data; this.form = response.data;
if(this.form.summary!=null && this.form.summary!=""){ if (this.form.summary != null && this.form.summary != "") {
this.summary = JSON.parse(this.form.summary); this.summary = JSON.parse(this.form.summary);
} }
// 禁用状态 this.oldDeviceStatus = this.form.status;
if (this.form.status == 2) {
this.deviceStatus = 1;
}
if (this.form.imgUrl != null && this.form.imgUrl != "") {
this.imageUrl = this.form.imgUrl;
}
this.loadMap(); this.loadMap();
}); });
@@ -348,20 +360,19 @@ export default {
this.$refs["form"].validate(valid => { this.$refs["form"].validate(valid => {
if (valid) { if (valid) {
if (this.form.deviceId != 0) { if (this.form.deviceId != 0) {
// 设置设备状态
this.setDeviceStatus();
console.log(this.form);
updateDevice(this.form).then(response => { updateDevice(this.form).then(response => {
if (response.data == 0) { if (response.data == 0) {
this.$modal.alertError(response.msg); this.$modal.alertError(response.msg);
} else { } else {
this.$modal.alertSuccess("修改成功"); this.$modal.alertSuccess("修改成功");
this.form=JSON.parse(JSON.stringify(this.form));
this.loadMap(); this.loadMap();
} }
}); });
} else { } else {
addDevice(this.form).then(response => { addDevice(this.form).then(response => {
this.form = response.data; this.form = response.data;
this.oldDeviceStatus = this.from.status;
if (this.form.deviceId == null || this.form.deviceId == 0) { if (this.form.deviceId == null || this.form.deviceId == 0) {
this.$modal.alertError("设备编号已经存在,添加设备失败"); this.$modal.alertError("设备编号已经存在,添加设备失败");
} else { } else {
@@ -417,17 +428,6 @@ export default {
this.map.addOverlay(this.mk) this.map.addOverlay(this.mk)
this.map.panTo(point) this.map.panTo(point)
}, },
// 设置设备的状态
setDeviceStatus() {
if (this.deviceStatus == 1) {
this.form.status = 2;
} else {
// 禁用状态,启用后状态是离线
if (this.form.status == 2) {
this.form.status = 4;
}
}
},
// 生成随机字母和数字 // 生成随机字母和数字
generateNum() { generateNum() {
this.genDisabled = true; this.genDisabled = true;

View File

@@ -368,6 +368,7 @@ export default {
this.shadowUnEnable = true; this.shadowUnEnable = true;
} }
} }
this.$emit('statusEvent', this.deviceInfo.status);
}, },
/** 设备升级 */ /** 设备升级 */
otaUpgrade() { otaUpgrade() {