-
+
{{ item.placeholder }}
@@ -177,84 +177,84 @@
From cd6e2ea224cc916301335ff35ae68d488572148b Mon Sep 17 00:00:00 2001
From: ival <610568032@qq.com>
Date: Tue, 19 Nov 2019 18:35:31 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/scripts/plugin/OperateHandler.js | 2 +-
src/scripts/plugin/OperateHandler2.js | 80 +++++----------------------
src/scripts/plugin/ValidateHandler.js | 71 ++++++++++++++++++++++++
3 files changed, 87 insertions(+), 66 deletions(-)
create mode 100644 src/scripts/plugin/ValidateHandler.js
diff --git a/src/scripts/plugin/OperateHandler.js b/src/scripts/plugin/OperateHandler.js
index c316fbebd..35b528afd 100644
--- a/src/scripts/plugin/OperateHandler.js
+++ b/src/scripts/plugin/OperateHandler.js
@@ -3,6 +3,6 @@ import OperateHandler2 from './OperateHandler2.js';
import Cookies from 'js-cookie';
const OPERATEHANDLER_KEY = 'OperateHandler';
-Cookies.set(OPERATEHANDLER_KEY, 1);
+Cookies.set(OPERATEHANDLER_KEY, '');
export default Cookies.get(OPERATEHANDLER_KEY) ? OperateHandler1 : OperateHandler2;
diff --git a/src/scripts/plugin/OperateHandler2.js b/src/scripts/plugin/OperateHandler2.js
index 0e5eb4522..7a7a33cc0 100644
--- a/src/scripts/plugin/OperateHandler2.js
+++ b/src/scripts/plugin/OperateHandler2.js
@@ -1,11 +1,9 @@
import store from '@/store';
import router from '@/router';
import CommandHandler from './CommandHandler.js';
-import { TrainingMode } from '@/scripts/ConstDic';
+import ValidateHandler from './ValidateHandler.js';
import { sendTrainingNextStep } from '@/api/jmap/training';
-import { Message } from 'element-ui';
import { OperationEvent } from '@/scripts/ConstDic';
-import LangStorage from '@/utils/lang';
class OperateHandler {
constructor() {
@@ -22,24 +20,6 @@ class OperateHandler {
this.operates.splice(0, this.operates.length);
}
- /** 判断操作步骤是否正确 */
- judge (operate) {
- const steps = this.getSteps();
- const order = this.getOrder();
-
- let valid = false;
- if (order < steps.length) {
- const standard = steps[order];
- if (operate && standard && operate.code == standard.code && operate.type == standard.type &&
- operate.operation == standard.operation &&
- operate.val == standard.val) {
- valid = true;
- }
- }
-
- return valid;
- }
-
getCommand(operate) {
let command = null;
if (operate.send) {
@@ -63,8 +43,11 @@ class OperateHandler {
return command;
}
- /** 步骤前处理*/
- preProcessor(operate) {
+ execute(command) {
+ return CommandHandler.execute(command);
+ }
+
+ storeOperate(operate) {
// 按钮操作之后,第二步错误操作菜单的情况,需要直接返回
if ((this.operates.length && operate.start === true) && (this.operates[0].type === 'mbm')) {
return false;
@@ -79,8 +62,7 @@ class OperateHandler {
this.operates.push(operate);
}
- /** 步骤后处理*/
- postProcessor(operate, valid) {
+ afterAalid(operate, valid) {
const basicInfo = store.getters['training/basicInfo'];
if (basicInfo.id && valid) {
// 发送记录步骤数据
@@ -97,48 +79,16 @@ class OperateHandler {
}
}
- /** 根据模式验证操作步骤 */
- validate(operate) {
- this.preProcessor(operate);
-
- let valid = true;
- if (TrainingMode.EDIT === this.getTrainingMode()) {
- // 编辑制作模式
- if (this.getOperateBreakStatus()) {
- valid = false;
- const tip = LangStorage.getLang() == 'en' ? 'Please enter a hint and click next' : '请输入提示并点击下一步';
- Message.error(tip);
- this.operates.pop();
- return valid;
- }
-
- if (this.getTrainingStart()) {
- store.dispatch('training/setTempStep', operate);
- }
-
- } else if (TrainingMode.TEACH === this.getTrainingMode() || TrainingMode.PRACTICE === this.getTrainingMode()) {
- // 教学模式/练习模式
- if (this.getTrainingStart()) {
- valid = this.judge(operate);
- } else {
- this.cleanOperates();
- valid = false;
- }
- }
-
- this.postProcessor(operate, valid);
-
- return valid;
- }
-
handle(operate) {
+ this.storeOperate(operate);
return new Promise((resolve, reject) => {
const rtn = { valid: false, response: null };
- const valid = this.validate(operate);
+ const valid = ValidateHandler.vaildate(this.getTrainingMode(), operate);
const command = this.getCommand(operate);
-
rtn.valid = valid;
+ this.afterAalid(operate, valid);
+
if (valid && command) {
CommandHandler.execute(command).then(response => {
rtn.response = response;
@@ -152,10 +102,6 @@ class OperateHandler {
});
}
- getTrainingMode () {
- return store.state.training.mode;
- }
-
getSteps() {
return store.state.training.steps;
}
@@ -164,6 +110,10 @@ class OperateHandler {
return store.state.training.order;
}
+ getTrainingMode () {
+ return store.state.training.mode;
+ }
+
getTrainingStart() {
return store.state.training.started;
}
diff --git a/src/scripts/plugin/ValidateHandler.js b/src/scripts/plugin/ValidateHandler.js
new file mode 100644
index 000000000..6f041d2bd
--- /dev/null
+++ b/src/scripts/plugin/ValidateHandler.js
@@ -0,0 +1,71 @@
+import store from '@/store';
+import LangStorage from '@/utils/lang';
+import OperateHandler from './OperateHandler.js';
+import { TrainingMode } from '@/scripts/ConstDic';
+import { Message } from 'element-ui';
+
+class ValidateHandler {
+ vaildate(mode, operate) {
+ switch (mode) {
+ case TrainingMode.EDIT: // 编辑制作模式
+ return this.vaildate_edit(operate);
+ case TrainingMode.PRACTICE: // 练习模式
+ return this.vaildate_tips(operate);
+ case TrainingMode.TEACH: // 教学模式
+ return this.vaildate_tips(operate);
+ }
+
+ return true;
+ }
+
+ vaildate_edit(operate) {
+ let vaild = true;
+ if (OperateHandler.getOperateBreakStatus()) {
+ const tip = LangStorage.getLang() == 'en' ? 'Please enter a hint and click next' : '请输入提示并点击下一步';
+ Message.error(tip);
+ OperateHandler.operates.pop();
+ vaild = false;
+ }
+
+ if (OperateHandler.getTrainingStart()) {
+ store.dispatch('training/setTempStep', operate);
+ }
+
+ return vaild;
+ }
+
+ vaildate_tips(operate) {
+ let valid = true;
+ if (OperateHandler.getTrainingStart()) {
+ valid = this.judge(operate);
+ } else {
+ OperateHandler.cleanOperates();
+ valid = false;
+ }
+
+ return valid;
+ }
+
+ /** 判断操作步骤是否正确 */
+ judge (operate) {
+ const steps = OperateHandler.getSteps();
+ const order = OperateHandler.getOrder();
+
+ let valid = false;
+ if (order < steps.length) {
+ const standard = steps[order];
+ if (operate && standard &&
+ operate.code == standard.code &&
+ operate.type == standard.type &&
+ operate.operation == standard.operation &&
+ operate.val == standard.val) {
+ valid = true;
+ }
+ }
+
+ return valid;
+ }
+
+}
+
+export default new ValidateHandler();