修改代码

This commit is contained in:
ival 2019-07-25 11:07:32 +08:00
parent 1c980c5613
commit 83c6fccfc9
3 changed files with 102 additions and 83 deletions

View File

@ -1,6 +1,6 @@
import Vue from 'vue';
import { TrainingMode } from '@/scripts/ConstDic';
import OperateHandler from '@/scripts/plugin/trainingOperateHandler';
// import OperateHandler from '@/scripts/plugin/trainingOperateHandler';
/**
* 实训状态数据
@ -249,7 +249,7 @@ const training = {
*/
start: ({ commit }) => {
// 清空操作组
OperateHandler.cleanOperates();
// OperateHandler.cleanOperates();
// 清空计时器以及得分
commit('stopCountTime');
commit('resetUsedTime');
@ -345,28 +345,28 @@ const training = {
}
// 处理operation
OperateHandler.handle(operate).then(rtn => {
if (state.started) {
// 教学和联系模式需要给出过程步骤提示
if (TrainingMode.TEACH === state.mode || TrainingMode.PRACTICE === state.mode) {
if (rtn && rtn.valid) {
commit('next');
commit('setOperateErrMsg', { errMsg: '操作正确!真棒!', color: 'green' });
commit('tipEventIncrement');
} else {
if (!operate.repeat) {
commit('setOperateErrMsg', { errMsg: '操作错误!', color: 'red' });
}
}
} else if (TrainingMode.EXAM === state.mode || TrainingMode.TEST === state.mode) {
// 测试和考试不给提示
rtn && rtn.valid && commit('next');
}
}
resolve(rtn);
}).catch(error => {
reject(error);
});
// OperateHandler.handle(operate).then(rtn => {
// if (state.started) {
// // 教学和联系模式需要给出过程步骤提示
// if (TrainingMode.TEACH === state.mode || TrainingMode.PRACTICE === state.mode) {
// if (rtn && rtn.valid) {
// commit('next');
// commit('setOperateErrMsg', { errMsg: '操作正确!真棒!', color: 'green' });
// commit('tipEventIncrement');
// } else {
// if (!operate.repeat) {
// commit('setOperateErrMsg', { errMsg: '操作错误!', color: 'red' });
// }
// }
// } else if (TrainingMode.EXAM === state.mode || TrainingMode.TEST === state.mode) {
// // 测试和考试不给提示
// rtn && rtn.valid && commit('next');
// }
// }
// resolve(rtn);
// }).catch(error => {
// reject(error);
// });
});
},

View File

@ -1,14 +1,9 @@
/* eslint-disable no-mixed-spaces-and-tabs */
/**
* Created by PanJiaChen on 16/11/18.
* Created by jiachenpan on 16/11/18.
*/
import md5 from 'js-md5';
/**
* Parse the time to string
* @param {(Object|string|number)} time
* @param {string} cFormat
* @returns {string}
*/
// 时间转换格式
export function parseTime(time, cFormat) {
if (arguments.length === 0) {
return null;
@ -18,12 +13,7 @@ export function parseTime(time, cFormat) {
if (typeof time === 'object') {
date = time;
} else {
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
time = parseInt(time);
}
if ((typeof time === 'number') && (time.toString().length === 10)) {
time = time * 1000;
}
if (('' + time).length === 10) time = parseInt(time) * 1000;
date = new Date(time);
}
const formatObj = {
@ -37,8 +27,7 @@ export function parseTime(time, cFormat) {
};
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key];
// Note: getDay() returns 0 on Sunday
if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ]; }
if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1];
if (result.length > 0 && value < 10) {
value = '0' + value;
}
@ -46,18 +35,9 @@ export function parseTime(time, cFormat) {
});
return time_str;
}
/**
* @param {number} time
* @param {string} option
* @returns {string}
*/
export function timeFormat(time, option) {
if (('' + time).length === 10) {
time = parseInt(time) * 1000;
} else {
time = +time;
}
// 判断多久之前
export function formatTime(time, option) {
time = +time * 1000;
const d = new Date(time);
const now = Date.now();
@ -65,8 +45,7 @@ export function timeFormat(time, option) {
if (diff < 30) {
return '刚刚';
} else if (diff < 3600) {
// less 1 hour
} else if (diff < 3600) { // less 1 hour
return Math.ceil(diff / 60) + '分钟前';
} else if (diff < 3600 * 24) {
return Math.ceil(diff / 3600) + '小时前';
@ -76,36 +55,75 @@ export function timeFormat(time, option) {
if (option) {
return parseTime(time, option);
} else {
return (
d.getMonth() +
1 +
'月' +
d.getDate() +
'日' +
d.getHours() +
'时' +
d.getMinutes() +
'分'
);
return d.getMonth() + 1 + '月' + d.getDate() + '日' + d.getHours() + '时' + d.getMinutes() + '分';
}
}
/**
* @param {string} url
* @returns {Object}
* 获取dom对象偏移位置 设置初始位置
* @param {*} dom - 需要获取的dom
* @param {*} isFixed - 父级是否position: fixed
*/
export function param2Obj(url) {
const search = url.split('?')[1];
if (!search) {
return {};
export function getDomOffset(dom) {
let pol = 0;
let pot = 0;
let offsetLeft = 0;
let offsetTop = 0;
while (dom) {
if (pol != dom.offsetLeft) {
offsetLeft += dom.offsetLeft;
pol = dom.offsetLeft;
}
if (pot != dom.offsetTop) {
offsetTop += dom.offsetTop;
pot = dom.offsetTop;
}
dom = dom.offsetParent;
}
const offset = {
x: offsetLeft,
y: offsetTop
};
return offset;
}
/**
* 矩形碰撞检测
*/
export function checkRectCollision(rect1, rect2) {
const center1 = { x: rect1.point.x + rect1.width / 2, y: rect1.point.y + rect1.height / 2 };
const center2 = { x: rect2.point.x + rect2.width / 2, y: rect2.point.y + rect2.height / 2 };
if (
// 横向判断 和 纵向判断
Math.abs(center1.x - center2.x) < rect1.width / 2 + rect2.width / 2 &&
Math.abs(center1.y - center2.y) < rect1.height / 2 + rect2.height / 2
) {
return true;
}
return false;
}
export function getSessionId() {
return md5([Math.random().toFixed(5), +new Date()].join('_'));
}
/*
* 获取倒计时
* data 目标时间
*/
export function getCountTime(data) {
const stationDate = parseInt(data);
const date = Date.parse(new Date()) / 1000;
const time = stationDate - date;
if (time > 0) {
let h = Math.floor(time / (60 * 60));
let m = Math.floor(time / 60) - (h * 60);
let s = Math.floor(time) - (h * 60 * 60) - (m * 60);
if (h <= 9) h = '0' + h;
if (m <= 9) m = '0' + m;
if (s <= 9) s = '0' + s;
return `${h}:${m}:${s}`;
} else {
return -1;
}
return JSON.parse(
'{"' +
decodeURIComponent(search)
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"')
.replace(/\+/g, ' ') +
'"}'
);
}

View File

@ -76,8 +76,11 @@
try {
this.setMap(val);
} catch (error) {
this.mapViewLoaded(false);
console.log(error);
}
} else {
this.mapViewLoaded(false);
}
},
'$store.state.training.rezoomCount': function (val, old) {
@ -171,9 +174,7 @@
this.width = this.$store.state.config.width;
this.height = this.$store.state.config.height;
if (this.$jlmap) {
this.$jlmap.resizeZr({ width: this.width, height: this.height });
}
this.$jlmap && this.$jlmap.resize({ width: this.width, height: this.height });
this.$store.dispatch('training/updateOffsetStationCode', { offsetStationCode: this.offsetStationCode });