You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.3 KiB

<template lang="pug">
.add_${className}_wrapper
el-form
#foreach($column in $columns)
#if($column.edit)
el-form-item(label="${column.genLabel()}")
${column.genComponent()}(v-model="form.${column.javaField}")
#end
#end
el-button.mt16(type="primary" @click="add${ClassName}Click") 保存
</template>
<script>
import { add${ClassName}, get${ClassName}, update${ClassName} } from '@/api/${moduleName}/${className}'
export default {
name: 'Add',
data () {
return {
form: {
#foreach($column in $columns)
#if($column.edit)
${column.javaField}: null,
#end
#end
}
}
},
created () {
const { id } = this.$route.query
if (id) {
this.init${ClassName}(id)
}
},
methods: {
add${ClassName}Click () {
const call = this.form.id ? update${ClassName} : add${ClassName};
call({ ...this.form }).then(res => {
this.$message.success('创建成功')
})
},
init${ClassName} (id) {
get${ClassName}(id).then(res => {
this.form = res.data
})
}
}
}
</script>
<style lang="stylus">
.add_${className}_wrapper
.ant-form
padding 1rem 0 0 1rem
background-color white
display flex
flex-wrap wrap
.ant-form-item
width calc(50% - 1rem)
margin-right 1rem
</style>