From db00d3e054ac57acff21274ce31e6c0c57bed242 Mon Sep 17 00:00:00 2001 From: xianfuxing Date: Mon, 27 Aug 2018 22:25:17 +0800 Subject: [PATCH] =?UTF-8?q?#=20up=20map=20=E5=88=A4=E6=96=AD=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E6=9D=A5=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/getters.js | 3 ++- src/store/modules/counter.js | 11 +++++++++-- src/views/counter/device.vue | 9 +++++++-- src/views/counter/map.vue | 37 ++++++++++++++++++++++++++---------- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/store/getters.js b/src/store/getters.js index 5742ea5..c2aaec0 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -14,6 +14,7 @@ const getters = { permission_routers: state => state.permission.routers, addRouters: state => state.permission.addRouters, errorLogs: state => state.errorLog.logs, - deviceID: state => state.counter.deviceID + deviceID: state => state.counter.deviceID, + mapClick: state => state.counter.mapClick } export default getters diff --git a/src/store/modules/counter.js b/src/store/modules/counter.js index b788947..26b63e6 100644 --- a/src/store/modules/counter.js +++ b/src/store/modules/counter.js @@ -1,16 +1,23 @@ const counter = { state: { - deviceID: '868575028779793' + deviceID: '868575028779793', + mapClick: false }, mutations: { CHANGE_DEVICE_ID: (state, deviceID) => { state.deviceID = deviceID localStorage.deviceID = deviceID + }, + CHANGE_MAP_CLICK: (state, mapClick) => { + state.mapClick = mapClick } }, actions: { - chnageDeviceID({ commit }, deviceID) { + changeDeviceID({ commit }, deviceID) { commit('CHANGE_DEVICE_ID', deviceID) + }, + changeMapClick({ commit }, mapClick) { + commit('CHANGE_MAP_CLICK', mapClick) } } } diff --git a/src/views/counter/device.vue b/src/views/counter/device.vue index b99a198..cbb1847 100644 --- a/src/views/counter/device.vue +++ b/src/views/counter/device.vue @@ -142,7 +142,7 @@ export default { }, handleDetailClick(deviceID) { // console.log(deviceID) - this.$store.dispatch('chnageDeviceID', deviceID).then(() => { + this.$store.dispatch('changeDeviceID', deviceID).then(() => { this.$router.push('/counter/detail') }).catch(() => { console.log('Err: get device_id failed in device page') @@ -150,7 +150,12 @@ export default { }, handleMapClick(deviceID) { // console.log(deviceID) - this.$store.dispatch('chnageDeviceID', deviceID).then(() => { + this.$store.dispatch('changeMapClick', true).then(() => { + console.log('go to map') + }).catch(() => { + console.log('Err: click map failed') + }) + this.$store.dispatch('changeDeviceID', deviceID).then(() => { this.$router.push('/counter/map') }).catch(() => { console.log('Err: get device_id failed in device page') diff --git a/src/views/counter/map.vue b/src/views/counter/map.vue index 3fd7354..f7eecb5 100644 --- a/src/views/counter/map.vue +++ b/src/views/counter/map.vue @@ -54,6 +54,12 @@ export default { }] } }, + // beforeRouteEnter(to, from, next) { + // next(vm => { + // vm.url = from.path + // console.log(from.path) + // }) + // }, methods: { getDevices(params) { fetchDeviceList(params).then(response => { @@ -68,17 +74,28 @@ export default { }) } }, + watch: { + '$route'(to, from) { + console.log(from) + } + }, created() { - const device_id = this.$store.getters.deviceID - this.getDevices({ device_id }) - this.defaultPositions.forEach((item, index) => { - const entry = {} - entry.position = item.position - entry.events = defaultEvents - entry.visible = true - entry.draggable = false - this.markers.push(entry) - }) + const mapClick = this.$store.getters.mapClick + if (mapClick) { + const device_id = this.$store.getters.deviceID + console.log(device_id) + this.getDevices({ device_id }) + } else { + this.defaultPositions.forEach((item, index) => { + const entry = {} + entry.position = item.position + entry.events = defaultEvents + entry.visible = true + entry.draggable = false + this.markers.push(entry) + }) + this.flag = true + } } }