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';
const OPERATEHANDLER_KEY = 'OperateHandler';
Cookies.set(OPERATEHANDLER_KEY, 1);
Cookies.set(OPERATEHANDLER_KEY, '');
export default Cookies.get(OPERATEHANDLER_KEY) ? OperateHandler1 : OperateHandler2;

View File

@ -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;
}

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>
</div>
<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">
<route-operate
ref="routeOperate"
@ -67,6 +53,20 @@
@setCenter="setCenter"
/>
</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>
</div>
</div>

View File

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

View File

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