end: 完成代码生成,支持vue增删查改

This commit is contained in:
wangiegie@gmail.com 2017-11-28 17:51:47 +08:00
parent 3539be7054
commit 9a8300e731
2 changed files with 107 additions and 7 deletions

View File

@ -55,7 +55,7 @@ public class MybatisPlusGenerator {
// 策略配置
StrategyConfig strategy = new StrategyConfig();
// strategy.setCapitalMode(true);// 全局大写命名 ORACLE 注意
//strategy.setTablePrefix(new String[]{"tlog_", "tsys_"});// 此处可以修改为您的表前缀
strategy.setTablePrefix(new String[]{"sys_"});// 此处可以修改为您的表前缀
// 表名生成策略
strategy.setNaming(NamingStrategy.underline_to_camel);
mpg.setStrategy(strategy);

View File

@ -1,20 +1,25 @@
<template>
<div class="app-container calendar-list-container">
<div class="filter-container">
<el-button v-if="${table.name}_add" class="filter-item" style="margin-left: 10px;" @click="handleCreate" type="primary" icon="edit">添加
</el-button>
</div>
<el-table :key='tableKey' :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border fit
highlight-current-row style="width: 100%">
#foreach($field in $table.fields)
<template scope="scope">
<el-table-column align="center" label="${field.comment}">
<span>{{scope.row.${field.propertyName}}}</span>
<el-table-column align="center" label="${field.comment}">
<template scope="scope">
<span>{{ scope.row.${field.propertyName} }}</span>
</template>
</el-table-column>
#end
<el-table-column label="操作">
<template scope="scope">
<el-button size="mini" type="danger"
<el-button v-if="${table.name}_upd" size="small" type="success"
@click="handleUpdate(scope.row)">编辑
</el-button>
<el-button v-if="${table.name}_del" size="mini" type="danger"
@click="handleDelete(scope.row)">删除
</el-button>
</template>
@ -27,12 +32,27 @@
layout="total, sizes, prev, pager, next, jumper" :total="total">
</el-pagination>
</div>
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
<el-form :model="form" :rules="rules" ref="form" label-width="100px">
#foreach($field in $table.fields)
<el-form-item label="${field.comment}" prop="username">
<el-input v-model="form.${field.propertyName}" placeholder="${field.comment}"></el-input>
</el-form-item>
#end
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="cancel('form')">取 消</el-button>
<el-button v-if="dialogStatus=='create'" type="primary" @click="create('form')">确 定</el-button>
<el-button v-else type="primary" @click="update('form')">修 改</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { fetchList, delObj } from '@/api/${table.name}'
import { fetchList, addObj, putObj, delObj } from '@/api/${table.name}'
import waves from '@/directive/waves/index.js' // 水波纹指令
import { mapGetters } from 'vuex'
export default {
name: 'table_${table.name}',
@ -48,11 +68,41 @@
page: 1,
limit: 20
},
rules: {
},
form: {
},
dialogFormVisible: false,
dialogStatus: '',
${table.name}_add: false,
${table.name}_upd: false,
${table.name}_del: false,
textMap: {
update: '编辑',
create: '创建'
},
tableKey: 0
}
},
computed: {
...mapGetters([
'permissions'
])
},
filters: {
statusFilter(status) {
const statusMap = {
0: '有效',
1: '无效'
}
return statusMap[status]
}
},
created() {
this.getList()
this.${table.name}_add = this.permissions['${table.name}_add']
this.${table.name}_upd = this.permissions['${table.name}_upd']
this.${table.name}_del = this.permissions['${table.name}_del']
},
methods: {
getList() {
@ -83,7 +133,57 @@
duration: 2000
})
})
}
},
handleCreate() {
this.dialogStatus = 'create'
this.dialogFormVisible = true
},
create(formName) {
const set = this.$refs
set[formName].validate(valid => {
if (valid) {
addObj(this.form)
.then(() => {
this.dialogFormVisible = false
this.getList()
this.$notify({
title: '成功',
message: '创建成功',
type: 'success',
duration: 2000
})
})
} else {
return false
}
})
},
cancel(formName) {
this.dialogFormVisible = false
const set = this.$refs
set[formName].resetFields()
},
update(formName) {
const set = this.$refs
set[formName].validate(valid => {
if (valid) {
this.dialogFormVisible = false
this.form.password = undefined
putObj(this.form).then(() => {
this.dialogFormVisible = false
this.getList()
this.$notify({
title: '成功',
message: '修改成功',
type: 'success',
duration: 2000
})
})
} else {
return false
}
})
},
}
}
</script>