代码生成:select的表单验证代码生成

This commit is contained in:
sunshine 2020-08-17 12:01:42 +08:00
parent d596d5bb8e
commit 4597cd6a88

View File

@ -1,17 +1,17 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
#foreach($column in $columns) #foreach($column in $columns)
#if($column.query) #if($column.query)
#set($dictType=$column.dictType) #set($dictType=$column.dictType)
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#set($parentheseIndex=$column.columnComment.indexOf("")) #set($parentheseIndex=$column.columnComment.indexOf(""))
#if($parentheseIndex != -1) #if($parentheseIndex != -1)
#set($comment=$column.columnComment.substring(0, $parentheseIndex)) #set($comment=$column.columnComment.substring(0, $parentheseIndex))
#else #else
#set($comment=$column.columnComment) #set($comment=$column.columnComment)
#end #end
#if($column.htmlType == "input") #if($column.htmlType == "input")
<el-form-item label="${comment}" prop="${column.javaField}"> <el-form-item label="${comment}" prop="${column.javaField}">
<el-input <el-input
v-model="queryParams.${column.javaField}" v-model="queryParams.${column.javaField}"
@ -21,7 +21,7 @@
@keyup.enter.native="handleQuery" @keyup.enter.native="handleQuery"
/> />
</el-form-item> </el-form-item>
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType) #elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
<el-form-item label="${comment}" prop="${column.javaField}"> <el-form-item label="${comment}" prop="${column.javaField}">
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small"> <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small">
<el-option <el-option
@ -32,13 +32,13 @@
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType) #elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType)
<el-form-item label="${comment}" prop="${column.javaField}"> <el-form-item label="${comment}" prop="${column.javaField}">
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small"> <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small">
<el-option label="请选择字典生成" value="" /> <el-option label="请选择字典生成" value="" />
</el-select> </el-select>
</el-form-item> </el-form-item>
#elseif($column.htmlType == "datetime") #elseif($column.htmlType == "datetime")
<el-form-item label="${comment}" prop="${column.javaField}"> <el-form-item label="${comment}" prop="${column.javaField}">
<el-date-picker clearable size="small" style="width: 200px" <el-date-picker clearable size="small" style="width: 200px"
v-model="queryParams.${column.javaField}" v-model="queryParams.${column.javaField}"
@ -47,9 +47,9 @@
placeholder="选择${comment}"> placeholder="选择${comment}">
</el-date-picker> </el-date-picker>
</el-form-item> </el-form-item>
#end #end
#end #end
#end #end
<el-form-item> <el-form-item>
<el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
@ -100,28 +100,28 @@
<el-table v-loading="loading" :data="${businessName}List" @selection-change="handleSelectionChange"> <el-table v-loading="loading" :data="${businessName}List" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" /> <el-table-column type="selection" width="55" align="center" />
#foreach($column in $columns) #foreach($column in $columns)
#set($javaField=$column.javaField) #set($javaField=$column.javaField)
#set($parentheseIndex=$column.columnComment.indexOf("")) #set($parentheseIndex=$column.columnComment.indexOf(""))
#if($parentheseIndex != -1) #if($parentheseIndex != -1)
#set($comment=$column.columnComment.substring(0, $parentheseIndex)) #set($comment=$column.columnComment.substring(0, $parentheseIndex))
#else #else
#set($comment=$column.columnComment) #set($comment=$column.columnComment)
#end #end
#if($column.pk) #if($column.pk)
<el-table-column label="${comment}" align="center" prop="${javaField}" /> <el-table-column label="${comment}" align="center" prop="${javaField}" />
#elseif($column.list && $column.htmlType == "datetime") #elseif($column.list && $column.htmlType == "datetime")
<el-table-column label="${comment}" align="center" prop="${javaField}" width="180"> <el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span> <span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span>
</template> </template>
</el-table-column> </el-table-column>
#elseif($column.list && "" != $column.dictType) #elseif($column.list && "" != $column.dictType)
<el-table-column label="${comment}" align="center" prop="${javaField}" :formatter="${javaField}Format" /> <el-table-column label="${comment}" align="center" prop="${javaField}" :formatter="${javaField}Format" />
#elseif($column.list && "" != $javaField) #elseif($column.list && "" != $javaField)
<el-table-column label="${comment}" align="center" prop="${javaField}" /> <el-table-column label="${comment}" align="center" prop="${javaField}" />
#end #end
#end #end
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button
@ -153,23 +153,23 @@
<!-- 添加或修改${functionName}对话框 --> <!-- 添加或修改${functionName}对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px"> <el-form ref="form" :model="form" :rules="rules" label-width="80px">
#foreach($column in $columns) #foreach($column in $columns)
#set($field=$column.javaField) #set($field=$column.javaField)
#if($column.insert && !$column.pk) #if($column.insert && !$column.pk)
#if(($column.usableColumn) || (!$column.superColumn)) #if(($column.usableColumn) || (!$column.superColumn))
#set($parentheseIndex=$column.columnComment.indexOf("")) #set($parentheseIndex=$column.columnComment.indexOf(""))
#if($parentheseIndex != -1) #if($parentheseIndex != -1)
#set($comment=$column.columnComment.substring(0, $parentheseIndex)) #set($comment=$column.columnComment.substring(0, $parentheseIndex))
#else #else
#set($comment=$column.columnComment) #set($comment=$column.columnComment)
#end #end
#set($dictType=$column.dictType) #set($dictType=$column.dictType)
#if($column.htmlType == "input") #if($column.htmlType == "input")
<el-form-item label="${comment}" prop="${field}"> <el-form-item label="${comment}" prop="${field}">
<el-input v-model="form.${field}" placeholder="请输入${comment}" /> <el-input v-model="form.${field}" placeholder="请输入${comment}" />
</el-form-item> </el-form-item>
#elseif($column.htmlType == "select" && "" != $dictType) #elseif($column.htmlType == "select" && "" != $dictType)
<el-form-item label="${comment}"> <el-form-item label="${comment}" prop="${field}">
<el-select v-model="form.${field}" placeholder="请选择${comment}"> <el-select v-model="form.${field}" placeholder="请选择${comment}">
<el-option <el-option
v-for="dict in ${field}Options" v-for="dict in ${field}Options"
@ -180,13 +180,13 @@
></el-option> ></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
#elseif($column.htmlType == "select" && $dictType) #elseif($column.htmlType == "select" && $dictType)
<el-form-item label="${comment}"> <el-form-item label="${comment}" prop="${field}">
<el-select v-model="form.${field}" placeholder="请选择${comment}"> <el-select v-model="form.${field}" placeholder="请选择${comment}">
<el-option label="请选择字典生成" value="" /> <el-option label="请选择字典生成" value="" />
</el-select> </el-select>
</el-form-item> </el-form-item>
#elseif($column.htmlType == "checkbox" && "" != $dictType) #elseif($column.htmlType == "checkbox" && "" != $dictType)
<el-form-item label="${comment}"> <el-form-item label="${comment}">
<el-checkbox-group v-model="form.${field}"> <el-checkbox-group v-model="form.${field}">
<el-checkbox <el-checkbox
@ -197,13 +197,13 @@
</el-checkbox> </el-checkbox>
</el-checkbox-group> </el-checkbox-group>
</el-form-item> </el-form-item>
#elseif($column.htmlType == "checkbox" && $dictType) #elseif($column.htmlType == "checkbox" && $dictType)
<el-form-item label="${comment}"> <el-form-item label="${comment}">
<el-checkbox-group v-model="form.${field}"> <el-checkbox-group v-model="form.${field}">
<el-checkbox>请选择字典生成</el-checkbox> <el-checkbox>请选择字典生成</el-checkbox>
</el-checkbox-group> </el-checkbox-group>
</el-form-item> </el-form-item>
#elseif($column.htmlType == "radio" && "" != $dictType) #elseif($column.htmlType == "radio" && "" != $dictType)
<el-form-item label="${comment}"> <el-form-item label="${comment}">
<el-radio-group v-model="form.${field}"> <el-radio-group v-model="form.${field}">
<el-radio <el-radio
@ -214,13 +214,13 @@
>{{dict.dictLabel}}</el-radio> >{{dict.dictLabel}}</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
#elseif($column.htmlType == "radio" && $dictType) #elseif($column.htmlType == "radio" && $dictType)
<el-form-item label="${comment}"> <el-form-item label="${comment}">
<el-radio-group v-model="form.${field}"> <el-radio-group v-model="form.${field}">
<el-radio label="1">请选择字典生成</el-radio> <el-radio label="1">请选择字典生成</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
#elseif($column.htmlType == "datetime") #elseif($column.htmlType == "datetime")
<el-form-item label="${comment}" prop="${field}"> <el-form-item label="${comment}" prop="${field}">
<el-date-picker clearable size="small" style="width: 200px" <el-date-picker clearable size="small" style="width: 200px"
v-model="form.${field}" v-model="form.${field}"
@ -229,14 +229,14 @@
placeholder="选择${comment}"> placeholder="选择${comment}">
</el-date-picker> </el-date-picker>
</el-form-item> </el-form-item>
#elseif($column.htmlType == "textarea") #elseif($column.htmlType == "textarea")
<el-form-item label="${comment}" prop="${field}"> <el-form-item label="${comment}" prop="${field}">
<el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" /> <el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" />
</el-form-item> </el-form-item>
#end #end
#end #end
#end #end
#end #end
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button> <el-button type="primary" @click="submitForm">确 定</el-button>
@ -247,9 +247,9 @@
</template> </template>
<script> <script>
import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName}, export${BusinessName} } from "@/api/${moduleName}/${businessName}"; import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName}, export${BusinessName} } from "@/api/${moduleName}/${businessName}";
export default { export default {
name: "${BusinessName}", name: "${BusinessName}",
data() { data() {
return { return {
@ -271,60 +271,60 @@ export default {
title: "", title: "",
// 是否显示弹出层 // 是否显示弹出层
open: false, open: false,
#foreach ($column in $columns) #foreach ($column in $columns)
#set($parentheseIndex=$column.columnComment.indexOf("")) #set($parentheseIndex=$column.columnComment.indexOf(""))
#if($parentheseIndex != -1) #if($parentheseIndex != -1)
#set($comment=$column.columnComment.substring(0, $parentheseIndex)) #set($comment=$column.columnComment.substring(0, $parentheseIndex))
#else #else
#set($comment=$column.columnComment) #set($comment=$column.columnComment)
#end #end
#if(${column.dictType} != '') #if(${column.dictType} != '')
// $comment字典 // $comment字典
${column.javaField}Options: [], ${column.javaField}Options: [],
#end #end
#end #end
// 查询参数 // 查询参数
queryParams: { queryParams: {
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
#foreach ($column in $columns) #foreach ($column in $columns)
#if($column.query) #if($column.query)
$column.javaField: null#if($velocityCount != $columns.size()),#end $column.javaField: null#if($velocityCount != $columns.size()),#end
#end #end
#end #end
}, },
// 表单参数 // 表单参数
form: {}, form: {},
// 表单校验 // 表单校验
rules: { rules: {
#foreach ($column in $columns) #foreach ($column in $columns)
#if($column.required) #if($column.required)
#set($parentheseIndex=$column.columnComment.indexOf("")) #set($parentheseIndex=$column.columnComment.indexOf(""))
#if($parentheseIndex != -1) #if($parentheseIndex != -1)
#set($comment=$column.columnComment.substring(0, $parentheseIndex)) #set($comment=$column.columnComment.substring(0, $parentheseIndex))
#else #else
#set($comment=$column.columnComment) #set($comment=$column.columnComment)
#end #end
#set($comment=$column.columnComment) #set($comment=$column.columnComment)
$column.javaField: [ $column.javaField: [
{ required: true, message: "$comment不能为空", trigger: "blur" } { required: true, message: "$comment不能为空", #if($column.htmlType == "select")"change"#else"blur"#end }
]#if($velocityCount != $columns.size()),#end ]#if($velocityCount != $columns.size()),#end
#end #end
#end #end
} }
}; };
}, },
created() { created() {
this.getList(); this.getList();
#foreach ($column in $columns) #foreach ($column in $columns)
#if(${column.dictType} != '') #if(${column.dictType} != '')
this.getDicts("${column.dictType}").then(response => { this.getDicts("${column.dictType}").then(response => {
this.${column.javaField}Options = response.data; this.${column.javaField}Options = response.data;
}); });
#end #end
#end #end
}, },
methods: { methods: {
/** 查询${functionName}列表 */ /** 查询${functionName}列表 */
@ -336,20 +336,20 @@ export default {
this.loading = false; this.loading = false;
}); });
}, },
#foreach ($column in $columns) #foreach ($column in $columns)
#if(${column.dictType} != '') #if(${column.dictType} != '')
#set($parentheseIndex=$column.columnComment.indexOf("")) #set($parentheseIndex=$column.columnComment.indexOf(""))
#if($parentheseIndex != -1) #if($parentheseIndex != -1)
#set($comment=$column.columnComment.substring(0, $parentheseIndex)) #set($comment=$column.columnComment.substring(0, $parentheseIndex))
#else #else
#set($comment=$column.columnComment) #set($comment=$column.columnComment)
#end #end
// $comment字典翻译 // $comment字典翻译
${column.javaField}Format(row, column) { ${column.javaField}Format(row, column) {
return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField}); return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField});
}, },
#end #end
#end #end
// 取消按钮 // 取消按钮
cancel() { cancel() {
this.open = false; this.open = false;
@ -358,18 +358,18 @@ export default {
// 表单重置 // 表单重置
reset() { reset() {
this.form = { this.form = {
#foreach ($column in $columns) #foreach ($column in $columns)
#if($column.htmlType == "radio") #if($column.htmlType == "radio")
$column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end $column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end
#elseif($column.htmlType == "checkbox") #elseif($column.htmlType == "checkbox")
$column.javaField: []#if($velocityCount != $columns.size()),#end $column.javaField: []#if($velocityCount != $columns.size()),#end
#else #else
$column.javaField: null#if($velocityCount != $columns.size()),#end $column.javaField: null#if($velocityCount != $columns.size()),#end
#end #end
#end #end
}; };
this.resetForm("form"); this.resetForm("form");
}, },
@ -401,11 +401,11 @@ export default {
const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids
get${BusinessName}(${pkColumn.javaField}).then(response => { get${BusinessName}(${pkColumn.javaField}).then(response => {
this.form = response.data; this.form = response.data;
#foreach ($column in $columns) #foreach ($column in $columns)
#if($column.htmlType == "checkbox") #if($column.htmlType == "checkbox")
this.form.$column.javaField = this.form.${column.javaField}.split(","); this.form.$column.javaField = this.form.${column.javaField}.split(",");
#end #end
#end #end
this.open = true; this.open = true;
this.title = "修改${functionName}"; this.title = "修改${functionName}";
}); });
@ -414,11 +414,11 @@ export default {
submitForm() { submitForm() {
this.#[[$]]#refs["form"].validate(valid => { this.#[[$]]#refs["form"].validate(valid => {
if (valid) { if (valid) {
#foreach ($column in $columns) #foreach ($column in $columns)
#if($column.htmlType == "checkbox") #if($column.htmlType == "checkbox")
this.form.$column.javaField = this.form.${column.javaField}.join(","); this.form.$column.javaField = this.form.${column.javaField}.join(",");
#end #end
#end #end
if (this.form.${pkColumn.javaField} != null) { if (this.form.${pkColumn.javaField} != null) {
update${BusinessName}(this.form).then(response => { update${BusinessName}(this.form).then(response => {
if (response.code === 200) { if (response.code === 200) {
@ -467,5 +467,5 @@ export default {
}).catch(function() {}); }).catch(function() {});
} }
} }
}; };
</script> </script>