This commit is contained in:
joylink_cuiweidong 2019-11-20 10:39:14 +08:00
commit c264b61f65
6 changed files with 258 additions and 237 deletions

View File

@ -3,6 +3,6 @@ import OperateHandler2 from './OperateHandler2.js';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
const OPERATEHANDLER_KEY = 'OperateHandler'; const OPERATEHANDLER_KEY = 'OperateHandler';
Cookies.set(OPERATEHANDLER_KEY, 1); Cookies.set(OPERATEHANDLER_KEY, '');
export default Cookies.get(OPERATEHANDLER_KEY) ? OperateHandler1 : OperateHandler2; export default Cookies.get(OPERATEHANDLER_KEY) ? OperateHandler1 : OperateHandler2;

View File

@ -1,11 +1,9 @@
import store from '@/store'; import store from '@/store';
import router from '@/router'; import router from '@/router';
import CommandHandler from './CommandHandler.js'; import CommandHandler from './CommandHandler.js';
import { TrainingMode } from '@/scripts/ConstDic'; import ValidateHandler from './ValidateHandler.js';
import { sendTrainingNextStep } from '@/api/jmap/training'; import { sendTrainingNextStep } from '@/api/jmap/training';
import { Message } from 'element-ui';
import { OperationEvent } from '@/scripts/ConstDic'; import { OperationEvent } from '@/scripts/ConstDic';
import LangStorage from '@/utils/lang';
class OperateHandler { class OperateHandler {
constructor() { constructor() {
@ -22,24 +20,6 @@ class OperateHandler {
this.operates.splice(0, this.operates.length); 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) { getCommand(operate) {
let command = null; let command = null;
if (operate.send) { if (operate.send) {
@ -63,8 +43,11 @@ class OperateHandler {
return command; return command;
} }
/** 步骤前处理*/ execute(command) {
preProcessor(operate) { return CommandHandler.execute(command);
}
storeOperate(operate) {
// 按钮操作之后,第二步错误操作菜单的情况,需要直接返回 // 按钮操作之后,第二步错误操作菜单的情况,需要直接返回
if ((this.operates.length && operate.start === true) && (this.operates[0].type === 'mbm')) { if ((this.operates.length && operate.start === true) && (this.operates[0].type === 'mbm')) {
return false; return false;
@ -79,8 +62,7 @@ class OperateHandler {
this.operates.push(operate); this.operates.push(operate);
} }
/** 步骤后处理*/ afterAalid(operate, valid) {
postProcessor(operate, valid) {
const basicInfo = store.getters['training/basicInfo']; const basicInfo = store.getters['training/basicInfo'];
if (basicInfo.id && valid) { 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) { handle(operate) {
this.storeOperate(operate);
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 = ValidateHandler.vaildate(this.getTrainingMode(), operate);
const command = this.getCommand(operate); const command = this.getCommand(operate);
rtn.valid = valid; rtn.valid = valid;
this.afterAalid(operate, valid);
if (valid && command) { if (valid && command) {
CommandHandler.execute(command).then(response => { CommandHandler.execute(command).then(response => {
rtn.response = response; rtn.response = response;
@ -152,10 +102,6 @@ class OperateHandler {
}); });
} }
getTrainingMode () {
return store.state.training.mode;
}
getSteps() { getSteps() {
return store.state.training.steps; return store.state.training.steps;
} }
@ -164,6 +110,10 @@ class OperateHandler {
return store.state.training.order; return store.state.training.order;
} }
getTrainingMode () {
return store.state.training.mode;
}
getTrainingStart() { getTrainingStart() {
return store.state.training.started; return store.state.training.started;
} }

View File

@ -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();

View File

@ -13,20 +13,6 @@
<el-button type="text" class="mapEdit_box" @click="showMap">{{ $t('map.viewLayer') }}</el-button> <el-button type="text" class="mapEdit_box" @click="showMap">{{ $t('map.viewLayer') }}</el-button>
</div> </div>
<el-tabs v-model="enabledTab" type="card" class="map_card" @tab-click="changePane"> <el-tabs v-model="enabledTab" type="card" class="map_card" @tab-click="changePane">
<el-tab-pane label="站台屏蔽门" class="tab_pane_box" name="safetyDoor">
<safety-door-operate
ref="routeOperate"
:map-info="mapInfo"
:selected="selected"
/>
</el-tab-pane>
<el-tab-pane label="站台紧急停车按钮" class="tab_pane_box" name="park">
<park-operate
ref="routeOperate"
:map-info="mapInfo"
:selected="selected"
/>
</el-tab-pane>
<el-tab-pane :label="$t('map.routeID')" class="tab_pane_box" name="route"> <el-tab-pane :label="$t('map.routeID')" class="tab_pane_box" name="route">
<route-operate <route-operate
ref="routeOperate" ref="routeOperate"
@ -67,6 +53,20 @@
@setCenter="setCenter" @setCenter="setCenter"
/> />
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="站台屏蔽门" class="tab_pane_box" name="safetyDoor">
<safety-door-operate
ref="routeOperate"
:map-info="mapInfo"
:selected="selected"
/>
</el-tab-pane>
<el-tab-pane label="站台紧急停车按钮" class="tab_pane_box" name="park">
<park-operate
ref="routeOperate"
:map-info="mapInfo"
:selected="selected"
/>
</el-tab-pane>
</el-tabs> </el-tabs>
</div> </div>
</div> </div>

View File

@ -162,84 +162,84 @@
<script> <script>
import ElFont from '@/views/components/font/index'; import ElFont from '@/views/components/font/index';
export default { export default {
name: 'ConfigList', name: 'ConfigList',
components: { components: {
ElFont ElFont
}, },
props: { props: {
formModel: { formModel: {
type: Object, type: Object,
required: true required: true
}, },
form: { form: {
type: Object, type: Object,
required: true required: true
}, },
rules: { rules: {
type: Object, type: Object,
default: function () { default: function () {
return null; return null;
} }
} }
}, },
data () { data () {
return { return {
skins: [] skins: []
}; };
}, },
methods: { methods: {
handleLabel(option, label) { handleLabel(option, label) {
if (label == 'name') { if (label == 'name') {
return option.name; return option.name;
} else if (label == 'code') { } else if (label == 'code') {
return option.code; return option.code;
} else if (label == 'label') { } else if (label == 'label') {
return option.label; return option.label;
} else if (label == 'name&&code') { } else if (label == 'name&&code') {
if (option.code) { if (option.code) {
return option.name + ' (' + option.code+ ')'; return option.name + ' (' + option.code + ')';
} else { } else {
return option.name; return option.name;
} }
} else if (label == 'code&&name') { } else if (label == 'code&&name') {
return option.code + ' (' + option.name+ ')'; return option.code + ' (' + option.name + ')';
} else { } else {
return option.label; return option.label;
} }
}, },
decompose(item, prop) { decompose(item, prop) {
if (!prop.includes('.')) { if (!prop.includes('.')) {
return prop; return prop;
} }
const keyArr = prop.split('.'); const keyArr = prop.split('.');
return keyArr[0][keyArr[1]]; return keyArr[0][keyArr[1]];
}, },
checkFieldType(field, type) { checkFieldType(field, type) {
if (field.hasOwnProperty('show')) { if (field.hasOwnProperty('show')) {
return field.type === type && field.show; return field.type === type && field.show;
} else { } else {
return field.type === type; return field.type === type;
} }
}, },
validate(callback) { validate(callback) {
this.$refs.form.validate((valid) => { this.$refs.form.validate((valid) => {
if (valid) { if (valid) {
callback(true); callback(true);
} else { } else {
callback(false); callback(false);
} }
}); });
}, },
resetForm() { resetForm() {
this.$refs.form.resetFields(); this.$refs.form.resetFields();
}, },
clearValidate() { clearValidate() {
this.$refs.form.clearValidate(); this.$refs.form.clearValidate();
}, },
resetFields() { resetFields() {
this.$refs.form.resetFields(); this.$refs.form.resetFields();
} }
} }
}; };
</script> </script>

View File

@ -68,7 +68,7 @@
<template v-if="checkFieldType(item, 'number')"> <template v-if="checkFieldType(item, 'number')">
<el-form-item v-if="!item.isHidden" :key="item.prop" :label="item.label" :prop="item.prop" :required="item.required"> <el-form-item v-if="!item.isHidden" :key="item.prop" :label="item.label" :prop="item.prop" :required="item.required">
<div v-if="!item.firstLevel"> <div v-if="!item.firstLevel">
<el-input-number v-model="formModel[item.prop]" :min="item.min" :max="item.max" :label="item.label" :disabled="item.disabled" /> <el-input-number v-model="formModel[item.prop]" :min="item.min" :max="item.max" :label="item.label" :disabled="item.disabled" style="width: 140px" />
<span style="padding-left: 1px;">{{ item.placeholder }}</span> <span style="padding-left: 1px;">{{ item.placeholder }}</span>
</div> </div>
<div v-else> <div v-else>
@ -177,84 +177,84 @@
<script> <script>
import ElFont from '@/views/components/font/index'; import ElFont from '@/views/components/font/index';
export default { export default {
name: 'ConfigList', name: 'ConfigList',
components: { components: {
ElFont ElFont
}, },
props: { props: {
formModel: { formModel: {
type: Object, type: Object,
required: true required: true
}, },
form: { form: {
type: Object, type: Object,
required: true required: true
}, },
rules: { rules: {
type: Object, type: Object,
default: function () { default: function () {
return null; return null;
} }
} }
}, },
data () { data () {
return { return {
skins: [] skins: []
}; };
}, },
methods: { methods: {
handleLabel(option, label) { handleLabel(option, label) {
if (label == 'name') { if (label == 'name') {
return option.name; return option.name;
} else if (label == 'code') { } else if (label == 'code') {
return option.code; return option.code;
} else if (label == 'label') { } else if (label == 'label') {
return option.label; return option.label;
} else if (label == 'name&&code') { } else if (label == 'name&&code') {
if (option.code) { if (option.code) {
return option.name + ' (' + option.code+ ')'; return option.name + ' (' + option.code + ')';
} else { } else {
return option.name; return option.name;
} }
} else if (label == 'code&&name') { } else if (label == 'code&&name') {
return option.code + ' (' + option.name+ ')'; return option.code + ' (' + option.name + ')';
} else { } else {
return option.label; return option.label;
} }
}, },
decompose(item, prop) { decompose(item, prop) {
if (!prop.includes('.')) { if (!prop.includes('.')) {
return prop; return prop;
} }
const keyArr = prop.split('.'); const keyArr = prop.split('.');
return keyArr[0][keyArr[1]]; return keyArr[0][keyArr[1]];
}, },
checkFieldType(field, type) { checkFieldType(field, type) {
if (field.hasOwnProperty('show')) { if (field.hasOwnProperty('show')) {
return field.type === type && field.show; return field.type === type && field.show;
} else { } else {
return field.type === type; return field.type === type;
} }
}, },
validate(callback) { validate(callback) {
this.$refs.form.validate((valid) => { this.$refs.form.validate((valid) => {
if (valid) { if (valid) {
callback(true); callback(true);
} else { } else {
callback(false); callback(false);
} }
}); });
}, },
resetForm() { resetForm() {
this.$refs.form.resetFields(); this.$refs.form.resetFields();
}, },
clearValidate() { clearValidate() {
this.$refs.form.clearValidate(); // this.$refs.form.clearValidate(); //
}, },
resetFields() { resetFields() {
this.$refs.form.resetFields(); // this.$refs.form.resetFields(); //
} }
} }
}; };
</script> </script>