From 8e5a6428e3ba0921117d1c1f50dbc551b3240905 Mon Sep 17 00:00:00 2001 From: szdot Date: Thu, 19 Jun 2025 03:14:39 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=B1=BB=20=20=E5=9E=8B=E3=80=91?= =?UTF-8?q?=EF=BC=9Afeat=20=E3=80=90=E5=8E=9F=20=20=E5=9B=A0=E3=80=91?= =?UTF-8?q?=EF=BC=9A=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=9C=BA=E5=9E=8B=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E9=87=8C=E9=9D=A2=20=E6=B7=BB=E5=8A=A0=E5=92=8C?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E5=8A=9F=E8=83=BD=20=E3=80=90=E8=BF=87=20?= =?UTF-8?q?=20=E7=A8=8B=E3=80=91=EF=BC=9A=E6=96=B0=E5=A2=9E=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E9=A1=B5=E9=9D=A2=E7=BB=84=E4=BB=B6=EF=BC=8C=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E6=B7=BB=E5=8A=A0=E4=B8=8E=E7=BC=96=E8=BE=91=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E6=94=AF=E6=8C=81=20shop=5Fid=E3=80=81?= =?UTF-8?q?=E6=9C=BA=E5=9E=8B=E7=B1=BB=E5=9E=8B=E3=80=81=E8=BD=BD=E9=87=8D?= =?UTF-8?q?=E7=AD=89=E5=AD=97=E6=AE=B5=E7=9A=84=E5=BD=95=E5=85=A5=E5=92=8C?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E3=80=90=E5=BD=B1=20=20=E5=93=8D=E3=80=91?= =?UTF-8?q?=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/index.js | 65 +++++++++++ src/views/layout/components/headbar.vue | 1 + .../layout/components/main/model/add.vue | 101 +++++++++--------- src/views/layout/index.vue | 1 + 4 files changed, 115 insertions(+), 53 deletions(-) diff --git a/src/store/index.js b/src/store/index.js index fce212f..429dc06 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -15,6 +15,7 @@ const store = new Vuex.Store({ shopList: [], // 商铺列表 adminList: [], // 管理员列表 airList: [], // 所有飞机列表 + planeClassList: [], // 机型列表 siteList: [], // 站点列表 routeList: [], // 航线列表 noflyData: [[], [], []], // [0]禁飞区数据 [1]限制飞区 [2]限飞区高度 @@ -66,6 +67,12 @@ const store = new Vuex.Store({ setRouteList (state, list) { state.routeList = list }, + /** + * @description: 设置机型列表 + */ + setPlaneClassList (state, list) { + state.planeClassList = list + }, /** * @description: 设置禁飞区列表 */ @@ -431,6 +438,64 @@ const store = new Vuex.Store({ }) } }, + /** + * @description: 获取机型列表 + */ + async fetchPlaneClassList ({ commit }) { + const res = await api.get('getPlaneClassList') + if (res.data.status === 1) { + commit('setPlaneClassList', res.data.planeClassList) + } else { + commit('setPlaneClassList', []) + Message.warning(res.data.msg) + } + return res.data.planeClassList + }, + /** + * @description: 创建新机型 + * @param {*} form 表单.机型信息 + * @return {*} 服务器返回信息 + */ + async fetchAddPlaneClass ({ dispatch }, form) { + const params = new URLSearchParams() + params.append('shop_id', form.shop_id) + params.append('class_name', form.class_name) + params.append('wheelbase', form.wheelbase) + params.append('category', form.category) + params.append('weight_max', form.weight_max) + params.append('describe', form.describe) + const res = await api.post('addPlaneClass', params) + if (res.data.status === 1) { + await dispatch('fetchPlaneClassList')// 刷新 机型列表 + Message.success(res.data.msg) + } else { + Message.error(res.data.msg) + } + return res + }, + /** + * @description: 创建新机型 + * @param {*} form 表单.机型信息 + * @return {*} 服务器返回信息 + */ + async fetchSavePlaneClass ({ dispatch }, form) { + const params = new URLSearchParams() + params.append('id', form.id) + params.append('shop_id', form.shop_id) + params.append('class_name', form.class_name) + params.append('wheelbase', form.wheelbase) + params.append('category', form.category) + params.append('weight_max', form.weight_max) + params.append('describe', form.describe) + const res = await api.post('savePlaneClass', params) + if (res.data.status === 1) { + await dispatch('fetchPlaneClassList')// 刷新 机型列表 + Message.success(res.data.msg) + } else { + Message.error(res.data.msg) + } + return res + }, /** * @description: 获取站点列表 */ diff --git a/src/views/layout/components/headbar.vue b/src/views/layout/components/headbar.vue index dc84547..ef8a760 100644 --- a/src/views/layout/components/headbar.vue +++ b/src/views/layout/components/headbar.vue @@ -266,6 +266,7 @@ export default { refreshPage () { /* init 数据接口 */ this.$store.commit('app/setIsMobile') // 获取客户端平台类型 + this.$store.dispatch('fetchPlaneClassList')// 获取机型列表 this.$store.dispatch('fetchAirList') // 获取飞机列表 this.$store.dispatch('fetchShopList') // 获取商铺列表 this.$store.dispatch('fetchAdminList') // 获取管理员列表 diff --git a/src/views/layout/components/main/model/add.vue b/src/views/layout/components/main/model/add.vue index 69dd451..7ff17ef 100644 --- a/src/views/layout/components/main/model/add.vue +++ b/src/views/layout/components/main/model/add.vue @@ -35,14 +35,14 @@ - + - + @@ -52,15 +52,19 @@ - - 创建 - + + + {{ pageState === 'add' ? '创建' : '更新' }} + + 重填 - - 更新 - + @@ -73,7 +77,10 @@ import SelectionShopId from '@/components/SelectionShopId' export default { - name: 'RegisterAdd', + name: 'PlaneClassAdd', + components: { + SelectionShopId + }, data () { return { form: { @@ -82,79 +89,67 @@ export default { category: '四旋翼', wheelbase: '', weight_max: '', - module: '', - describe: '', - onoff: true + describe: '' }, - airId: this.$route.params.id, + planeClassId: this.$route.params.id, pageState: 'add', - plane: null + planeClass: null } }, - components: { - SelectionShopId - }, computed: { - airList () { - return this.$store.state.airList + planeClassList () { + return this.$store.state.planeClassList || [] } }, methods: { - setForm (data) { - this.form.shop_id = data.shop_id - this.form.class_name = data.class_name - this.form.category = data.category - this.form.wheelbase = data.wheelbase - this.form.weight_max = data.weight_max - this.form.module = data.module + setForm (data = {}) { + this.form.shop_id = data.shop_id || '' + this.form.class_name = data.class_name || '' + this.form.category = data.category || '四旋翼' + this.form.wheelbase = data.wheelbase || '' + this.form.weight_max = data.weight_max || '' this.form.describe = data.describe || '' - this.form.onoff = data.onoff === '1' || data.onoff === true if (Object.keys(data).length === 0) { this.$message.warning('清空表单') } }, initPage () { - if (this.airId === undefined) { + if (!this.planeClassId) { this.pageState = 'add' } else { this.pageState = 'edit' - this.plane = this.airList.find((item) => item.id === this.airId) - if (this.plane) { - const data = { - shop_id: this.plane.shop_id, - class_name: this.plane.class_name, - category: this.plane.category, - wheelbase: this.plane.wheelbase, - weight_max: this.plane.weight_max, - module: this.plane.module, - describe: this.plane.describe, - onoff: this.plane.onoff - } - this.setForm(data) + this.planeClass = this.planeClassList.find(item => item.id === this.planeClassId) + if (this.planeClass) { + this.setForm({ ...this.planeClass }) + } else { + this.$message.error('找不到对应机型信息') } } }, - async addAir () { - const res = await this.$store.dispatch('fetchAddAir', this.form) - if (res.data.status === 1) { - this.$router.push('/register/index') + async addPlaneClass () { + const res = await this.$store.dispatch('fetchAddPlaneClass', this.form) + if (res?.data?.status === 1) { + this.$router.push('/model/index') } }, - async saveAir () { - this.form.id = this.airId - const res = await this.$store.dispatch('fetchSaveAir', this.form) - if (res.data.status === 1) { - this.$router.push('/register/index') + async savePlaneClass () { + this.form.id = this.planeClassId + const res = await this.$store.dispatch('fetchSavePlaneClass', this.form) + if (res?.data?.status === 1) { + this.$router.push('/model/index') } } }, watch: { - airList () { - this.initPage() + planeClassList: { + handler () { + this.initPage() + }, + immediate: true } }, created () { - if (this.airList.length > 0) { + if (this.planeClassList.length > 0) { this.initPage() } } diff --git a/src/views/layout/index.vue b/src/views/layout/index.vue index c4162d4..2edbd37 100644 --- a/src/views/layout/index.vue +++ b/src/views/layout/index.vue @@ -107,6 +107,7 @@ export default { created () { /* init */ this.$store.commit('app/setIsMobile')// 获取客户端平台类型 + this.$store.dispatch('fetchPlaneClassList')// 获取机型列表 this.$store.dispatch('fetchAirList')// 获取飞机列表 this.$store.dispatch('fetchShopList')// 获取商铺列表 this.$store.dispatch('fetchAdminList')// 获取管理员列表