Commit c50d27f5cbb43713c455a15ce12ea15442395c4b

Authored by puhui999
1 parent 80db28ee

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

yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/api/api.js.vm
@@ -79,7 +79,7 @@ export function export${simpleClassName}Excel(params) { @@ -79,7 +79,7 @@ export function export${simpleClassName}Excel(params) {
79 #if ( $table.templateType == 11 ) 79 #if ( $table.templateType == 11 )
80 80
81 // 获得${subTable.classComment}分页 81 // 获得${subTable.classComment}分页
82 - export function get${simpleClassName}Page(params) { 82 + export function get${subSimpleClassName}Page(params) {
83 return request({ 83 return request({
84 url: '${baseURL}/${subSimpleClassName_strikeCase}/page', 84 url: '${baseURL}/${subSimpleClassName_strikeCase}/page',
85 method: 'get', 85 method: 'get',
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/components/form_sub_erp.vue.vm
  1 +#set ($subTable = $subTables.get($subIndex))##当前表
1 #set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组 2 #set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
2 #set ($subSimpleClassName = $subSimpleClassNames.get($subIndex)) 3 #set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
3 #set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 4 #set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
@@ -155,13 +156,13 @@ @@ -155,13 +156,13 @@
155 try { 156 try {
156 ${simpleClassName}Api.get${subSimpleClassName}(id).then(res=>{ 157 ${simpleClassName}Api.get${subSimpleClassName}(id).then(res=>{
157 that.formData = res.data; 158 that.formData = res.data;
158 - that.dialogTitle = "修改${table.classComment}"; 159 + that.dialogTitle = "修改${subTable.classComment}";
159 }) 160 })
160 } finally { 161 } finally {
161 this.formLoading = false; 162 this.formLoading = false;
162 } 163 }
163 } 164 }
164 - this.dialogTitle = "新增${table.classComment}"; 165 + this.dialogTitle = "新增${subTable.classComment}";
165 }, 166 },
166 /** 提交按钮 */ 167 /** 提交按钮 */
167 submitForm() { 168 submitForm() {
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/components/form_sub_normal.vue.vm
@@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
5 #set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 5 #set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
6 #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 6 #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
7 <template> 7 <template>
  8 + <div class="app-container">
8 #if ( $subTable.subJoinMany )## 情况一:一对多,table + form 9 #if ( $subTable.subJoinMany )## 情况一:一对多,table + form
9 <el-form 10 <el-form
10 ref="formRef" 11 ref="formRef"
@@ -216,6 +217,7 @@ @@ -216,6 +217,7 @@
216 #end 217 #end
217 </el-form> 218 </el-form>
218 #end 219 #end
  220 + </div>
219 </template> 221 </template>
220 222
221 <script> 223 <script>
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/components/list_sub_erp.vue.vm
  1 +#set ($subTable = $subTables.get($subIndex))##当前表
  2 +#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
  3 +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
  4 +#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
  5 +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
  6 +#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
1 <template> 7 <template>
2 <div class="app-container"> 8 <div class="app-container">
3 #if ($table.templateType == 11) 9 #if ($table.templateType == 11)
@@ -95,8 +101,10 @@ @@ -95,8 +101,10 @@
95 watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ 101 watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */
96 ${subJoinColumn.javaField}:{ 102 ${subJoinColumn.javaField}:{
97 handler(val) { 103 handler(val) {
98 - this.queryParams.${subJoinColumn.javaField} = val  
99 - this.handleQuery() 104 + this.queryParams.${subJoinColumn.javaField} = val;
  105 + if (val){
  106 + this.handleQuery();
  107 + }
100 }, 108 },
101 immediate: true 109 immediate: true
102 } 110 }
@@ -158,7 +166,7 @@ @@ -158,7 +166,7 @@
158 }).catch(() => {}); 166 }).catch(() => {});
159 } catch {} 167 } catch {}
160 }, 168 },
161 - }  
162 #end 169 #end
  170 + }
163 }; 171 };
164 </script> 172 </script>
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/form.vue.vm
@@ -214,7 +214,7 @@ @@ -214,7 +214,7 @@
214 this.title = "新增${table.classComment}"; 214 this.title = "新增${table.classComment}";
215 ## 特殊:树表专属逻辑 215 ## 特殊:树表专属逻辑
216 #if ( $table.templateType == 2 ) 216 #if ( $table.templateType == 2 )
217 - this.get${simpleClassName}Tree() 217 + this.get${simpleClassName}Tree();
218 #end 218 #end
219 }, 219 },
220 /** 提交按钮 */ 220 /** 提交按钮 */
@@ -241,7 +241,7 @@ @@ -241,7 +241,7 @@
241 data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = that.getRef('${subClassNameVar}FormRef').getData(); 241 data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = that.getRef('${subClassNameVar}FormRef').getData();
242 #end 242 #end
243 }).catch((err) => { 243 }).catch((err) => {
244 - validate = false 244 + validate = false;
245 that.subTabsName = err.replace("FormRef", ""); // 定位到没有校验通过的子表单 245 that.subTabsName = err.replace("FormRef", ""); // 定位到没有校验通过的子表单
246 }) 246 })
247 #end 247 #end
@@ -266,11 +266,11 @@ @@ -266,11 +266,11 @@
266 that.#[[$]]#emit('success'); 266 that.#[[$]]#emit('success');
267 }); 267 });
268 }finally { 268 }finally {
269 - this.formLoading = false 269 + this.formLoading = false;
270 } 270 }
271 }, 271 },
272 - getRef(refName){ // TODO puhui999: 获得表单 ref,提取出来的目的呢是解决 #[[$]]# 在 if 中 end闭合不了的问题,代码生成后可删除此方法  
273 - return this.#[[$]]#refs[refName] 272 + getRef(refName){
  273 + return this.#[[$]]#refs[refName];
274 }, 274 },
275 ## 特殊:主子表专属逻辑 275 ## 特殊:主子表专属逻辑
276 #if ( $table.templateType == 10 || $table.templateType == 12 ) 276 #if ( $table.templateType == 10 || $table.templateType == 12 )
@@ -278,12 +278,12 @@ @@ -278,12 +278,12 @@
278 /** 校验子表单 */ 278 /** 校验子表单 */
279 validateSubFrom(item) { 279 validateSubFrom(item) {
280 return new Promise((resolve, reject) => { 280 return new Promise((resolve, reject) => {
281 - this.$refs[item].validate() 281 + this.getRef(item).validate()
282 .then(() => { 282 .then(() => {
283 - resolve() 283 + resolve();
284 }) 284 })
285 .catch(() => { 285 .catch(() => {
286 - reject(item) 286 + reject(item);
287 }) 287 })
288 }) 288 })
289 }, 289 },
@@ -299,14 +299,14 @@ @@ -299,14 +299,14 @@
299 ]; 299 ];
300 const validArr = []; // 校验 300 const validArr = []; // 校验
301 for (const item of validFormRefArr) { 301 for (const item of validFormRefArr) {
302 - validArr.push(this.validateSubFrom(item)) 302 + validArr.push(this.validateSubFrom(item));
303 } 303 }
304 return new Promise((resolve, reject) => { 304 return new Promise((resolve, reject) => {
305 // 校验所有 305 // 校验所有
306 Promise.all(validArr).then(() => { 306 Promise.all(validArr).then(() => {
307 - resolve() 307 + resolve();
308 }).catch((err) => { 308 }).catch((err) => {
309 - reject(err) 309 + reject(err);
310 }) 310 })
311 }) 311 })
312 }, 312 },
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/index.vue.vm
@@ -152,14 +152,14 @@ @@ -152,14 +152,14 @@
152 ## 特殊:主子表专属逻辑 152 ## 特殊:主子表专属逻辑
153 #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 ) 153 #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
154 <!-- 子表的列表 --> 154 <!-- 子表的列表 -->
155 - <el-tabs model-value="$subClassNameVars.get(0)"> 155 + <el-tabs v-model="subTabsName">
156 #foreach ($subTable in $subTables) 156 #foreach ($subTable in $subTables)
157 #set ($index = $foreach.count - 1) 157 #set ($index = $foreach.count - 1)
158 #set ($subClassNameVar = $subClassNameVars.get($index)) 158 #set ($subClassNameVar = $subClassNameVars.get($index))
159 #set ($subSimpleClassName = $subSimpleClassNames.get($index)) 159 #set ($subSimpleClassName = $subSimpleClassNames.get($index))
160 #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index)) 160 #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
161 <el-tab-pane label="${subTable.classComment}" name="$subClassNameVar"> 161 <el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
162 - <${subSimpleClassName}List :${subJoinColumn_strikeCase}="currentRow.id" /> 162 + <${subSimpleClassName}List v-if="currentRow.id" :${subJoinColumn_strikeCase}="currentRow.id" />
163 </el-tab-pane> 163 </el-tab-pane>
164 #end 164 #end
165 </el-tabs> 165 </el-tabs>
@@ -247,7 +247,14 @@ export default { @@ -247,7 +247,14 @@ export default {
247 #end 247 #end
248 #end 248 #end
249 #end 249 #end
250 - } 250 + },
  251 + ## 特殊:主子表专属逻辑-erp
  252 + #if ( $table.templateType == 11)
  253 + #if ( $subTables && $subTables.size() > 0 )
  254 + /** 子表的列表 */
  255 + subTabsName: '$subClassNameVars.get(0)'
  256 + #end
  257 + #end
251 }; 258 };
252 }, 259 },
253 created() { 260 created() {
@@ -285,7 +292,7 @@ export default { @@ -285,7 +292,7 @@ export default {
285 }, 292 },
286 /** 添加/修改操作 */ 293 /** 添加/修改操作 */
287 openForm(id) { 294 openForm(id) {
288 - this.#[[$]]#refs["formRef"].open(id) 295 + this.#[[$]]#refs["formRef"].open(id);
289 }, 296 },
290 /** 删除按钮操作 */ 297 /** 删除按钮操作 */
291 handleDelete(row) { 298 handleDelete(row) {
@@ -319,7 +326,11 @@ export default { @@ -319,7 +326,11 @@ export default {
319 #if ( $table.templateType == 11 ) 326 #if ( $table.templateType == 11 )
320 /** 选中行操作 */ 327 /** 选中行操作 */
321 handleCurrentChange(row) { 328 handleCurrentChange(row) {
322 - this.currentRow = row 329 + this.currentRow = row;
  330 + #if ( $subTables && $subTables.size() > 0 )
  331 + /** 子表的列表 */
  332 + this.subTabsName = '$subClassNameVars.get(0)';
  333 + #end
323 }, 334 },
324 #end 335 #end
325 ## 特殊:树表专属逻辑 336 ## 特殊:树表专属逻辑