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 79 #if ( $table.templateType == 11 )
80 80  
81 81 // 获得${subTable.classComment}分页
82   - export function get${simpleClassName}Page(params) {
  82 + export function get${subSimpleClassName}Page(params) {
83 83 return request({
84 84 url: '${baseURL}/${subSimpleClassName_strikeCase}/page',
85 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 2 #set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
2 3 #set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
3 4 #set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
... ... @@ -155,13 +156,13 @@
155 156 try {
156 157 ${simpleClassName}Api.get${subSimpleClassName}(id).then(res=>{
157 158 that.formData = res.data;
158   - that.dialogTitle = "修改${table.classComment}";
  159 + that.dialogTitle = "修改${subTable.classComment}";
159 160 })
160 161 } finally {
161 162 this.formLoading = false;
162 163 }
163 164 }
164   - this.dialogTitle = "新增${table.classComment}";
  165 + this.dialogTitle = "新增${subTable.classComment}";
165 166 },
166 167 /** 提交按钮 */
167 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 5 #set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
6 6 #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
7 7 <template>
  8 + <div class="app-container">
8 9 #if ( $subTable.subJoinMany )## 情况一:一对多,table + form
9 10 <el-form
10 11 ref="formRef"
... ... @@ -216,6 +217,7 @@
216 217 #end
217 218 </el-form>
218 219 #end
  220 + </div>
219 221 </template>
220 222  
221 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 7 <template>
2 8 <div class="app-container">
3 9 #if ($table.templateType == 11)
... ... @@ -95,8 +101,10 @@
95 101 watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */
96 102 ${subJoinColumn.javaField}:{
97 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 109 immediate: true
102 110 }
... ... @@ -158,7 +166,7 @@
158 166 }).catch(() => {});
159 167 } catch {}
160 168 },
161   - }
162 169 #end
  170 + }
163 171 };
164 172 </script>
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/form.vue.vm
... ... @@ -214,7 +214,7 @@
214 214 this.title = "新增${table.classComment}";
215 215 ## 特殊:树表专属逻辑
216 216 #if ( $table.templateType == 2 )
217   - this.get${simpleClassName}Tree()
  217 + this.get${simpleClassName}Tree();
218 218 #end
219 219 },
220 220 /** 提交按钮 */
... ... @@ -241,7 +241,7 @@
241 241 data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = that.getRef('${subClassNameVar}FormRef').getData();
242 242 #end
243 243 }).catch((err) => {
244   - validate = false
  244 + validate = false;
245 245 that.subTabsName = err.replace("FormRef", ""); // 定位到没有校验通过的子表单
246 246 })
247 247 #end
... ... @@ -266,11 +266,11 @@
266 266 that.#[[$]]#emit('success');
267 267 });
268 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 276 #if ( $table.templateType == 10 || $table.templateType == 12 )
... ... @@ -278,12 +278,12 @@
278 278 /** 校验子表单 */
279 279 validateSubFrom(item) {
280 280 return new Promise((resolve, reject) => {
281   - this.$refs[item].validate()
  281 + this.getRef(item).validate()
282 282 .then(() => {
283   - resolve()
  283 + resolve();
284 284 })
285 285 .catch(() => {
286   - reject(item)
  286 + reject(item);
287 287 })
288 288 })
289 289 },
... ... @@ -299,14 +299,14 @@
299 299 ];
300 300 const validArr = []; // 校验
301 301 for (const item of validFormRefArr) {
302   - validArr.push(this.validateSubFrom(item))
  302 + validArr.push(this.validateSubFrom(item));
303 303 }
304 304 return new Promise((resolve, reject) => {
305 305 // 校验所有
306 306 Promise.all(validArr).then(() => {
307   - resolve()
  307 + resolve();
308 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 152 ## 特殊:主子表专属逻辑
153 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 156 #foreach ($subTable in $subTables)
157 157 #set ($index = $foreach.count - 1)
158 158 #set ($subClassNameVar = $subClassNameVars.get($index))
159 159 #set ($subSimpleClassName = $subSimpleClassNames.get($index))
160 160 #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
161 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 163 </el-tab-pane>
164 164 #end
165 165 </el-tabs>
... ... @@ -247,7 +247,14 @@ export default {
247 247 #end
248 248 #end
249 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 260 created() {
... ... @@ -285,7 +292,7 @@ export default {
285 292 },
286 293 /** 添加/修改操作 */
287 294 openForm(id) {
288   - this.#[[$]]#refs["formRef"].open(id)
  295 + this.#[[$]]#refs["formRef"].open(id);
289 296 },
290 297 /** 删除按钮操作 */
291 298 handleDelete(row) {
... ... @@ -319,7 +326,11 @@ export default {
319 326 #if ( $table.templateType == 11 )
320 327 /** 选中行操作 */
321 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 335 #end
325 336 ## 特殊:树表专属逻辑
... ...