修改代码
This commit is contained in:
parent
d50ee414ae
commit
09af7d91b4
@ -1,3 +1,4 @@
|
|||||||
|
import { MapDeviceType } from '@/scripts/ConstDic';
|
||||||
import { sendCommand } from '@/api/jmap/training';
|
import { sendCommand } from '@/api/jmap/training';
|
||||||
import router from '@/router';
|
import router from '@/router';
|
||||||
|
|
||||||
@ -5,24 +6,46 @@ class CommandHandle {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.data = [];
|
this.data = [];
|
||||||
this.instructionMap = {
|
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) {
|
getInstruction(operate) {
|
||||||
return this.instructionMap[operation] || {};
|
return this.instructionMap[operate.commandType.value] || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
getCommand(operates) {
|
getCommand(operates) {
|
||||||
const operate = operates[operates.length - 1] || {};
|
const operate = operates[operates.length - 1] || {};
|
||||||
if (operate && operate.instructionType) {
|
if (operate && operate.commandType) {
|
||||||
const instruction = this.getInstruction(operate.instructionType);
|
const instruction = this.getInstruction(operate);
|
||||||
if (instruction) {
|
if (instruction) {
|
||||||
return {
|
const command = {
|
||||||
...instruction,
|
...instruction,
|
||||||
paramList: this.getParamsList(operates),
|
code: operate.code,
|
||||||
|
val: operate.val,
|
||||||
over: operate.over
|
over: operate.over
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!command.code) {
|
||||||
|
operates.forEach(elem => {
|
||||||
|
if (elem.code) {
|
||||||
|
command.code = elem.code;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return command;
|
||||||
} else {
|
} else {
|
||||||
return { error: true };
|
return { error: true };
|
||||||
}
|
}
|
||||||
@ -34,16 +57,11 @@ class CommandHandle {
|
|||||||
execute(command) {
|
execute(command) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const group = router.currentRoute.query.group;
|
const group = router.currentRoute.query.group;
|
||||||
if (command) {
|
|
||||||
sendCommand(group, command).then((response) => {
|
sendCommand(group, command).then((response) => {
|
||||||
resolve(response);
|
resolve(response);
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
reject();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import LangStorage from '@/utils/lang';
|
|||||||
class OperateHandler {
|
class OperateHandler {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.operates = []; // 操作数据
|
this.operates = []; // 操作数据
|
||||||
this.command = {}; // 命令对象
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 操作组 */
|
/** 操作组 */
|
||||||
@ -136,11 +135,11 @@ class OperateHandler {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const rtn = { valid: false, response: null };
|
const rtn = { valid: false, response: null };
|
||||||
const valid = this.validate(operate);
|
const valid = this.validate(operate);
|
||||||
|
const command = this.getCommand(operate);
|
||||||
|
|
||||||
rtn.valid = valid;
|
rtn.valid = valid;
|
||||||
|
|
||||||
if (valid) {
|
if (valid && command) {
|
||||||
const command = this.getCommand(operate);
|
|
||||||
CommandHandler.execute(command).then(response => {
|
CommandHandler.execute(command).then(response => {
|
||||||
rtn.response = response;
|
rtn.response = response;
|
||||||
resolve(rtn);
|
resolve(rtn);
|
||||||
|
Loading…
Reference in New Issue
Block a user