代码生成:完善 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 )
// 获得${subTable.classComment}分页
export function get${simpleClassName}Page(params) {
export function get${subSimpleClassName}Page(params) {
return request({
url: '${baseURL}/${subSimpleClassName_strikeCase}/page',
method: 'get',

View File

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

View File

@ -5,6 +5,7 @@
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
<template>
<div class="app-container">
#if ( $subTable.subJoinMany )## 情况一一对多table + form
<el-form
ref="formRef"
@ -216,6 +217,7 @@
#end
</el-form>
#end
</div>
</template>
<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>
<div class="app-container">
#if ($table.templateType == 11)
@ -95,8 +101,10 @@
watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */
${subJoinColumn.javaField}:{
handler(val) {
this.queryParams.${subJoinColumn.javaField} = val
this.handleQuery()
this.queryParams.${subJoinColumn.javaField} = val;
if (val){
this.handleQuery();
}
},
immediate: true
}
@ -158,7 +166,7 @@
}).catch(() => {});
} catch {}
},
}
#end
}
};
</script>

View File

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

View File

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