This commit is contained in:
zyy 2019-07-25 11:08:23 +08:00
commit e14460f1ef
5 changed files with 915 additions and 392 deletions

View File

@ -6,6 +6,7 @@ import user from './modules/user';
import config from './modules/config';
import permission from './modules/permission';
import map from './modules/map';
import training from './modules/training';
import getters from './getters';
Vue.use(Vuex);
@ -17,7 +18,8 @@ const store = new Vuex.Store({
user,
permission,
config,
map
map,
training
},
getters
});

View File

@ -191,9 +191,6 @@ const map = {
deviceUpdateCount: 0, // 地图设备更新标识
mapViewLoadedCount: 0, // 地图视图加载完成标识
mapDataLoadedCount: 0, // 地图数据加载完成标识
// prdType: '', // 产品类型
// roles: '', // 角色权限类型
// group: '', // 设置全局 group
trainDetails: null // 列车详情显示
},
@ -207,12 +204,6 @@ const map = {
trainDetails: (state) => {
return state.trainDetails;
},
// prdType: (state) => {
// return state.prdType;
// },
// roles: (state) => {
// return state.roles;
// },
mapViewLoadedCount: (state) => {
return state.mapViewLoadedCount;
},
@ -329,7 +320,6 @@ const map = {
return [];
}
},
// 延时解锁倒计时列表
delayShowList: (state) => {
if (state.map) {
return state.map.delayShowList;
@ -337,15 +327,6 @@ const map = {
return [];
}
},
// 停车点列表
stopPointList: (state) => {
if (state.map) {
return state.map.stopPointList;
} else {
return [];
}
},
// 分割线列表
lineList: (state) => {
if (state.map) {
return state.map.lineList;
@ -353,7 +334,6 @@ const map = {
return [];
}
},
// 文字列表
textList: (state) => {
if (state.map) {
return state.map.textList;
@ -361,7 +341,6 @@ const map = {
return [];
}
},
// 车次窗列表
trainWindowList: (state) => {
if (state.map) {
return state.map.trainWindowList;
@ -369,7 +348,6 @@ const map = {
return [];
}
},
// 列车列表
trainList: (state) => {
if (state.map) {
return state.map.trainList;
@ -377,7 +355,6 @@ const map = {
return [];
}
},
// 列车模型
trainModelList: (state) => {
if (state.map) {
return state.map.trainModelList;
@ -385,36 +362,23 @@ const map = {
return [];
}
},
// 视图中的列车列表
viewTrainList: (state) => {
const trainList = [];
const trainLevel = Vue.$jlmap.getTrainView();
if (trainLevel) {
trainLevel.eachChild((viewGroup) => {
viewGroup.eachChild((train) => {
if (train && train._type === deviceType.Train) {
trainList.push(train.model);
}
}, this);
}, this);
}
return trainList;
// const trainList = [];
// const trainLevel = Vue.$jlmap.getTrainView();
// if (trainLevel) {
// trainLevel.eachChild((viewGroup) => {
// viewGroup.eachChild((train) => {
// if (train && train._type === deviceType.Train) {
// trainList.push(train.model);
// }
// }, this);
// }, this);
// }
// return trainList;
},
// 根据code获取设备
getDeviceByCode: (state) => (code) => {
if (state.map && state.map.deviceMap) {
return state.map.deviceMap[code];
} else {
return null;
}
},
// 根据code获取视图
getViewInstanceByDevice: (state) => (device) => {
if (Vue.$jlmap) {
return Vue.$jlmap.getViewInstanceByDevice(device);
}
return Vue.$jlmap || Vue.$jlmap.getDeviceByCode(code);
},
// 查询区段关联的计数器
@ -488,15 +452,6 @@ const map = {
setTrainDetails: (state, details) => {
state.trainDetails = details;
},
setPrdType: (state, prdType) => {
state.prdType = prdType;
},
setRoles: (state, roles) => {
state.roles = roles;
},
setGroup: (state, group) => {
state.group = group;
},
mapViewLoadedCountIncrement: (state) => {
state.mapViewLoadedCount += 1;
},
@ -588,18 +543,6 @@ const map = {
saveMapDeviceDefaultConvert(state);
},
// setPrdType: ({ commit }, prdType) => {
// commit('setPrdType', prdType);
// },
// setRoles: ({ commit }, roles) => {
// commit('setRoles', roles);
// },
// setGroup: ({ commit }, group) => {
// commit('setGroup', group);
// },
mapViewLoaded: ({ commit }) => {
commit('mapViewLoadedCountIncrement');
},

View File

@ -0,0 +1,558 @@
import Vue from 'vue';
import { TrainingMode } from '@/scripts/ConstDic';
// import OperateHandler from '@/scripts/plugin/trainingOperateHandler';
/**
* 实训状态数据
*/
const training = {
namespaced: true,
state: {
mode: null, // 模式
operatemode: null, // 操作模式 管理员/普通
started: false, // 是否开始
switchcount: 0, // 开关标识
basicInfo: {}, // 实训基本信息数据
offsetStationCode: '', // 偏移到车站
rezoomCount: 0, // 车站变更标识
steps: [], // 实训步骤数据
tempStep: {}, // 临时步骤数据(编辑模式)
order: -1, // 实训进行到第几步
orderCount: 0, // 步骤变更标识
operateErrMsg: '', // 操作错误提示信息
subscribeCount: 0, // 仿真订阅完成标识
score: 0, // 实训得分
usedTime: 0, // 实训所需时间
timeInterval: null, // 计时器
tipEvent: 0, // 提示刷新检测
operate: {}, // 操作model,
initTime: 0, // 当前系统时间
prdType: '', // 产品类型
roles: '', // 角色权限类型
group: '' // 设置全局 group
},
getters: {
tempStep: (state) => {
return state.tempStep;
},
steps: (state) => {
return state.steps;
},
order: (state) => {
return state.order;
},
offsetStationCode: (state) => {
return state.offsetStationCode;
},
basicInfo: (state) => {
return state.basicInfo;
},
mode: (state) => {
return state.mode;
},
operatemode: (state) => {
return state.operatemode;
},
started: (state) => {
return state.started;
},
score: (state) => {
return state.score;
},
usedTime: (state) => {
return state.usedTime;
},
tipEvent: (state) => {
return state.tipEvent;
},
initTime: (state) => {
return state.initTime;
},
prdType: (state) => {
return state.prdType;
},
roles: (state) => {
return state.roles;
},
// 视图中的列车列表
viewTrainList: (state) => {
// let trainList = [];
// if (state.jlmap && state.started) {
// let trainLevel = state.jlmap.getTrainView();
// if (trainLevel) {
// trainLevel.eachChild((viewGroup) => {
// viewGroup.eachChild((train) => {
// if (train && train._type === ModelType.Train) {
// trainList.push(train.model);
// }
// }, this);
// }, this);
// }
// }
// return trainList;
}
},
mutations: {
changeMode: (state, mode) => {
state.mode = mode;
},
changeOperateMode: (state, mode) => {
state.operatemode = mode;
},
start: (state) => {
state.started = true;
state.switchcount += 1;
},
over: (state) => {
state.started = false;
state.switchcount += 1;
},
setBasicInfo: (state, basicInfo) => {
state.basicInfo = basicInfo;
},
setOffsetStationCode: (state, offsetStationCode) => {
state.offsetStationCode = offsetStationCode || null;
if (state % 100 === 0) {
state.rezoomCount = 0;
} else {
state.rezoomCount += 1;
}
},
setSteps: (state, steps) => {
state.steps = steps;
},
addStep: (state, step) => {
state.steps.push(step);
},
next: (state) => {
state.order += 1;
state.orderCount += 1;
},
orderCountIncrement: (state) => {
state.orderCount += 1;
},
resetOrder: (state) => {
state.order = -1;
},
backOrder: (state, stepNum) => {
if (state.order > stepNum) {
state.order -= stepNum;
state.orderCount += 1;
}
},
setTempStep: (state, step) => {
state.tempStep = step;
},
setOperateErrMsg: (state, errMsg) => {
state.operateErrMsg = errMsg;
},
setHasSubscribed: (state) => {
state.subscribeCount++;
},
setScore: (state, score) => {
state.score = score;
},
resetScore: (state) => {
state.score = '';
},
tipEventIncrement: (state) => {
state.tipEvent++;
},
resetUsedTime: (state) => {
state.usedTime = 0;
},
countUsedTime: (state) => {
if (state.timeInterval) {
clearInterval(state.timeInterval);
state.timeInterval = null;
}
state.timeInterval = setInterval(() => {
state.usedTime++;
state.initTime += 1000;
}, 1000);
},
stopCountTime: (state) => {
if (state.timeInterval) {
clearInterval(state.timeInterval);
state.timeInterval = null;
}
},
setOperate: (state, operate) => {
state.operate = operate;
},
setInitTime: (state, operate) => {
state.initTime = operate;
},
setPrdType: (state, prdType) => {
state.prdType = prdType;
},
setRoles: (state, roles) => {
state.roles = roles;
},
setGroup: (state, group) => {
state.group = group;
}
},
actions: {
/**
* 清除仿真所在组
*/
clearSimulationGroup: ({ commit }, type) => {
commit('clearSimulationGroup', type);
},
/**
* 设置socke已经连接
*/
setHasSubscribed: ({ commit }) => {
commit('setHasSubscribed');
},
/**
* 模式变更
*/
changeMode: ({ commit }, opts) => {
commit('changeMode', opts.mode);
},
/**
* 操作模式变更
*/
changeOperateMode: ({ commit }, opts) => {
commit('changeOperateMode', opts.mode);
},
/**
* 重置实训状态
*/
reset: ({ commit }) => {
commit('over');
commit('resetOrder');
commit('stopCountTime');
// 清空计时器以及得分
commit('resetUsedTime');
commit('resetScore');
// 设置其他属性状态
commit('setOffsetStationCode', null);
},
/**
* 开始
*/
start: ({ commit }) => {
// 清空操作组
// OperateHandler.cleanOperates();
// 清空计时器以及得分
commit('stopCountTime');
commit('resetUsedTime');
commit('resetScore');
commit('start');
},
/**
* 结束
*/
over: ({ commit }) => {
commit('over');
commit('resetOrder');
commit('stopCountTime');
},
/**
* step步骤是否结束
*/
isStepOver: ({ state }) => {
if (state.order >= state.steps.length) {
return true;
}
},
/**
* 停止计时
*/
setStopCountTime: ({ commit }) => {
commit('stopCountTime');
},
/**
* 主动判断是否结束
*/
judgeFinish: ({ dispatch, commit, state }, rtn) => {
if (state.started) {
if (state.order >= state.steps.length) {
if (rtn && rtn.valid) {
commit('next');
commit('setOperateErrMsg', { errMsg: '操作正确!实训结束!', color: 'green' });
} else {
commit('setOperateErrMsg', { errMsg: '操作错误!实训结束!', color: 'red' });
}
dispatch('over');
dispatch('changeMode', { mode: null });
if (rtn.hasOwnProperty('score')) {
commit('setScore', rtn.score || 0);
}
} else {
rtn && rtn.valid && commit('next');
}
}
},
/**
* 开始实训模式变更和开始的混合操作
*/
startTraining: ({ commit }, opts) => {
commit('resetOrder');
commit('changeMode', opts.mode);
if (opts.start) {
// 清空计时器以及得分
commit('stopCountTime');
commit('resetUsedTime');
commit('resetScore');
// 开始实训
commit('start');
commit('next');
// 开始计时
commit('countUsedTime');
}
},
/**
* 开始实训模式变更和开始的混合操作
*/
backSteps: ({ commit }, stepNum) => {
if (Number.isInteger) {
commit('backOrder', stepNum);
}
},
/**
* 下一步
*/
next: ({ commit, state }, operate) => {
commit('setOperate', operate);
return new Promise((resolve, reject) => {
if (!state.started && !state.mode) {
commit('setOperateErrMsg', { errMsg: '请点击开始,开始实训!', color: 'red' });
return;
}
// 处理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);
// });
});
},
/**
* 提示消息重新加载
*/
tipReload: ({ commit }) => {
commit('orderCountIncrement');
},
/**
* 更新偏移位置车站
*/
updateOffsetStationCode: ({ commit }, payLoad) => {
commit('setOffsetStationCode', payLoad.offsetStationCode);
},
/**
* 设置实训数据
*/
setTrainingData: ({ commit }, trainingData) => {
const basicInfo = {
id: trainingData.id,
name: trainingData.name,
remarks: trainingData.remarks,
prdType: trainingData.prdType,
minDuration: trainingData.minDuration,
maxDuration: trainingData.maxDuration
};
commit('setBasicInfo', basicInfo);
const steps = trainingData.steps;
commit('setSteps', steps);
const offsetStationCode = trainingData.locateDeviceCode;
commit('setOffsetStationCode', offsetStationCode);
commit('setMapDefaultStatus');
},
/**
* 设置步骤数据
*/
setSteps: ({ commit }, steps) => {
commit('setSteps', steps);
},
/**
* 添加步骤数据
*/
addStep: ({ state, commit }, step) => {
return new Promise((resolve, reject) => {
try {
var valid = true;
const steps = state.steps;
if (steps && steps.length > 0) {
const last = steps.length - 1;
if (steps[last].type === step.type &&
steps[last].code === step.code &&
steps[last].operation === step.operation) {
steps.splice(last, 1);
step.order = step.order - 1;
valid = false;
}
}
commit('addStep', step);
resolve(valid);
} catch (error) {
reject(error);
}
});
},
/**
* 设置地图默认状态
*/
setMapDefaultState: ({ commit }) => {
Vue.$jlmap.setDefaultState();
},
/**
* 更新地图设备状态数据
*/
updateMapState: ({ commit, state }, deviceStatus) => {
Vue.$jlmap.update(deviceStatus);
},
/**
* 设置临时步骤数据
*/
setTempStep: ({ commit }, step) => {
commit('setTempStep', step);
},
/**
* 开始教学模式
*/
teachModeStart: ({ dispatch }, mode) => {
const payLoad = { start: true, mode: mode };
dispatch('startTraining', payLoad);
},
/**
* 开始考试模式
*/
examModeStart: ({ dispatch }) => {
const payLoad = { start: true, mode: TrainingMode.EXAM };
dispatch('startTraining', payLoad);
},
/**
* 仿真和大屏和计划模式
*/
simulationStart: ({ dispatch }) => {
const payLoad = { start: true, mode: TrainingMode.NORMAL };
dispatch('startTraining', payLoad);
},
/**
* 结束模式
*/
end: ({ commit }, mode) => {
commit('over');
commit('resetOrder');
commit('stopCountTime');
commit('changeMode', mode);
},
/**
* 是否教学模式
*/
isTeachMode: ({ state }) => {
return new Promise((resolve, reject) => {
if (state.mode === TrainingMode.TEACH) {
resolve();
} else {
reject(new Error('not teach mode'));
}
});
},
/**
* 设置用户得分
*/
setScore: ({ commit }, score) => {
commit('setScore', score);
},
/**
* 设置tip变化事件
*/
emitTipFresh: ({ commit }) => {
commit('tipEventIncrement');
},
/**
* 设置WebSocket链接状态
*/
setConnected: ({ commit }, isConnected) => {
commit('setConnected', isConnected);
},
/**
* 设置系统时间
*/
setInitTime: ({ commit }, initTime) => {
commit('setInitTime', initTime);
},
/**
* 设置产品类型
*/
setPrdType: ({ commit }, prdType) => {
commit('setPrdType', prdType);
},
/**
* 设置角色列表
*/
setRoles: ({ commit }, roles) => {
commit('setRoles', roles);
},
/**
* 设置仿真组
*/
setGroup: ({ commit }, group) => {
commit('setGroup', group);
}
}
};
export default training;

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

@ -1,282 +1,284 @@
<template>
<div class="jlmap-canvas" :style="{ width: width+'px', height: height+28+'px' }">
<div :id="canvasId" style="background: #000;" />
<progress-bar ref="progressBar" />
<zoom-box :scale-rate="dataZoom.scaleRate" v-if="!isScreen" @setShrink="setShrink" @setMagnify="setMagnify" />
<div v-if="show" class="zoom-view" :style="{ width: width +'px'}">
<el-form :model="dataZoom" label-width="60px" size="mini" inline>
<el-form-item label="偏移:">
<el-input v-model="dataZoom.offsetX" :disabled="true" />
</el-form-item>
<el-form-item>
<el-input v-model="dataZoom.offsetY" :disabled="true" />
</el-form-item>
<el-form-item label="缩放:" style="float: right">
<el-input v-model="dataZoom.scaleRate" :disabled="true" />
</el-form-item>
</el-form>
<div class="jlmap-canvas" :style="{ width: width+'px', height: height+28+'px' }">
<div :id="canvasId" style="background: #000;"></div>
<progress-bar ref="progressBar" ></progress-bar>
<zoom-box @setShrink="setShrink" @setMagnify="setMagnify" :scaleRate="dataZoom.scaleRate" v-if="!isScreen"></zoom-box>
<div v-if="show" class="zoom-view" :style="{ width: width +'px'}">
<el-form :model="dataZoom" label-width="60px" size="mini" inline>
<el-form-item label="偏移:">
<el-input v-model="dataZoom.offsetX" :disabled="true"></el-input>
</el-form-item>
<el-form-item>
<el-input v-model="dataZoom.offsetY" :disabled="true"></el-input>
</el-form-item>
<el-form-item label="缩放:" style="float: right">
<el-input v-model="dataZoom.scaleRate" :disabled="true"></el-input>
</el-form-item>
</el-form>
</div>
</div>
</div>
</template>
<script>
import Vue from 'vue';
import localStore from 'storejs';
import Jlmap from '@/jmap/map';
import ZoomBox from './zoom/zoom';
import ProgressBar from '@/views/components/progressBar/index';
// import { mapGetters } from 'vuex';
// import { Loading } from 'element-ui';
import Vue from 'vue';
import localStore from 'storejs';
import Jlmap from '@/jmap/map';
import ZoomBox from './zoom/zoom';
import ProgressBar from '@/views/components/progressBar/index';
import { mapGetters } from 'vuex';
import { TrainingMode } from '@/scripts/ConstDic';
import { Loading } from 'element-ui';
export default {
name: 'JlmapVisual',
components: {
ZoomBox,
ProgressBar
},
data() {
return {
width: this.$store.state.config.width,
height: this.$store.state.config.height,
loading: true,
dataZoom: {
offsetX: '0',
offsetY: '0',
scaleRate: '1'
},
sectionActive: false,
operate: null
};
},
computed: {
// ...mapGetters('training', [
// 'mode',
// 'offsetStationCode'
// ]),
canvasId() {
const canvasId = ['map', (Math.random().toFixed(5)) * 100000].join('_');
this.$store.dispatch('config/setCurrentCancasId', { id: canvasId });
return canvasId;
},
show() {
// if (this.mode === TrainingMode.EDIT || this.mode === TrainingMode.MAP_EDIT) {
// return true;
// }
// return false;
return true;
},
isScreen() {
return this.$route.params.mode === 'dp';
}
},
watch: {
'$store.state.map.map': function (val, old) {
if (val && val.skinStyle) {
try {
this.setMap(val);
} catch (error) {
console.log(error);
}
}
},
'$store.state.training.rezoomCount': function (val, old) {
this.setShowCenter(this.$store.state.training.offsetStationCode);
},
'$store.state.config.canvasSizeCount': function (val) {
this.resetSize();
},
'$store.state.menuOperation.magnifyCount': function () {
this.setMagnify();
},
'$store.state.menuOperation.shrinkCount': function () {
this.setShrink();
},
$route() {
this.mapViewLoaded(true);
}
},
created() {
// eventBus.$on('viewLoading', (loading) => {
// this.mapViewLoaded(loading)
// });
// eventBus.$on('viewProgressAt', (percentage) => {
// this.mapViewProgressAt(percentage);
// });
// eventBus.$on('refresh', () => {
// this.refresh(this.$store.state.map.map);
// })
},
mounted() {
this.initLoadPage();
},
beforeDestroy() {
// eventBus.$off('refresh');
// eventBus.$off('viewLoading');
// eventBus.$off('viewProgressAt');
if (this.$jlmap) {
this.$jlmap.dispose();
}
},
methods: {
// jlmap
initLoadPage() {
document.getElementById(this.canvasId).oncontextmenu = function (e) {
return false;
};
export default {
name: 'JlmapVisual',
components: {
ZoomBox,
ProgressBar
},
data() {
return {
width: this.$store.state.config.width,
height: this.$store.state.config.height,
loading: true,
dataZoom: {
offsetX: '0',
offsetY: '0',
scaleRate: '1'
},
sectionActive: false,
operate: null,
}
},
computed: {
...mapGetters('training', [
'mode',
'offsetStationCode'
]),
canvasId() {
const canvasId = ['map', (Math.random().toFixed(5)) * 100000].join('_');
this.$store.dispatch('config/setCurrentCancasId', { id: canvasId });
return canvasId;
},
show() {
if (this.mode === TrainingMode.EDIT || this.mode === TrainingMode.MAP_EDIT) {
return true;
}
return false;
return true;
},
isScreen() {
return this.$route.params.mode === 'dp'
}
},
watch: {
'$store.state.map.map': function (val, old) {
if (val && val.skinStyle) {
try {
this.setMap(val);
} catch (error) {
this.mapViewLoaded(false);
console.log(error);
}
} else {
this.mapViewLoaded(false);
}
},
'$store.state.training.rezoomCount': function (val, old) {
this.setShowCenter(this.$store.state.training.offsetStationCode);
},
'$store.state.config.canvasSizeCount': function (val) {
this.resetSize();
},
'$store.state.menuOperation.magnifyCount': function () {
this.setMagnify();
},
'$store.state.menuOperation.shrinkCount': function () {
this.setShrink();
},
$route() {
this.mapViewLoaded(true);
}
},
created() {
// eventBus.$on('viewLoading', (loading) => {
// this.mapViewLoaded(loading)
// });
// eventBus.$on('viewProgressAt', (percentage) => {
// this.mapViewProgressAt(percentage);
// });
// eventBus.$on('refresh', () => {
// this.refresh(this.$store.state.map.map);
// })
},
mounted() {
this.initLoadPage();
},
beforeDestroy() {
// eventBus.$off('refresh');
// eventBus.$off('viewLoading');
// eventBus.$off('viewProgressAt');
if (this.$jlmap) {
this.$jlmap.dispose();
}
},
methods: {
// jlmap
initLoadPage() {
const dom = document.getElementById(this.canvasId).oncontextmenu = function (e) {
return false;
};
Vue.prototype.$jlmap = new Jlmap({
dom: document.getElementById(this.canvasId),
config: {
renderer: 'canvas',
width: this.width,
height: this.height
},
options: {
scaleRate: 1,
offsetX: 0,
offsetY: 0
},
methods: {
dataLoaded() {
console.log('dataLoaded');
},
viewLoaded() {
console.log('viewLoaded');
this.mapViewLoaded(true);
},
stateLoaded() {
},
viewUpdate() {
console.log('viewUpdate');
},
stateUpdate() {
console.log('stateUpdate');
},
optionsUpdate() { console.log('optionsUpdate'); }
}
});
Vue.prototype.$jlmap = new Jlmap({
dom: document.getElementById(this.canvasId),
config: {
renderer: 'canvas',
width: this.width,
height: this.height
},
options: {
scaleRate: 1,
offsetX: 0,
offsetY: 0
},
methods: {
dataLoaded() {
console.log('dataLoaded');
},
viewLoaded() {
console.log('viewLoaded');
this.mapViewLoaded(true);
},
stateLoaded() {
},
viewUpdate() {
console.log('viewUpdate');
},
stateUpdate() {
console.log('stateUpdate');
},
optionsUpdate() { console.log('optionsUpdate'); }
}
});
this.$jlmap.on('datazoom', this.onDataZoom, this);
this.$jlmap.on('selected', this.onSelected, this);
this.$jlmap.on('contextmenu', this.onContextMenu, this);
this.$jlmap.on('datazoom', this.onDataZoom, this);
this.$jlmap.on('selected', this.onSelected, this);
this.$jlmap.on('contextmenu', this.onContextMenu, this);
window.document.oncontextmenu = function () {
return false;
}
},
// jlmap
resetSize() {
this.$nextTick(() => {
this.width = this.$store.state.config.width;
this.height = this.$store.state.config.height;
window.document.oncontextmenu = function () {
return false;
};
},
// jlmap
resetSize() {
this.$nextTick(() => {
this.width = this.$store.state.config.width;
this.height = this.$store.state.config.height;
this.$jlmap && this.$jlmap.resize({ width: this.width, height: this.height });
if (this.$jlmap) {
this.$jlmap.resize({ width: this.width, height: this.height });
}
this.$store.dispatch('training/updateOffsetStationCode', { offsetStationCode: this.offsetStationCode });
// this.$store.dispatch('training/updateOffsetStationCode', { offsetStationCode: this.offsetStationCode });
setTimeout(() => {
this.$store.dispatch('config/resetCanvasOffset');
this.$store.dispatch('training/emitTipFresh');
}, 100);
});
},
//
setShowLevel(level) {
if (this.$jlmap) {
console.log('设置显示图层');
// this.$jlmap.setShowLevel(level);
}
},
// Level
setShowLogicalLevel(levels) {
if (this.$jlmap) {
console.log('设置逻辑视图Level');
// this.$jlmap.setShowLogicalLevel(levels);
}
},
// Level
setShowPhysicalLevel(levels) {
if (this.$jlmap) {
onsole.log('设置物理视图Level');
// this.$jlmap.setShowPhysicalLevel(levels);
}
},
//
setShowCenter(deviceCode) {
if (this.$jlmap) {
this.$jlmap.setCenter(deviceCode);
}
},
//
onDataZoom(dataZoom) {
this.dataZoom.offsetX = dataZoom._offsetX.toFixed(1) + '';
this.dataZoom.offsetY = dataZoom._offsetY.toFixed(1) + '';
this.dataZoom.scaleRate = dataZoom._scaleRate + '';
// setTimeout(() => {
// this.$store.dispatch('config/resetCanvasOffset');
// this.$store.dispatch('training/emitTipFresh');
// }, 100);
});
},
//
setShowLevel(level) {
if (this.$jlmap) {
console.log('设置显示图层');
// this.$jlmap.setShowLevel(level);
}
},
// Level
setShowLogicalLevel(levels) {
if (this.$jlmap) {
console.log('设置逻辑视图Level');
// this.$jlmap.setShowLogicalLevel(levels);
}
},
// Level
setShowPhysicalLevel(levels) {
if (this.$jlmap) {
console.log('设置物理视图Level');
// this.$jlmap.setShowPhysicalLevel(levels);
}
},
//
setShowCenter(deviceCode) {
if (this.$jlmap) {
this.$jlmap.setCenter(deviceCode);
}
},
//
onDataZoom(dataZoom) {
this.dataZoom.offsetX = dataZoom._offsetX.toFixed(1) + '';
this.dataZoom.offsetY = dataZoom._offsetY.toFixed(1) + '';
this.dataZoom.scaleRate = dataZoom._scaleRate + '';
let skinStyle = this.$store.state.map.map.skinStyle;
if (skinStyle) {
let param = {
scaleRate: this.dataZoom.scaleRate,
skinCode: skinStyle,
offsetY: this.dataZoom.offsetY,
}
const skinStyle = this.$store.state.map.map.skinStyle;
if (skinStyle) {
const param = {
scaleRate: this.dataZoom.scaleRate,
skinCode: skinStyle,
offsetY: this.dataZoom.offsetY
};
localStore.set(`scaleRate_${skinStyle}`, JSON.stringify(param)); //
}
localStore.set(`scaleRate_${skinStyle}`, JSON.stringify(param)); //
}
this.$store.dispatch('map/updateZoom', this.dataZoom);
this.$store.dispatch('training/emitTipFresh');
},
//
onSelected(em) {
this.$emit('onSelect', em);
},
//
onContextMenu(em) {
this.$emit('onMenu', em);
},
//
mapViewLoaded(loading) {
this.loading = loading;
if (loading) {
this.$refs.progressBar.start();
} else {
this.$refs.progressBar.end(true);
}
},
//
mapViewProgressAt(percentage) {
this.$nextTick(() => {
this.$refs.progressBar.progressAt(percentage);
});
},
//
setMap(map) {
this.$jlmap.setMap(map);
},
//
refresh(map) {
},
//
addOrUpdateDevices(devices) {
this.$jlmap.render(devices);
},
//
deleteDevices(devices) {
this.$jlmap.render(devices);
},
//
setShrink() {
this.$jlmap.setOptions({scale: -1});
},
//
setMagnify() {
this.$jlmap.setOptions({scale: 1});
}
}
};
this.$store.dispatch('map/updateZoom', this.dataZoom);
this.$store.dispatch('training/emitTipFresh');
},
//
onSelected(em) {
this.$emit('onSelect', em);
},
//
onContextMenu(em) {
this.$emit('onMenu', em);
},
//
mapViewLoaded(loading) {
this.loading = loading;
if (loading) {
this.$refs.progressBar.start();
} else {
this.$refs.progressBar.end(true);
}
},
//
mapViewProgressAt(percentage) {
this.$nextTick(() => {
this.$refs.progressBar.progressAt(percentage);
});
},
//
setMap(map) {
this.$jlmap.setMap(map);
},
//
refresh(map) {
},
//
addOrUpdateDevices(devices) {
this.$jlmap.render(devices);
},
//
deleteDevices(devices) {
this.$jlmap.render(devices);
},
//
setShrink() {
this.$jlmap.setOptions({scale: -1});
},
//
setMagnify() {
this.$jlmap.setOptions({scale: 1});
}
}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.jlmap-canvas {