代码生成:完善 vue2 模版,适配树表和主子表

This commit is contained in:
puhui999 2023-11-21 11:58:04 +08:00
parent 80db28ee5b
commit c50d27f5cb
6 changed files with 44 additions and 22 deletions

View File

@ -79,7 +79,7 @@ export function export${simpleClassName}Excel(params) {
#if ( $table.templateType == 11 ) #if ( $table.templateType == 11 )
// 获得${subTable.classComment}分页 // 获得${subTable.classComment}分页
export function get${simpleClassName}Page(params) { export function get${subSimpleClassName}Page(params) {
return request({ return request({
url: '${baseURL}/${subSimpleClassName_strikeCase}/page', url: '${baseURL}/${subSimpleClassName_strikeCase}/page',
method: 'get', method: 'get',

View File

@ -1,3 +1,4 @@
#set ($subTable = $subTables.get($subIndex))##当前表
#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组 #set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex)) #set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 #set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
@ -155,13 +156,13 @@
try { try {
${simpleClassName}Api.get${subSimpleClassName}(id).then(res=>{ ${simpleClassName}Api.get${subSimpleClassName}(id).then(res=>{
that.formData = res.data; that.formData = res.data;
that.dialogTitle = "修改${table.classComment}"; that.dialogTitle = "修改${subTable.classComment}";
}) })
} finally { } finally {
this.formLoading = false; this.formLoading = false;
} }
} }
this.dialogTitle = "新增${table.classComment}"; this.dialogTitle = "新增${subTable.classComment}";
}, },
/** 提交按钮 */ /** 提交按钮 */
submitForm() { submitForm() {

View File

@ -5,6 +5,7 @@
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 #set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
<template> <template>
<div class="app-container">
#if ( $subTable.subJoinMany )## 情况一一对多table + form #if ( $subTable.subJoinMany )## 情况一一对多table + form
<el-form <el-form
ref="formRef" ref="formRef"
@ -216,6 +217,7 @@
#end #end
</el-form> </el-form>
#end #end
</div>
</template> </template>
<script> <script>

View File

@ -1,3 +1,9 @@
#set ($subTable = $subTables.get($subIndex))##当前表
#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
<template> <template>
<div class="app-container"> <div class="app-container">
#if ($table.templateType == 11) #if ($table.templateType == 11)
@ -95,8 +101,10 @@
watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */
${subJoinColumn.javaField}:{ ${subJoinColumn.javaField}:{
handler(val) { handler(val) {
this.queryParams.${subJoinColumn.javaField} = val this.queryParams.${subJoinColumn.javaField} = val;
this.handleQuery() if (val){
this.handleQuery();
}
}, },
immediate: true immediate: true
} }
@ -158,7 +166,7 @@
}).catch(() => {}); }).catch(() => {});
} catch {} } catch {}
}, },
}
#end #end
}
}; };
</script> </script>

View File

@ -214,7 +214,7 @@
this.title = "新增${table.classComment}"; this.title = "新增${table.classComment}";
## 特殊:树表专属逻辑 ## 特殊:树表专属逻辑
#if ( $table.templateType == 2 ) #if ( $table.templateType == 2 )
this.get${simpleClassName}Tree() this.get${simpleClassName}Tree();
#end #end
}, },
/** 提交按钮 */ /** 提交按钮 */
@ -241,7 +241,7 @@
data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = that.getRef('${subClassNameVar}FormRef').getData(); data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = that.getRef('${subClassNameVar}FormRef').getData();
#end #end
}).catch((err) => { }).catch((err) => {
validate = false validate = false;
that.subTabsName = err.replace("FormRef", ""); // 定位到没有校验通过的子表单 that.subTabsName = err.replace("FormRef", ""); // 定位到没有校验通过的子表单
}) })
#end #end
@ -266,11 +266,11 @@
that.#[[$]]#emit('success'); that.#[[$]]#emit('success');
}); });
}finally { }finally {
this.formLoading = false this.formLoading = false;
} }
}, },
getRef(refName){ // TODO puhui999: 获得表单 ref提取出来的目的呢是解决 #[[$]]# 在 if 中 end闭合不了的问题代码生成后可删除此方法 getRef(refName){
return this.#[[$]]#refs[refName] return this.#[[$]]#refs[refName];
}, },
## 特殊:主子表专属逻辑 ## 特殊:主子表专属逻辑
#if ( $table.templateType == 10 || $table.templateType == 12 ) #if ( $table.templateType == 10 || $table.templateType == 12 )
@ -278,12 +278,12 @@
/** 校验子表单 */ /** 校验子表单 */
validateSubFrom(item) { validateSubFrom(item) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.$refs[item].validate() this.getRef(item).validate()
.then(() => { .then(() => {
resolve() resolve();
}) })
.catch(() => { .catch(() => {
reject(item) reject(item);
}) })
}) })
}, },
@ -299,14 +299,14 @@
]; ];
const validArr = []; // 校验 const validArr = []; // 校验
for (const item of validFormRefArr) { for (const item of validFormRefArr) {
validArr.push(this.validateSubFrom(item)) validArr.push(this.validateSubFrom(item));
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// 校验所有 // 校验所有
Promise.all(validArr).then(() => { Promise.all(validArr).then(() => {
resolve() resolve();
}).catch((err) => { }).catch((err) => {
reject(err) reject(err);
}) })
}) })
}, },

View File

@ -152,14 +152,14 @@
## 特殊:主子表专属逻辑 ## 特殊:主子表专属逻辑
#if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 ) #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
<!-- 子表的列表 --> <!-- 子表的列表 -->
<el-tabs model-value="$subClassNameVars.get(0)"> <el-tabs v-model="subTabsName">
#foreach ($subTable in $subTables) #foreach ($subTable in $subTables)
#set ($index = $foreach.count - 1) #set ($index = $foreach.count - 1)
#set ($subClassNameVar = $subClassNameVars.get($index)) #set ($subClassNameVar = $subClassNameVars.get($index))
#set ($subSimpleClassName = $subSimpleClassNames.get($index)) #set ($subSimpleClassName = $subSimpleClassNames.get($index))
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index)) #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
<el-tab-pane label="${subTable.classComment}" name="$subClassNameVar"> <el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
<${subSimpleClassName}List :${subJoinColumn_strikeCase}="currentRow.id" /> <${subSimpleClassName}List v-if="currentRow.id" :${subJoinColumn_strikeCase}="currentRow.id" />
</el-tab-pane> </el-tab-pane>
#end #end
</el-tabs> </el-tabs>
@ -247,7 +247,14 @@ export default {
#end #end
#end #end
#end #end
} },
## 特殊:主子表专属逻辑-erp
#if ( $table.templateType == 11)
#if ( $subTables && $subTables.size() > 0 )
/** 子表的列表 */
subTabsName: '$subClassNameVars.get(0)'
#end
#end
}; };
}, },
created() { created() {
@ -285,7 +292,7 @@ export default {
}, },
/** 添加/修改操作 */ /** 添加/修改操作 */
openForm(id) { openForm(id) {
this.#[[$]]#refs["formRef"].open(id) this.#[[$]]#refs["formRef"].open(id);
}, },
/** 删除按钮操作 */ /** 删除按钮操作 */
handleDelete(row) { handleDelete(row) {
@ -319,7 +326,11 @@ export default {
#if ( $table.templateType == 11 ) #if ( $table.templateType == 11 )
/** 选中行操作 */ /** 选中行操作 */
handleCurrentChange(row) { handleCurrentChange(row) {
this.currentRow = row this.currentRow = row;
#if ( $subTables && $subTables.size() > 0 )
/** 子表的列表 */
this.subTabsName = '$subClassNameVars.get(0)';
#end
}, },
#end #end
## 特殊:树表专属逻辑 ## 特殊:树表专属逻辑