修改代码

This commit is contained in:
ival 2019-11-19 16:41:21 +08:00
parent d50ee414ae
commit 09af7d91b4
2 changed files with 37 additions and 20 deletions

View File

@ -1,3 +1,4 @@
import { MapDeviceType } from '@/scripts/ConstDic';
import { sendCommand } from '@/api/jmap/training';
import router from '@/router';
@ -5,24 +6,46 @@ class CommandHandle {
constructor() {
this.data = [];
this.instructionMap = {
1: {
type: MapDeviceType.Signal.type,
operation: 1
},
2: {
type: MapDeviceType.Signal.type,
operation: 2
},
8: {
type: MapDeviceType.StationStand.type,
operation: 8
}
};
}
getInstruction(operation) {
return this.instructionMap[operation] || {};
getInstruction(operate) {
return this.instructionMap[operate.commandType.value] || {};
}
getCommand(operates) {
const operate = operates[operates.length - 1] || {};
if (operate && operate.instructionType) {
const instruction = this.getInstruction(operate.instructionType);
if (operate && operate.commandType) {
const instruction = this.getInstruction(operate);
if (instruction) {
return {
const command = {
...instruction,
paramList: this.getParamsList(operates),
code: operate.code,
val: operate.val,
over: operate.over
};
if (!command.code) {
operates.forEach(elem => {
if (elem.code) {
command.code = elem.code;
}
});
}
return command;
} else {
return { error: true };
}
@ -34,16 +57,11 @@ class CommandHandle {
execute(command) {
return new Promise((resolve, reject) => {
const group = router.currentRoute.query.group;
if (command) {
sendCommand(group, command).then((response) => {
resolve(response);
}).catch(error => {
reject(error);
});
} else {
reject();
}
sendCommand(group, command).then((response) => {
resolve(response);
}).catch(error => {
reject(error);
});
});
}
}

View File

@ -10,7 +10,6 @@ import LangStorage from '@/utils/lang';
class OperateHandler {
constructor() {
this.operates = []; // 操作数据
this.command = {}; // 命令对象
}
/** 操作组 */
@ -136,11 +135,11 @@ class OperateHandler {
return new Promise((resolve, reject) => {
const rtn = { valid: false, response: null };
const valid = this.validate(operate);
const command = this.getCommand(operate);
rtn.valid = valid;
if (valid) {
const command = this.getCommand(operate);
if (valid && command) {
CommandHandler.execute(command).then(response => {
rtn.response = response;
resolve(rtn);