From c6764c9e2e7416d0fa4f704322c6d9cc9b94a0bd Mon Sep 17 00:00:00 2001 From: oldHome Date: Wed, 4 Jun 2025 00:29:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0vuex=20=E7=A6=81=E9=A3=9E?= =?UTF-8?q?=E5=8C=BA=E6=95=B0=E6=8D=AE=20=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/index.js | 20 +++++++++++ .../layout/components/main/nofly/set.vue | 33 +------------------ src/views/layout/index.vue | 1 + 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/store/index.js b/src/store/index.js index b18c0b6..ffd5060 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -17,6 +17,7 @@ const store = new Vuex.Store({ airList: [], // 所有飞机列表 siteList: [], // 站点列表 routeList: [], // 航线列表 + noflyData: [], // 禁飞区数据 categoryList: [], // 分类列表(小程序) spuList: [], // 商品spu列表 skuList: [], // 商品sku列表 @@ -64,6 +65,12 @@ const store = new Vuex.Store({ setRouteList (state, list) { state.routeList = list }, + /** + * @description: 设置禁飞区列表 + */ + setNoflyData (state, data) { + state.noflyData = data + }, /** * @description: 设置分类列表 */ @@ -582,6 +589,19 @@ const store = new Vuex.Store({ }) } }, + /** + * @description: 获取禁飞区数据 + */ + async fetchNoflyData ({ commit }) { + const res = await api.get('getNoflyData') + if (res.data.status === 1) { + commit('setNoflyData', res.data.noflyData) + } else { + commit('setNoflyData', {}) + Message.warning(res.data.msg) + } + return res.data.routeData + }, /** * @description: 获取分类列表 * @return {*} 列表 diff --git a/src/views/layout/components/main/nofly/set.vue b/src/views/layout/components/main/nofly/set.vue index a479c4f..e8eb014 100644 --- a/src/views/layout/components/main/nofly/set.vue +++ b/src/views/layout/components/main/nofly/set.vue @@ -17,9 +17,6 @@ export default { MapBox }, computed: { - airList () { - return this.$store.state.airList - }, /** * @description: 侧边栏显隐 */ @@ -28,39 +25,11 @@ export default { } }, methods: { - /** - * @description: 创建飞机图标 - */ - makePlanes (planes) { - this.$refs.mapbox.removePlanes()// 先清除画布上现有的飞机 - planes.forEach((plane, index) => { // 创建所有飞机 - let planeDefaultLonLat - if (localStorage.getItem(plane.name) !== null) { // 从本地缓存 拿飞机得初始位置 - planeDefaultLonLat = JSON.parse(localStorage.getItem(plane.name)) - plane.lon = planeDefaultLonLat.lon - plane.lat = planeDefaultLonLat.lat - } else { - plane.lon = 0 - plane.lat = 0 - } - this.$refs.mapbox.makePlane(plane, index) - }) - } + }, mounted () { - if (this.airList.length > 0) { - this.makePlanes(this.airList)// 创建飞机图标 - } }, watch: { - /** - * @description: 飞机列表更新时候 更新地图 - */ - airList: { - handler (val) { - this.makePlanes(val) - } - }, /** * @description: 侧边栏缩进有变化时 地图重新自适应 */ diff --git a/src/views/layout/index.vue b/src/views/layout/index.vue index c101849..4168012 100644 --- a/src/views/layout/index.vue +++ b/src/views/layout/index.vue @@ -64,6 +64,7 @@ export default { this.$store.dispatch('fetchAdminList')// 获取管理员列表 this.$store.dispatch('fetchSiteList')// 获取站点列表 this.$store.dispatch('fetchRouteList')// 获取航线列表 + this.$store.dispatch('fetchNoflyData')// 获取禁飞区数据 this.$store.dispatch('fetchCategoryList')// 获取分类列表(小程序) this.$store.dispatch('fetchSpuList')// 获取商品spu列表 this.$store.dispatch('fetchSkuList')// 获取商品sku列表