diff --git a/ruoyi-ui/src/components/BoardTopNav/index.vue b/ruoyi-ui/src/components/BoardTopNav/index.vue index bb66e5a..2f9f452 100644 --- a/ruoyi-ui/src/components/BoardTopNav/index.vue +++ b/ruoyi-ui/src/components/BoardTopNav/index.vue @@ -55,7 +55,7 @@ export default { selectSecnesList: [], name: '智慧场景', isIndex: true, - sceneId: 0, + sceneId: this.$store.getters.sceneId, } }, props: { @@ -66,6 +66,11 @@ export default { }, async mounted() { + + if (this.$route.name === 'SmartScene' || this.$route.name === 'GPS' || this.$route.name === 'index' || this.$store.getters.sceneId) { + }else{ + await this.$router.replace({path: "/board/index"}); + } await this.setSelectSecnes() if (this.$route.name === 'SmartScene' || this.$route.name === 'GPS') { if (this.$route.query?.name) { @@ -83,31 +88,35 @@ export default { } else { this.isIndex = false } + }, methods: { async setSelectSecnes() { const {data} = await selectSecnes() this.selectSecnesList = data - if (!this.$route.query.name) { + if (!this.$store.getters.sceneId) { this.sceneId = data.find(e => e.defaultFlag === '1').sceneId - }else{ + } + if (this.$route.query.name) { this.sceneId = data.find(e => e.sceneName === this.$route.query.name).sceneId } this.$emit('sceneIdChange', this.sceneId); + await this.$store.dispatch('app/setSceneId', this.sceneId) }, // sceneIdChange(){ // // }, toLink(e) { - this.$router.push({path: "/board/" + e}); + this.$router.replace({path: "/board/" + e}); }, dropdownLink(e) { - this.name = e.name this.$emit('sceneIdChange', e.sceneId); - this.$router.push({path: "/board/" + (e.router || 'smartScene'), query: {name: e.name}}); + this.name = e.name + this.$store.dispatch('app/setSceneId', e.sceneId) + this.$router.replace({path: "/board/" + (e.router || 'smartScene'), query: {name: e.name}}); }, toIndex() { - this.$router.push({path: "/index"}); + this.$router.replace({path: "/index"}); } } }; diff --git a/ruoyi-ui/src/store/getters.js b/ruoyi-ui/src/store/getters.js index 3115cb5..03a5d08 100644 --- a/ruoyi-ui/src/store/getters.js +++ b/ruoyi-ui/src/store/getters.js @@ -16,5 +16,6 @@ const getters = { defaultRoutes:state => state.permission.defaultRoutes, sidebarRouters:state => state.permission.sidebarRouters, language: state => state.app.language, + sceneId: state => state.app.sceneId, } export default getters diff --git a/ruoyi-ui/src/store/modules/app.js b/ruoyi-ui/src/store/modules/app.js index 0f3c1e7..09a384a 100644 --- a/ruoyi-ui/src/store/modules/app.js +++ b/ruoyi-ui/src/store/modules/app.js @@ -8,7 +8,8 @@ const state = { }, device: 'desktop', size: Cookies.get('size') || 'medium', - language: Cookies.get('language') || 'en_US' + language: Cookies.get('language') || 'en_US', + sceneId:0 } const mutations = { @@ -42,6 +43,9 @@ const mutations = { SET_LANGUAGE: (state, language) => { state.language = language Cookies.set('language', language) + }, + SET_SCENEID:(state,sceneId) =>{ + state.sceneId = sceneId } } @@ -64,6 +68,10 @@ const actions = { }, setLanguage({ commit }, language) { commit('SET_LANGUAGE', language) + }, + + setSceneId({ commit }, sceneId) { + commit('SET_SCENEID', sceneId) } } diff --git a/ruoyi-ui/src/views/board/GPS/index.vue b/ruoyi-ui/src/views/board/GPS/index.vue index fef8c7c..d1b61ea 100644 --- a/ruoyi-ui/src/views/board/GPS/index.vue +++ b/ruoyi-ui/src/views/board/GPS/index.vue @@ -220,7 +220,7 @@ export default { map.setFitView() }, async getAlarmStats() { - const {data} = await alarmStats(this.sceneId) + const {data} = await alarmStats(this.$store.getters.sceneId) let option1 = { ...this.chart1Option, yAxis: { @@ -268,7 +268,7 @@ export default { this.$refs.chart1.setData(option1) }, async getAubDevice() { - let data = await subDevice(this.sceneId) + let data = await subDevice(this.$store.getters.sceneId) this.num1 = data.deviceNum this.num2 = data.subSum this.num3 = data.onlineDeviceNum @@ -285,7 +285,7 @@ export default { }) }, async setElectronicNumVo() { - const {data} = await ElectronicNumVo(this.sceneId) + const {data} = await ElectronicNumVo(this.$store.getters.sceneId) data.forEach(e => { if (e.areaPoints?.length > 0) { this.setPolygon(e.areaPoints) diff --git a/ruoyi-ui/src/views/board/equipment/index.vue b/ruoyi-ui/src/views/board/equipment/index.vue index 31dd6a4..f0c7246 100644 --- a/ruoyi-ui/src/views/board/equipment/index.vue +++ b/ruoyi-ui/src/views/board/equipment/index.vue @@ -1,7 +1,7 @@