From 09af7d91b4cb335f3802b61cdcb1c2b212913274 Mon Sep 17 00:00:00 2001 From: ival <610568032@qq.com> Date: Tue, 19 Nov 2019 16:41:21 +0800 Subject: [PATCH 1/4] =?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/CommandHandler.js | 52 ++++++++++++++++++--------- src/scripts/plugin/OperateHandler2.js | 5 ++- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/scripts/plugin/CommandHandler.js b/src/scripts/plugin/CommandHandler.js index 62c939466..9c5259656 100644 --- a/src/scripts/plugin/CommandHandler.js +++ b/src/scripts/plugin/CommandHandler.js @@ -1,3 +1,4 @@ +import { MapDeviceType } from '@/scripts/ConstDic'; import { sendCommand } from '@/api/jmap/training'; import router from '@/router'; @@ -5,24 +6,46 @@ class CommandHandle { constructor() { this.data = []; this.instructionMap = { - + 1: { + type: MapDeviceType.Signal.type, + operation: 1 + }, + 2: { + type: MapDeviceType.Signal.type, + operation: 2 + }, + 8: { + type: MapDeviceType.StationStand.type, + operation: 8 + } }; } - getInstruction(operation) { - return this.instructionMap[operation] || {}; + getInstruction(operate) { + return this.instructionMap[operate.commandType.value] || {}; } getCommand(operates) { const operate = operates[operates.length - 1] || {}; - if (operate && operate.instructionType) { - const instruction = this.getInstruction(operate.instructionType); + if (operate && operate.commandType) { + const instruction = this.getInstruction(operate); if (instruction) { - return { + const command = { ...instruction, - paramList: this.getParamsList(operates), + code: operate.code, + val: operate.val, over: operate.over }; + + if (!command.code) { + operates.forEach(elem => { + if (elem.code) { + command.code = elem.code; + } + }); + } + + return command; } else { return { error: true }; } @@ -34,16 +57,11 @@ class CommandHandle { execute(command) { return new Promise((resolve, reject) => { const group = router.currentRoute.query.group; - if (command) { - sendCommand(group, command).then((response) => { - resolve(response); - }).catch(error => { - reject(error); - }); - } else { - reject(); - } - + sendCommand(group, command).then((response) => { + resolve(response); + }).catch(error => { + reject(error); + }); }); } } diff --git a/src/scripts/plugin/OperateHandler2.js b/src/scripts/plugin/OperateHandler2.js index f9f5fa3d7..0e5eb4522 100644 --- a/src/scripts/plugin/OperateHandler2.js +++ b/src/scripts/plugin/OperateHandler2.js @@ -10,7 +10,6 @@ import LangStorage from '@/utils/lang'; class OperateHandler { constructor() { this.operates = []; // 操作数据 - this.command = {}; // 命令对象 } /** 操作组 */ @@ -136,11 +135,11 @@ class OperateHandler { return new Promise((resolve, reject) => { const rtn = { valid: false, response: null }; const valid = this.validate(operate); + const command = this.getCommand(operate); rtn.valid = valid; - if (valid) { - const command = this.getCommand(operate); + if (valid && command) { CommandHandler.execute(command).then(response => { rtn.response = response; resolve(rtn); From 13a5df8571babed030ca747f8748483aec12281d Mon Sep 17 00:00:00 2001 From: joylink_cuiweidong <364937672@qq.com> Date: Tue, 19 Nov 2019 17:06:13 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jmap/theme/fuzhou_01/menus/menuSignal.vue | 9 ++- src/scripts/plugin/CommandHandler.js | 13 +++- src/scripts/plugin/MenuContextHandler.js | 62 +++++++++++++++++++ src/views/display/designIndex.vue | 6 -- 4 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 src/scripts/plugin/MenuContextHandler.js diff --git a/src/jmap/theme/fuzhou_01/menus/menuSignal.vue b/src/jmap/theme/fuzhou_01/menus/menuSignal.vue index 0da44ea60..60a3a22dc 100644 --- a/src/jmap/theme/fuzhou_01/menus/menuSignal.vue +++ b/src/jmap/theme/fuzhou_01/menus/menuSignal.vue @@ -24,7 +24,9 @@ import Commands from '@/scripts/plugin/Commands'; import { mapGetters } from 'vuex'; import { OperateMode } from '@/scripts/ConstDic'; import { MapDeviceType, OperationEvent, DeviceMenu } from '@/scripts/ConstDic'; +// 开关 import { MenuDisabledState, menuConvert, menuFiltration } from './utils/menuItemStatus'; +import MenuContextHandler from '@/scripts/plugin/MenuContextHandler'; export default { name: 'SignalMenu', @@ -222,7 +224,8 @@ export default { }, initMenu() { // 编辑模式菜单列表 - this.menu = menuFiltration(this.menuNormal); + this.menu = MenuContextHandler.menuFiltration(this.menuNormal); + // this.menu = menuFiltration(this.menuNormal); if (this.operatemode === OperateMode.ADMIN) { this.menu = [...this.menu, ...this.menuForce]; } @@ -232,7 +235,9 @@ export default { this.menu = this.menuForce; } - this.menu = menuConvert(this.menu); + debugger; + this.menu = MenuContextHandler.covert(this.menu); + // this.menu = menuConvert(this.menu); }, doShow(point) { diff --git a/src/scripts/plugin/CommandHandler.js b/src/scripts/plugin/CommandHandler.js index 62c939466..c63b336d8 100644 --- a/src/scripts/plugin/CommandHandler.js +++ b/src/scripts/plugin/CommandHandler.js @@ -5,7 +5,14 @@ class CommandHandle { constructor() { this.data = []; this.instructionMap = { - + // Signal: { + // FALT: { + // commandType: 'FALT', + // disabledList: [ + // {name: 'states', code: '02', operate: 'eq'} + // ] + // } + // } }; } @@ -31,6 +38,10 @@ class CommandHandle { return null; } + checkDisabled(menu, selected) { + + } + execute(command) { return new Promise((resolve, reject) => { const group = router.currentRoute.query.group; diff --git a/src/scripts/plugin/MenuContextHandler.js b/src/scripts/plugin/MenuContextHandler.js new file mode 100644 index 000000000..8fe5f9730 --- /dev/null +++ b/src/scripts/plugin/MenuContextHandler.js @@ -0,0 +1,62 @@ +import store from '@/store'; +class MenuContextHandler { + constructor() { + this.operates = []; // 操作数据 + this.command = {}; // 命令对象 + } + + getCurrentStateObject() { + return store.getters['menuOperation/selected']; + } + + menuFiltration(menuList) { + const SystemType = { + '01': 'local', // 现地工作站 + '02': 'central' // 中心调度工作站 + }; + + const StationControlType = { + '01': 'center', // 中控 + '02': 'station', // 站控 + '03': 'station' + }; + + var selected = this.getCurrentStateObject(); + let control; + var menu = []; + + if (selected._type == 'StationStand') { + control = store.getters['map/getStationControlByStationCode'](selected.deviceStationCode); + } else if (selected._type == 'Station') { + control = store.getters['map/getStationControlByStationCode'](selected.code); + } else { + control = store.getters['map/getStationControlByStationCode'](selected.stationCode); + } + if (control) { + if (store.state.training.prdType != '') { + const type = SystemType[store.state.training.prdType]; + const status = StationControlType[control.status]; + menu = [...menuList[type]]; + if (menu.constructor === Array) { + menu.forEach(elem => { + if (elem.type === 'separator') { + elem.show = true; + return; + } + + if (elem.auth.constructor === Object) { + elem.show = true; + if (!elem.auth['station'] && !elem.auth['center']) { // 控制不显示 + elem.show = false; + } + elem.defaultDisabled = !elem.auth[status]; + } + }); + } + } + } + return menu; + } +} + +export default new MenuContextHandler(); diff --git a/src/views/display/designIndex.vue b/src/views/display/designIndex.vue index 3d08a026c..b4fac786b 100644 --- a/src/views/display/designIndex.vue +++ b/src/views/display/designIndex.vue @@ -37,12 +37,6 @@ @switchMode="switchMode" @selectQuest="selectQuest" /> - From bd2744f567c2dd919b46b44e7c573e8f192785dc Mon Sep 17 00:00:00 2001 From: joylink_cuiweidong <364937672@qq.com> Date: Tue, 19 Nov 2019 17:42:36 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/router/index.js b/src/router/index.js index 0bc95fd84..e4b0d0ffa 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -876,4 +876,10 @@ router.beforeEach((to, from, next) => { next(); }); +// 兼容 vue-router在3.1.0版本以上的路由跳转使用的是 promise 的方式 +const originalPush = Router.prototype.push; +Router.prototype.push = function push(location) { + return originalPush.call(this, location).catch(err => err); +}; + export default router; From 096a848024b3fdfe0cb80b57ebc758c61271079e Mon Sep 17 00:00:00 2001 From: joylink_cuiweidong <364937672@qq.com> Date: Tue, 19 Nov 2019 17:48:33 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jmap/theme/fuzhou_01/menus/menuSignal.vue | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/jmap/theme/fuzhou_01/menus/menuSignal.vue b/src/jmap/theme/fuzhou_01/menus/menuSignal.vue index 60a3a22dc..4422ccd7e 100644 --- a/src/jmap/theme/fuzhou_01/menus/menuSignal.vue +++ b/src/jmap/theme/fuzhou_01/menus/menuSignal.vue @@ -26,7 +26,7 @@ import { OperateMode } from '@/scripts/ConstDic'; import { MapDeviceType, OperationEvent, DeviceMenu } from '@/scripts/ConstDic'; // 开关 import { MenuDisabledState, menuConvert, menuFiltration } from './utils/menuItemStatus'; -import MenuContextHandler from '@/scripts/plugin/MenuContextHandler'; +// import MenuContextHandler from '@/scripts/plugin/MenuContextHandler'; export default { name: 'SignalMenu', @@ -224,8 +224,8 @@ export default { }, initMenu() { // 编辑模式菜单列表 - this.menu = MenuContextHandler.menuFiltration(this.menuNormal); - // this.menu = menuFiltration(this.menuNormal); + // this.menu = MenuContextHandler.menuFiltration(this.menuNormal); + this.menu = menuFiltration(this.menuNormal); if (this.operatemode === OperateMode.ADMIN) { this.menu = [...this.menu, ...this.menuForce]; } @@ -235,9 +235,9 @@ export default { this.menu = this.menuForce; } - debugger; - this.menu = MenuContextHandler.covert(this.menu); - // this.menu = menuConvert(this.menu); + // debugger; + // this.menu = MenuContextHandler.covert(this.menu); + this.menu = menuConvert(this.menu); }, doShow(point) {