change - 代码生成优化

main
yinq 7 months ago
parent adf9f82845
commit b7288c3f66

@ -16,7 +16,6 @@ import com.os.common.annotation.Log;
import com.os.common.core.controller.BaseController;
import com.os.common.core.domain.AjaxResult;
import com.os.common.enums.BusinessType;
import com.os.common.utils.DateUtils;
import ${packageName}.domain.${ClassName};
import ${packageName}.service.I${ClassName}Service;
import com.os.common.utils.poi.ExcelUtil;
@ -89,8 +88,7 @@ public class ${ClassName}Controller extends BaseController
@PostMapping
public AjaxResult add(@RequestBody ${ClassName} ${className})
{
${className}.setCreatedBy(getUsername());
${className}.setCreatedTime(DateUtils.getNowDate());
${className}.setCreateBy(getUsername());
return toAjax(${className}Service.insert${ClassName}(${className}));
}
@ -102,8 +100,7 @@ public class ${ClassName}Controller extends BaseController
@PutMapping
public AjaxResult edit(@RequestBody ${ClassName} ${className})
{
${className}.setUpdatedBy(getUsername());
${className}.setUpdatedTime(DateUtils.getNowDate());
${className}.setUpdateBy(getUsername());
return toAjax(${className}Service.update${ClassName}(${className}));
}

@ -1,7 +1,6 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
label-width="100px">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
#foreach($column in $columns)
#if($column.query)
#set($dictType=$column.dictType)
@ -77,8 +76,7 @@
size="mini"
@click="handleAdd"
v-hasPermi="['${moduleName}:${businessName}:add']"
>新增
</el-button>
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
@ -87,8 +85,7 @@
icon="el-icon-sort"
size="mini"
@click="toggleExpandAll"
>展开/折叠
</el-button>
>展开/折叠</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
</el-row>
@ -111,26 +108,22 @@
#end
#if($column.pk)
#elseif($column.list && $column.htmlType == "datetime")
<el-table-column label="${comment}" align="center" prop="${javaField}" width="180"
v-if="columns[${foreach.index}].visible">
<el-table-column label="${comment}" align="center" prop="${javaField}" width="180" v-if="columns[${foreach.index}].visible">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
#elseif($column.list && $column.htmlType == "imageUpload")
<el-table-column label="${comment}" align="center" prop="${javaField}" width="100"
v-if="columns[${foreach.index}].visible">
<el-table-column label="${comment}" align="center" prop="${javaField}" width="100" v-if="columns[${foreach.index}].visible">
<template slot-scope="scope">
<image-preview :src="scope.row.${javaField}" :width="50" :height="50"/>
</template>
</el-table-column>
#elseif($column.list && "" != $column.dictType)
<el-table-column label="${comment}" align="center" prop="${javaField}"
v-if="columns[${foreach.index}].visible">
<el-table-column label="${comment}" align="center" prop="${javaField}" v-if="columns[${foreach.index}].visible">
<template slot-scope="scope">
#if($column.htmlType == "checkbox")
<dict-tag :options="dict.type.${column.dictType}"
:value="scope.row.${javaField} ? scope.row.${javaField}.split(',') : []"/>
<dict-tag :options="dict.type.${column.dictType}" :value="scope.row.${javaField} ? scope.row.${javaField}.split(',') : []"/>
#else
<dict-tag :options="dict.type.${column.dictType}" :value="scope.row.${javaField}"/>
#end
@ -138,11 +131,9 @@
</el-table-column>
#elseif($column.list && "" != $javaField)
#if(${foreach.index} == 1)
<el-table-column label="${comment}" prop="${javaField}"
v-if="columns[${foreach.index}].visible"/>
<el-table-column label="${comment}" prop="${javaField}" v-if="columns[${foreach.index}].visible" />
#else
<el-table-column label="${comment}" align="center" prop="${javaField}"
v-if="columns[${foreach.index}].visible"/>
<el-table-column label="${comment}" align="center" prop="${javaField}" v-if="columns[${foreach.index}].visible" />
#end
#end
#end
@ -154,24 +145,21 @@
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['${moduleName}:${businessName}:edit']"
>修改
</el-button>
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-plus"
@click="handleAdd(scope.row)"
v-hasPermi="['${moduleName}:${businessName}:add']"
>新增
</el-button>
>新增</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['${moduleName}:${businessName}:remove']"
>删除
</el-button>
>删除</el-button>
</template>
</el-table-column>
</el-table>
@ -192,8 +180,7 @@
#set($dictType=$column.dictType)
#if("" != $treeParentCode && $column.javaField == $treeParentCode)
<el-form-item label="${comment}" prop="${treeParentCode}">
<treeselect v-model="form.${treeParentCode}" :options="${businessName}Options"
:normalizer="normalizer" placeholder="请选择${comment}"/>
<treeselect v-model="form.${treeParentCode}" :options="${businessName}Options" :normalizer="normalizer" placeholder="请选择${comment}" />
</el-form-item>
#elseif($column.htmlType == "input")
<el-form-item label="${comment}" prop="${field}">
@ -260,8 +247,7 @@
#else
:label="dict.value"
#end
>{{dict.label}}
</el-radio>
>{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
#elseif($column.htmlType == "radio" && $dictType)
@ -297,13 +283,7 @@
</template>
<script>
import {
list${BusinessName},
get${BusinessName},
del${BusinessName},
add${BusinessName},
update${BusinessName}
} from "@/api/${moduleName}/${businessName}";
import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName} } from "@/api/${moduleName}/${businessName}";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
@ -361,9 +341,7 @@
#set($comment=$column.columnComment)
#end
$column.javaField: [
{
required: true, message: "$comment不能为空", trigger: #if($column.htmlType ==
"select" || $column.htmlType == "radio")"change"#else"blur"#end }
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
]#if($foreach.count != $columns.size()),#end
#end
#end
@ -501,54 +479,22 @@
},
/** 提交按钮 */
submitForm() {
this.
#
[[$]]
#refs["form"].validate(valid => {
this.#[[$]]#refs["form"].validate(valid => {
if (valid) {
#foreach ($column in $columns)
#if($column.htmlType == "checkbox")
this.form.$column.javaField = this.form.$
{
column.javaField
}
.
join(",");
this.form.$column.javaField = this.form.${column.javaField}.join(",");
#end
#end
if (this.form.${
pkColumn.javaField
}
!=
null
)
{
update$
{
BusinessName
}
(this.form).then(response => {
this.
#
[[$modal]]
#.
msgSuccess("修改成功");
if (this.form.${pkColumn.javaField} != null) {
update${BusinessName}(this.form).then(response => {
this.#[[$modal]]#.msgSuccess("修改成功");
this.open = false;
this.getList();
});
}
else
{
add$
{
BusinessName
}
(this.form).then(response => {
this.
#
[[$modal]]
#.
msgSuccess("新增成功");
} else {
add${BusinessName}(this.form).then(response => {
this.#[[$modal]]#.msgSuccess("新增成功");
this.open = false;
this.getList();
});
@ -558,36 +504,12 @@
},
/** 删除按钮操作 */
handleDelete(row) {
this.
#
[[$modal]]
#.
confirm('是否确认删除${functionName}编号为"' + row.$
{
pkColumn.javaField
}
+'"的数据项?'
).
then(function () {
return del$
{
BusinessName
}
(row.$
{
pkColumn.javaField
}
)
;
this.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + row.${pkColumn.javaField} + '"的数据项?').then(function() {
return del${BusinessName}(row.${pkColumn.javaField});
}).then(() => {
this.getList();
this.
#
[[$modal]]
#.
msgSuccess("删除成功");
}).catch(() => {
});
this.#[[$modal]]#.msgSuccess("删除成功");
}).catch(() => {});
}
}
};

@ -1,7 +1,6 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
label-width="100px">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
#foreach($column in $columns)
#if($column.query)
#set($dictType=$column.dictType)
@ -51,12 +50,12 @@
<el-form-item label="${comment}">
<el-date-picker
v-model="daterange${AttrName}"
style="width: 240px"
value-format="yyyy-MM-dd"
type="daterange"
style="width: 340px"
value-format="yyyy-MM-dd HH:mm:ss"
type="datetimerange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
start-placeholder="开始时间"
end-placeholder="结束时间"
></el-date-picker>
</el-form-item>
#end
@ -77,8 +76,7 @@
size="mini"
@click="handleAdd"
v-hasPermi="['${moduleName}:${businessName}:add']"
>新增
</el-button>
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
@ -89,8 +87,7 @@
:disabled="single"
@click="handleUpdate"
v-hasPermi="['${moduleName}:${businessName}:edit']"
>修改
</el-button>
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
@ -101,8 +98,7 @@
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['${moduleName}:${businessName}:remove']"
>删除
</el-button>
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
@ -112,8 +108,7 @@
size="mini"
@click="handleExport"
v-hasPermi="['${moduleName}:${businessName}:export']"
>导出
</el-button>
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
</el-row>
@ -129,37 +124,31 @@
#set($comment=$column.columnComment)
#end
#if($column.pk)
<el-table-column label="${comment}" align="center" prop="${javaField}"
v-if="columns[${foreach.index}].visible"/>
<el-table-column label="${comment}" align="center" prop="${javaField}" v-if="columns[${foreach.index}].visible"/>
#elseif($column.list && $column.htmlType == "datetime")
<el-table-column label="${comment}" align="center" prop="${javaField}" width="180"
v-if="columns[${foreach.index}].visible">
<el-table-column label="${comment}" align="center" prop="${javaField}" width="180" v-if="columns[${foreach.index}].visible">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
</template>
</el-table-column>
#elseif($column.list && $column.htmlType == "imageUpload")
<el-table-column label="${comment}" align="center" prop="${javaField}" width="100"
v-if="columns[${foreach.index}].visible">
<el-table-column label="${comment}" align="center" prop="${javaField}" width="100" v-if="columns[${foreach.index}].visible">
<template slot-scope="scope">
<image-preview :src="scope.row.${javaField}" :width="50" :height="50"/>
</template>
</el-table-column>
#elseif($column.list && "" != $column.dictType)
<el-table-column label="${comment}" align="center" prop="${javaField}"
v-if="columns[${foreach.index}].visible">
<el-table-column label="${comment}" align="center" prop="${javaField}" v-if="columns[${foreach.index}].visible">
<template slot-scope="scope">
#if($column.htmlType == "checkbox")
<dict-tag :options="dict.type.${column.dictType}"
:value="scope.row.${javaField} ? scope.row.${javaField}.split(',') : []"/>
<dict-tag :options="dict.type.${column.dictType}" :value="scope.row.${javaField} ? scope.row.${javaField}.split(',') : []"/>
#else
<dict-tag :options="dict.type.${column.dictType}" :value="scope.row.${javaField}"/>
#end
</template>
</el-table-column>
#elseif($column.list && "" != $javaField)
<el-table-column label="${comment}" align="center" prop="${javaField}"
v-if="columns[${foreach.index}].visible"/>
<el-table-column label="${comment}" align="center" prop="${javaField}" v-if="columns[${foreach.index}].visible"/>
#end
#end
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
@ -170,16 +159,14 @@
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['${moduleName}:${businessName}:edit']"
>修改
</el-button>
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['${moduleName}:${businessName}:remove']"
>删除
</el-button>
>删除</el-button>
</template>
</el-table-column>
</el-table>
@ -271,8 +258,7 @@
#else
:label="dict.value"
#end
>{{dict.label}}
</el-radio>
>{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
#elseif($column.htmlType == "radio" && $dictType)
@ -302,18 +288,13 @@
<el-divider content-position="center">${subTable.functionName}信息</el-divider>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd${subClassName}">
添加
</el-button>
<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd${subClassName}">添加</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="danger" icon="el-icon-delete" size="mini"
@click="handleDelete${subClassName}">删除
</el-button>
<el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDelete${subClassName}">删除</el-button>
</el-col>
</el-row>
<el-table :data="${subclassName}List" :row-class-name="row${subClassName}Index"
@selection-change="handle${subClassName}SelectionChange" ref="${subclassName}">
<el-table :data="${subclassName}List" :row-class-name="row${subClassName}Index" @selection-change="handle${subClassName}SelectionChange" ref="${subclassName}">
<el-table-column type="selection" width="50" align="center" />
<el-table-column label="序号" align="center" prop="index" width="50"/>
#foreach($column in $subTable.columns)
@ -334,12 +315,10 @@
#elseif($column.list && $column.htmlType == "datetime")
<el-table-column label="$comment" prop="${javaField}" width="240">
<template slot-scope="scope">
<el-date-picker clearable v-model="scope.row.$javaField" type="date"
value-format="yyyy-MM-dd" placeholder="请选择$comment"/>
<el-date-picker clearable v-model="scope.row.$javaField" type="date" value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择$comment" />
</template>
</el-table-column>
#elseif($column.list && ($column.htmlType == "select" || $column.htmlType == "radio") &&
"" != $column.dictType)
#elseif($column.list && ($column.htmlType == "select" || $column.htmlType == "radio") && "" != $column.dictType)
<el-table-column label="$comment" prop="${javaField}" width="150">
<template slot-scope="scope">
<el-select v-model="scope.row.$javaField" placeholder="请选择$comment">
@ -352,8 +331,7 @@
</el-select>
</template>
</el-table-column>
#elseif($column.list && ($column.htmlType == "select" || $column.htmlType == "radio") &&
"" == $column.dictType)
#elseif($column.list && ($column.htmlType == "select" || $column.htmlType == "radio") && "" == $column.dictType)
<el-table-column label="$comment" prop="${javaField}" width="150">
<template slot-scope="scope">
<el-select v-model="scope.row.$javaField" placeholder="请选择$comment">
@ -375,13 +353,7 @@
</template>
<script>
import {
list${BusinessName},
get${BusinessName},
del${BusinessName},
add${BusinessName},
update${BusinessName}
} from "@/api/${moduleName}/${businessName}";
import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName} } from "@/api/${moduleName}/${businessName}";
export default {
name: "${BusinessName}",
@ -446,9 +418,7 @@
#set($comment=$column.columnComment)
#end
$column.javaField: [
{
required: true, message: "$comment不能为空", trigger: #if($column.htmlType ==
"select" || $column.htmlType == "radio")"change"#else"blur"#end }
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
]#if($foreach.count != $columns.size()),#end
#end
#end
@ -563,65 +533,25 @@
},
/** 提交按钮 */
submitForm() {
this.
#
[[$]]
#refs["form"].validate(valid => {
this.#[[$]]#refs["form"].validate(valid => {
if (valid) {
#foreach ($column in $columns)
#if($column.htmlType == "checkbox")
this.form.$column.javaField = this.form.$
{
column.javaField
}
.
join(",");
this.form.$column.javaField = this.form.${column.javaField}.join(",");
#end
#end
#if($table.sub)
this.form.$
{
subclassName
}
List = this.$
{
subclassName
}
List;
this.form.${subclassName}List = this.${subclassName}List;
#end
if (this.form.${
pkColumn.javaField
}
!=
null
)
{
update$
{
BusinessName
}
(this.form).then(response => {
this.
#
[[$modal]]
#.
msgSuccess("修改成功");
if (this.form.${pkColumn.javaField} != null) {
update${BusinessName}(this.form).then(response => {
this.#[[$modal]]#.msgSuccess("修改成功");
this.open = false;
this.getList();
});
}
else
{
add$
{
BusinessName
}
(this.form).then(response => {
this.
#
[[$modal]]
#.
msgSuccess("新增成功");
} else {
add${BusinessName}(this.form).then(response => {
this.#[[$modal]]#.msgSuccess("新增成功");
this.open = false;
this.getList();
});
@ -631,51 +561,21 @@
},
/** 删除按钮操作 */
handleDelete(row) {
const ${pkColumn.javaField}s = row.$
{
pkColumn.javaField
}
||
this.ids;
this.
#
[[$modal]]
#.
confirm('是否确认删除${functionName}编号为"' + ${pkColumn.javaField}s + '"的数据项?').then(function () {
return del$
{
BusinessName
}
(${pkColumn.javaField}s);
const ${pkColumn.javaField}s = row.${pkColumn.javaField} || this.ids;
this.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + ${pkColumn.javaField}s + '"的数据项?').then(function() {
return del${BusinessName}(${pkColumn.javaField}s);
}).then(() => {
this.getList();
this.
#
[[$modal]]
#.
msgSuccess("删除成功");
}).catch(() => {
});
this.#[[$modal]]#.msgSuccess("删除成功");
}).catch(() => {});
},
#if($table.sub
)
#if($table.sub)
/** ${subTable.functionName}序号 */
row$
{
subClassName
}
Index({row, rowIndex})
{
row${subClassName}Index({ row, rowIndex }) {
row.index = rowIndex + 1;
}
,
},
/** ${subTable.functionName}添加按钮操作 */
handleAdd$
{
subClassName
}
()
{
handleAdd${subClassName}() {
let obj = {};
#foreach($column in $subTable.columns)
#if($column.pk || $column.javaField == ${subTableFkclassName})
@ -683,87 +583,31 @@
obj.$column.javaField = "";
#end
#end
this.$
{
subclassName
}
List.push(obj);
}
,
this.${subclassName}List.push(obj);
},
/** ${subTable.functionName}删除按钮操作 */
handleDelete$
{
subClassName
}
()
{
if (this.checked${
subClassName
}
.
length == 0
)
{
this.
#
[[$modal]]
#.
msgError("请先选择要删除的${subTable.functionName}数据");
}
else
{
const ${subclassName}List = this.$
{
subclassName
}
List;
const checked$
{
subClassName
}
= this.checked$
{
subClassName
}
;
this.$
{
subclassName
}
List = ${subclassName}List.filter(function (item) {
return checked$
{
subClassName
}
.
indexOf(item.index) == -1
handleDelete${subClassName}() {
if (this.checked${subClassName}.length == 0) {
this.#[[$modal]]#.msgError("请先选择要删除的${subTable.functionName}数据");
} else {
const ${subclassName}List = this.${subclassName}List;
const checked${subClassName} = this.checked${subClassName};
this.${subclassName}List = ${subclassName}List.filter(function(item) {
return checked${subClassName}.indexOf(item.index) == -1
});
}
}
,
},
/** 复选框选中数据 */
handle$
{
subClassName
}
SelectionChange(selection)
{
this.checked$
{
subClassName
}
= selection.map(item => item.index)
}
,
handle${subClassName}SelectionChange(selection) {
this.checked${subClassName} = selection.map(item => item.index)
},
#end
/** 导出按钮操作 */
handleExport()
{
handleExport() {
this.download('${moduleName}/${businessName}/export', {
...this.queryParams
}, `${businessName}_#[[${new Date().getTime()}]]#.xlsx`)
}
}
}
;
};
</script>
Loading…
Cancel
Save