【类 型】:feat

【原  因】:增加了机型管理里面 添加和更新 功能
【过  程】:新增表单页面组件,实现添加与编辑逻辑,支持 shop_id、机型类型、载重等字段的录入和更新
【影  响】:
This commit is contained in:
szdot 2025-06-19 03:14:39 +08:00
parent 7f2b2c4ed6
commit 8e5a6428e3
4 changed files with 115 additions and 53 deletions

View File

@ -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: 获取站点列表
*/

View File

@ -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') //

View File

@ -35,14 +35,14 @@
<!-- 轴距 -->
<el-form-item label="轴距">
<el-input v-model="form.wheelbase" placeholder="单位:厘米">
<template slot="append">cm</template>
<template #append>cm</template>
</el-input>
</el-form-item>
<!-- 最大载重 -->
<el-form-item label="最大载重">
<el-input v-model="form.weight_max" placeholder="单位:克">
<template slot="append"></template>
<template #append></template>
</el-input>
</el-form-item>
@ -52,15 +52,19 @@
</el-form-item>
<!-- 提交按钮 -->
<el-form-item v-if="pageState === 'add'">
<el-button type="primary" icon="el-icon-plus" @click="addAir">创建</el-button>
<el-button @click="setForm({ shop_id: form.shop_id })" class="iconfont icon-qingchu">
<el-form-item>
<el-button
type="primary"
:icon="pageState === 'add' ? 'el-icon-plus' : 'el-icon-edit'"
@click="pageState === 'add' ? addPlaneClass() : savePlaneClass()"
>
{{ pageState === 'add' ? '创建' : '更新' }}
</el-button>
<el-button v-if="pageState === 'add'" @click="setForm({ shop_id: form.shop_id })" class="iconfont icon-qingchu">
<font class="m-l-5">重填</font>
</el-button>
</el-form-item>
<el-form-item v-else>
<el-button type="primary" icon="el-icon-edit" @click="saveAir">更新</el-button>
</el-form-item>
</el-form>
</el-main>
</el-container>
@ -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()
}
}

View File

@ -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')//