add 代码生成增加 vue3 页面模板

This commit is contained in:
疯狂的狮子li 2021-12-16 15:09:35 +08:00
parent d2c6e27d07
commit d600cdd8a0
2 changed files with 44 additions and 23 deletions

View File

@ -11,7 +11,7 @@
#else #else
#set($comment=$column.columnComment) #set($comment=$column.columnComment)
#end #end
#if($column.htmlType == "input") #if($column.htmlType == "input" || $column.htmlType == "textarea")
<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}"
@ -105,7 +105,7 @@
<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 && "" != $column.dictType)
<el-table-column label="${comment}" align="center" prop="${javaField}"> <el-table-column label="${comment}" align="center" prop="${javaField}">
<template #default="scope"> <template #default="scope">
#if($column.htmlType == "checkbox") #if($column.htmlType == "checkbox")
@ -156,7 +156,6 @@
#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))
#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))
@ -245,8 +244,8 @@
<el-form-item label="${comment}" prop="${field}"> <el-form-item label="${comment}" prop="${field}">
<el-date-picker clearable size="small" <el-date-picker clearable size="small"
v-model="form.${field}" v-model="form.${field}"
type="date" type="datetime"
value-format="YYYY-MM-DD" value-format="YYYY-MM-DD HH:mm:ss"
placeholder="选择${comment}"> placeholder="选择${comment}">
</el-date-picker> </el-date-picker>
</el-form-item> </el-form-item>
@ -281,6 +280,7 @@ const { ${dictsNoSymbol} } = proxy.useDict(${dicts});
const ${businessName}List = ref([]); const ${businessName}List = ref([]);
const ${businessName}Options = ref([]); const ${businessName}Options = ref([]);
const open = ref(false); const open = ref(false);
const buttonLoading = ref(false);
const loading = ref(true); const loading = ref(true);
const showSearch = ref(true); const showSearch = ref(true);
const title = ref(""); const title = ref("");
@ -294,14 +294,14 @@ const daterange${AttrName} = ref([]);
const data = reactive({ const data = reactive({
form: {}, form: {},
queryParams: { queryParams: {
#foreach ($column in $columns) #foreach ($column in $columns)
#if($column.query) #if($column.query)
$column.javaField: null#if($foreach.count != $columns.size()),#end $column.javaField: undefined#if($foreach.count != $columns.size()),#end
#end #end
#end #end
}, },
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)
@ -408,12 +408,14 @@ async function handleAdd(row) {
/** 修改按钮操作 */ /** 修改按钮操作 */
async function handleUpdate(row) { async function handleUpdate(row) {
loading.value = true;
reset(); reset();
await getTreeselect(); await getTreeselect();
if (row != null) { if (row != null) {
form.value.${treeParentCode} = row.${treeCode}; form.value.${treeParentCode} = row.${treeCode};
} }
get${BusinessName}(row.${pkColumn.javaField}).then(response => { get${BusinessName}(row.${pkColumn.javaField}).then(response => {
loading.value = false;
form.value = response.data; form.value = response.data;
#foreach ($column in $columns) #foreach ($column in $columns)
#if($column.htmlType == "checkbox") #if($column.htmlType == "checkbox")
@ -429,6 +431,7 @@ async function handleUpdate(row) {
function submitForm() { function submitForm() {
proxy.#[[$]]#refs["${businessName}Ref"].validate(valid => { proxy.#[[$]]#refs["${businessName}Ref"].validate(valid => {
if (valid) { if (valid) {
buttonLoading.value = true;
#foreach ($column in $columns) #foreach ($column in $columns)
#if($column.htmlType == "checkbox") #if($column.htmlType == "checkbox")
form.value.$column.javaField = form.value.${column.javaField}.join(","); form.value.$column.javaField = form.value.${column.javaField}.join(",");
@ -439,12 +442,16 @@ function submitForm() {
proxy.#[[$modal]]#.msgSuccess("修改成功"); proxy.#[[$modal]]#.msgSuccess("修改成功");
open.value = false; open.value = false;
getList(); getList();
}).finally(() => {
buttonLoading.value = false;
}); });
} else { } else {
add${BusinessName}(form.value).then(response => { add${BusinessName}(form.value).then(response => {
proxy.#[[$modal]]#.msgSuccess("新增成功"); proxy.#[[$modal]]#.msgSuccess("新增成功");
open.value = false; open.value = false;
getList(); getList();
}).finally(() => {
buttonLoading.value = false;
}); });
} }
} }
@ -454,11 +461,15 @@ function submitForm() {
/** 删除按钮操作 */ /** 删除按钮操作 */
function handleDelete(row) { function handleDelete(row) {
proxy.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + row.${pkColumn.javaField} + '"的数据项?').then(function() { proxy.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + row.${pkColumn.javaField} + '"的数据项?').then(function() {
loading.value = true;
return del${BusinessName}(row.${pkColumn.javaField}); return del${BusinessName}(row.${pkColumn.javaField});
}).then(() => { }).then(() => {
loading.value = false;
getList(); getList();
proxy.#[[$modal]]#.msgSuccess("删除成功"); proxy.#[[$modal]]#.msgSuccess("删除成功");
}).catch(() => {}); }).finally(() => {
loading.value = false;
});
} }
getList(); getList();

View File

@ -11,7 +11,7 @@
#else #else
#set($comment=$column.columnComment) #set($comment=$column.columnComment)
#end #end
#if($column.htmlType == "input") #if($column.htmlType == "input" || $column.htmlType == "textarea")
<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}"
@ -126,14 +126,14 @@
#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}" v-if="${column.list}"/>
#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 #default="scope"> <template #default="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 && "" != $column.dictType)
<el-table-column label="${comment}" align="center" prop="${javaField}"> <el-table-column label="${comment}" align="center" prop="${javaField}">
<template #default="scope"> <template #default="scope">
#if($column.htmlType == "checkbox") #if($column.htmlType == "checkbox")
@ -181,7 +181,6 @@
#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))
#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))
@ -261,8 +260,8 @@
<el-form-item label="${comment}" prop="${field}"> <el-form-item label="${comment}" prop="${field}">
<el-date-picker clearable size="small" <el-date-picker clearable size="small"
v-model="form.${field}" v-model="form.${field}"
type="date" type="datetime"
value-format="YYYY-MM-DD" value-format="YYYY-MM-DD HH:mm:ss"
placeholder="选择${comment}"> placeholder="选择${comment}">
</el-date-picker> </el-date-picker>
</el-form-item> </el-form-item>
@ -273,7 +272,6 @@
#end #end
#end #end
#end #end
#end
#if($table.sub) #if($table.sub)
<el-divider content-position="center">${subTable.functionName}信息</el-divider> <el-divider content-position="center">${subTable.functionName}信息</el-divider>
<el-row :gutter="10" class="mb8"> <el-row :gutter="10" class="mb8">
@ -309,7 +307,7 @@
</el-form> </el-form>
<template #footer> <template #footer>
<div class="dialog-footer"> <div class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button> <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button> <el-button @click="cancel">取 消</el-button>
</div> </div>
</template> </template>
@ -331,6 +329,7 @@ const ${businessName}List = ref([]);
const ${subclassName}List = ref([]); const ${subclassName}List = ref([]);
#end #end
const open = ref(false); const open = ref(false);
const buttonLoading = ref(false);
const loading = ref(true); const loading = ref(true);
const showSearch = ref(true); const showSearch = ref(true);
const ids = ref([]); const ids = ref([]);
@ -353,14 +352,14 @@ const data = reactive({
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($foreach.count != $columns.size()),#end $column.javaField: undefined#if($foreach.count != $columns.size()),#end
#end #end
#end #end
}, },
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)
@ -462,9 +461,11 @@ function handleAdd() {
/** 修改按钮操作 */ /** 修改按钮操作 */
function handleUpdate(row) { function handleUpdate(row) {
loading.value = true
reset(); reset();
const ${pkColumn.javaField} = row.${pkColumn.javaField} || ids.value const ${pkColumn.javaField} = row.${pkColumn.javaField} || ids.value
get${BusinessName}(${pkColumn.javaField}).then(response => { get${BusinessName}(${pkColumn.javaField}).then(response => {
loading.value = false;
form.value = response.data; form.value = response.data;
#foreach ($column in $columns) #foreach ($column in $columns)
#if($column.htmlType == "checkbox") #if($column.htmlType == "checkbox")
@ -483,6 +484,7 @@ function handleUpdate(row) {
function submitForm() { function submitForm() {
proxy.#[[$]]#refs["${businessName}Ref"].validate(valid => { proxy.#[[$]]#refs["${businessName}Ref"].validate(valid => {
if (valid) { if (valid) {
buttonLoading.value = true;
#foreach ($column in $columns) #foreach ($column in $columns)
#if($column.htmlType == "checkbox") #if($column.htmlType == "checkbox")
form.value.$column.javaField = form.value.${column.javaField}.join(","); form.value.$column.javaField = form.value.${column.javaField}.join(",");
@ -496,12 +498,16 @@ function submitForm() {
proxy.#[[$modal]]#.msgSuccess("修改成功"); proxy.#[[$modal]]#.msgSuccess("修改成功");
open.value = false; open.value = false;
getList(); getList();
}).finally(() => {
buttonLoading.value = false;
}); });
} else { } else {
add${BusinessName}(form.value).then(response => { add${BusinessName}(form.value).then(response => {
proxy.#[[$modal]]#.msgSuccess("新增成功"); proxy.#[[$modal]]#.msgSuccess("新增成功");
open.value = false; open.value = false;
getList(); getList();
}).finally(() => {
buttonLoading.value = false;
}); });
} }
} }
@ -512,11 +518,15 @@ function submitForm() {
function handleDelete(row) { function handleDelete(row) {
const ${pkColumn.javaField}s = row.${pkColumn.javaField} || ids.value; const ${pkColumn.javaField}s = row.${pkColumn.javaField} || ids.value;
proxy.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + ${pkColumn.javaField}s + '"的数据项?').then(function() { proxy.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + ${pkColumn.javaField}s + '"的数据项?').then(function() {
loading.value = true;
return del${BusinessName}(${pkColumn.javaField}s); return del${BusinessName}(${pkColumn.javaField}s);
}).then(() => { }).then(() => {
loading.value = true;
getList(); getList();
proxy.#[[$modal]]#.msgSuccess("删除成功"); proxy.#[[$modal]]#.msgSuccess("删除成功");
}).catch(() => {}); }).finally(() => {
loading.value = false;
});
} }
#if($table.sub) #if($table.sub)