Commit 77bb57a2eecf741516606d367b2b5d03c7ff8d44

Authored by YunaiV
1 parent 0d55ca74

开始制作 vue 页面的模板

ruoyi-generator/src/main/resources/vm/vue/index.vue.vm deleted
1   -<template>
2   - <div class="app-container">
3   - <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
4   -#foreach($column in $columns)
5   -#if($column.query)
6   -#set($dictType=$column.dictType)
7   -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
8   -#set($parentheseIndex=$column.columnComment.indexOf("("))
9   -#if($parentheseIndex != -1)
10   -#set($comment=$column.columnComment.substring(0, $parentheseIndex))
11   -#else
12   -#set($comment=$column.columnComment)
13   -#end
14   -#if($column.htmlType == "input")
15   - <el-form-item label="${comment}" prop="${column.javaField}">
16   - <el-input
17   - v-model="queryParams.${column.javaField}"
18   - placeholder="请输入${comment}"
19   - clearable
20   - size="small"
21   - @keyup.enter.native="handleQuery"
22   - />
23   - </el-form-item>
24   -#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
25   - <el-form-item label="${comment}" prop="${column.javaField}">
26   - <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small">
27   - <el-option
28   - v-for="dict in ${column.javaField}Options"
29   - :key="dict.dictValue"
30   - :label="dict.dictLabel"
31   - :value="dict.dictValue"
32   - />
33   - </el-select>
34   - </el-form-item>
35   -#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType)
36   - <el-form-item label="${comment}" prop="${column.javaField}">
37   - <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small">
38   - <el-option label="请选择字典生成" value="" />
39   - </el-select>
40   - </el-form-item>
41   -#elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN")
42   - <el-form-item label="${comment}" prop="${column.javaField}">
43   - <el-date-picker clearable size="small"
44   - v-model="queryParams.${column.javaField}"
45   - type="date"
46   - value-format="yyyy-MM-dd"
47   - placeholder="选择${comment}">
48   - </el-date-picker>
49   - </el-form-item>
50   -#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
51   - <el-form-item label="${comment}">
52   - <el-date-picker
53   - v-model="daterange${AttrName}"
54   - size="small"
55   - style="width: 240px"
56   - value-format="yyyy-MM-dd"
57   - type="daterange"
58   - range-separator="-"
59   - start-placeholder="开始日期"
60   - end-placeholder="结束日期"
61   - ></el-date-picker>
62   - </el-form-item>
63   -#end
64   -#end
65   -#end
66   - <el-form-item>
67   - <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
68   - <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
69   - </el-form-item>
70   - </el-form>
71   -
72   - <el-row :gutter="10" class="mb8">
73   - <el-col :span="1.5">
74   - <el-button
75   - type="primary"
76   - icon="el-icon-plus"
77   - size="mini"
78   - @click="handleAdd"
79   - v-hasPermi="['${moduleName}:${businessName}:add']"
80   - >新增</el-button>
81   - </el-col>
82   - <el-col :span="1.5">
83   - <el-button
84   - type="success"
85   - icon="el-icon-edit"
86   - size="mini"
87   - :disabled="single"
88   - @click="handleUpdate"
89   - v-hasPermi="['${moduleName}:${businessName}:edit']"
90   - >修改</el-button>
91   - </el-col>
92   - <el-col :span="1.5">
93   - <el-button
94   - type="danger"
95   - icon="el-icon-delete"
96   - size="mini"
97   - :disabled="multiple"
98   - @click="handleDelete"
99   - v-hasPermi="['${moduleName}:${businessName}:remove']"
100   - >删除</el-button>
101   - </el-col>
102   - <el-col :span="1.5">
103   - <el-button
104   - type="warning"
105   - icon="el-icon-download"
106   - size="mini"
107   - @click="handleExport"
108   - v-hasPermi="['${moduleName}:${businessName}:export']"
109   - >导出</el-button>
110   - </el-col>
111   - <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
112   - </el-row>
113   -
114   - <el-table v-loading="loading" :data="${businessName}List" @selection-change="handleSelectionChange">
115   - <el-table-column type="selection" width="55" align="center" />
116   -#foreach($column in $columns)
117   -#set($javaField=$column.javaField)
118   -#set($parentheseIndex=$column.columnComment.indexOf("("))
119   -#if($parentheseIndex != -1)
120   -#set($comment=$column.columnComment.substring(0, $parentheseIndex))
121   -#else
122   -#set($comment=$column.columnComment)
123   -#end
124   -#if($column.pk)
125   - <el-table-column label="${comment}" align="center" prop="${javaField}" />
126   -#elseif($column.list && $column.htmlType == "datetime")
127   - <el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
128   - <template slot-scope="scope">
129   - <span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span>
130   - </template>
131   - </el-table-column>
132   -#elseif($column.list && "" != $column.dictType)
133   - <el-table-column label="${comment}" align="center" prop="${javaField}" :formatter="${javaField}Format" />
134   -#elseif($column.list && "" != $javaField)
135   - <el-table-column label="${comment}" align="center" prop="${javaField}" />
136   -#end
137   -#end
138   - <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
139   - <template slot-scope="scope">
140   - <el-button
141   - size="mini"
142   - type="text"
143   - icon="el-icon-edit"
144   - @click="handleUpdate(scope.row)"
145   - v-hasPermi="['${moduleName}:${businessName}:edit']"
146   - >修改</el-button>
147   - <el-button
148   - size="mini"
149   - type="text"
150   - icon="el-icon-delete"
151   - @click="handleDelete(scope.row)"
152   - v-hasPermi="['${moduleName}:${businessName}:remove']"
153   - >删除</el-button>
154   - </template>
155   - </el-table-column>
156   - </el-table>
157   -
158   - <pagination
159   - v-show="total>0"
160   - :total="total"
161   - :page.sync="queryParams.pageNum"
162   - :limit.sync="queryParams.pageSize"
163   - @pagination="getList"
164   - />
165   -
166   - <!-- 添加或修改${functionName}对话框 -->
167   - <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
168   - <el-form ref="form" :model="form" :rules="rules" label-width="80px">
169   -#foreach($column in $columns)
170   -#set($field=$column.javaField)
171   -#if($column.insert && !$column.pk)
172   -#if(($column.usableColumn) || (!$column.superColumn))
173   -#set($parentheseIndex=$column.columnComment.indexOf("("))
174   -#if($parentheseIndex != -1)
175   -#set($comment=$column.columnComment.substring(0, $parentheseIndex))
176   -#else
177   -#set($comment=$column.columnComment)
178   -#end
179   -#set($dictType=$column.dictType)
180   -#if($column.htmlType == "input")
181   - <el-form-item label="${comment}" prop="${field}">
182   - <el-input v-model="form.${field}" placeholder="请输入${comment}" />
183   - </el-form-item>
184   -#elseif($column.htmlType == "uploadImage")
185   - <el-form-item label="${comment}">
186   - <uploadImage v-model="form.${field}"/>
187   - </el-form-item>
188   -#elseif($column.htmlType == "editor")
189   - <el-form-item label="${comment}">
190   - <editor v-model="form.${field}" :min-height="192"/>
191   - </el-form-item>
192   -#elseif($column.htmlType == "select" && "" != $dictType)
193   - <el-form-item label="${comment}" prop="${field}">
194   - <el-select v-model="form.${field}" placeholder="请选择${comment}">
195   - <el-option
196   - v-for="dict in ${field}Options"
197   - :key="dict.dictValue"
198   - :label="dict.dictLabel"
199   - #if($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.dictValue)"#else:value="dict.dictValue"#end
200   -
201   - ></el-option>
202   - </el-select>
203   - </el-form-item>
204   -#elseif($column.htmlType == "select" && $dictType)
205   - <el-form-item label="${comment}" prop="${field}">
206   - <el-select v-model="form.${field}" placeholder="请选择${comment}">
207   - <el-option label="请选择字典生成" value="" />
208   - </el-select>
209   - </el-form-item>
210   -#elseif($column.htmlType == "checkbox" && "" != $dictType)
211   - <el-form-item label="${comment}">
212   - <el-checkbox-group v-model="form.${field}">
213   - <el-checkbox
214   - v-for="dict in ${field}Options"
215   - :key="dict.dictValue"
216   - :label="dict.dictValue">
217   - {{dict.dictLabel}}
218   - </el-checkbox>
219   - </el-checkbox-group>
220   - </el-form-item>
221   -#elseif($column.htmlType == "checkbox" && $dictType)
222   - <el-form-item label="${comment}">
223   - <el-checkbox-group v-model="form.${field}">
224   - <el-checkbox>请选择字典生成</el-checkbox>
225   - </el-checkbox-group>
226   - </el-form-item>
227   -#elseif($column.htmlType == "radio" && "" != $dictType)
228   - <el-form-item label="${comment}">
229   - <el-radio-group v-model="form.${field}">
230   - <el-radio
231   - v-for="dict in ${field}Options"
232   - :key="dict.dictValue"
233   - #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.dictValue)"#else:label="dict.dictValue"#end
234   -
235   - >{{dict.dictLabel}}</el-radio>
236   - </el-radio-group>
237   - </el-form-item>
238   -#elseif($column.htmlType == "radio" && $dictType)
239   - <el-form-item label="${comment}">
240   - <el-radio-group v-model="form.${field}">
241   - <el-radio label="1">请选择字典生成</el-radio>
242   - </el-radio-group>
243   - </el-form-item>
244   -#elseif($column.htmlType == "datetime")
245   - <el-form-item label="${comment}" prop="${field}">
246   - <el-date-picker clearable size="small"
247   - v-model="form.${field}"
248   - type="date"
249   - value-format="yyyy-MM-dd"
250   - placeholder="选择${comment}">
251   - </el-date-picker>
252   - </el-form-item>
253   -#elseif($column.htmlType == "textarea")
254   - <el-form-item label="${comment}" prop="${field}">
255   - <el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" />
256   - </el-form-item>
257   -#end
258   -#end
259   -#end
260   -#end
261   - </el-form>
262   - <div slot="footer" class="dialog-footer">
263   - <el-button type="primary" @click="submitForm">确 定</el-button>
264   - <el-button @click="cancel">取 消</el-button>
265   - </div>
266   - </el-dialog>
267   - </div>
268   -</template>
269   -
270   -<script>
271   -import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName}, export${BusinessName} } from "@/api/${moduleName}/${businessName}";
272   -#foreach($column in $columns)
273   -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "uploadImage")
274   -import UploadImage from '@/components/UploadImage';
275   -#break
276   -#end
277   -#end
278   -#foreach($column in $columns)
279   -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor")
280   -import Editor from '@/components/Editor';
281   -#break
282   -#end
283   -#end
284   -
285   -export default {
286   - name: "${BusinessName}",
287   - components: {
288   -#foreach($column in $columns)
289   -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "uploadImage")
290   - UploadImage,
291   -#break
292   -#end
293   -#end
294   -#foreach($column in $columns)
295   -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor")
296   - Editor,
297   -#break
298   -#end
299   -#end
300   - },
301   - data() {
302   - return {
303   - // 遮罩层
304   - loading: true,
305   - // 选中数组
306   - ids: [],
307   - // 非单个禁用
308   - single: true,
309   - // 非多个禁用
310   - multiple: true,
311   - // 显示搜索条件
312   - showSearch: true,
313   - // 总条数
314   - total: 0,
315   - // ${functionName}表格数据
316   - ${businessName}List: [],
317   - // 弹出层标题
318   - title: "",
319   - // 是否显示弹出层
320   - open: false,
321   -#foreach ($column in $columns)
322   -#set($parentheseIndex=$column.columnComment.indexOf("("))
323   -#if($parentheseIndex != -1)
324   -#set($comment=$column.columnComment.substring(0, $parentheseIndex))
325   -#else
326   -#set($comment=$column.columnComment)
327   -#end
328   -#if(${column.dictType} != '')
329   - // $comment字典
330   - ${column.javaField}Options: [],
331   -#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
332   -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
333   - // $comment时间范围
334   - daterange${AttrName}: [],
335   -#end
336   -#end
337   - // 查询参数
338   - queryParams: {
339   - pageNum: 1,
340   - pageSize: 10,
341   -#foreach ($column in $columns)
342   -#if($column.query)
343   - $column.javaField: null#if($velocityCount != $columns.size()),#end
344   -
345   -#end
346   -#end
347   - },
348   - // 表单参数
349   - form: {},
350   - // 表单校验
351   - rules: {
352   -#foreach ($column in $columns)
353   -#if($column.required)
354   -#set($parentheseIndex=$column.columnComment.indexOf("("))
355   -#if($parentheseIndex != -1)
356   -#set($comment=$column.columnComment.substring(0, $parentheseIndex))
357   -#else
358   -#set($comment=$column.columnComment)
359   -#end
360   - $column.javaField: [
361   - { required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }
362   - ]#if($velocityCount != $columns.size()),#end
363   -
364   -#end
365   -#end
366   - }
367   - };
368   - },
369   - created() {
370   - this.getList();
371   -#foreach ($column in $columns)
372   -#if(${column.dictType} != '')
373   - this.getDicts("${column.dictType}").then(response => {
374   - this.${column.javaField}Options = response.data;
375   - });
376   -#end
377   -#end
378   - },
379   - methods: {
380   - /** 查询${functionName}列表 */
381   - getList() {
382   - this.loading = true;
383   -#foreach ($column in $columns)
384   -#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
385   - this.queryParams.params = {};
386   -#break
387   -#end
388   -#end
389   -#foreach ($column in $columns)
390   -#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
391   -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
392   - if (null != this.daterange${AttrName} && '' != this.daterange${AttrName}) {
393   - this.queryParams.params["begin${AttrName}"] = this.daterange${AttrName}[0];
394   - this.queryParams.params["end${AttrName}"] = this.daterange${AttrName}[1];
395   - }
396   -#end
397   -#end
398   - list${BusinessName}(this.queryParams).then(response => {
399   - this.${businessName}List = response.rows;
400   - this.total = response.total;
401   - this.loading = false;
402   - });
403   - },
404   -#foreach ($column in $columns)
405   -#if(${column.dictType} != '')
406   -#set($parentheseIndex=$column.columnComment.indexOf("("))
407   -#if($parentheseIndex != -1)
408   -#set($comment=$column.columnComment.substring(0, $parentheseIndex))
409   -#else
410   -#set($comment=$column.columnComment)
411   -#end
412   - // $comment字典翻译
413   - ${column.javaField}Format(row, column) {
414   - return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField});
415   - },
416   -#end
417   -#end
418   - // 取消按钮
419   - cancel() {
420   - this.open = false;
421   - this.reset();
422   - },
423   - // 表单重置
424   - reset() {
425   - this.form = {
426   -#foreach ($column in $columns)
427   -#if($column.htmlType == "radio")
428   - $column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end
429   -
430   -#elseif($column.htmlType == "checkbox")
431   - $column.javaField: []#if($velocityCount != $columns.size()),#end
432   -
433   -#else
434   - $column.javaField: null#if($velocityCount != $columns.size()),#end
435   -
436   -#end
437   -#end
438   - };
439   - this.resetForm("form");
440   - },
441   - /** 搜索按钮操作 */
442   - handleQuery() {
443   - this.queryParams.pageNum = 1;
444   - this.getList();
445   - },
446   - /** 重置按钮操作 */
447   - resetQuery() {
448   -#foreach ($column in $columns)
449   -#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
450   -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
451   - this.daterange${AttrName} = [];
452   -#end
453   -#end
454   - this.resetForm("queryForm");
455   - this.handleQuery();
456   - },
457   - // 多选框选中数据
458   - handleSelectionChange(selection) {
459   - this.ids = selection.map(item => item.${pkColumn.javaField})
460   - this.single = selection.length!==1
461   - this.multiple = !selection.length
462   - },
463   - /** 新增按钮操作 */
464   - handleAdd() {
465   - this.reset();
466   - this.open = true;
467   - this.title = "添加${functionName}";
468   - },
469   - /** 修改按钮操作 */
470   - handleUpdate(row) {
471   - this.reset();
472   - const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids
473   - get${BusinessName}(${pkColumn.javaField}).then(response => {
474   - this.form = response.data;
475   -#foreach ($column in $columns)
476   -#if($column.htmlType == "checkbox")
477   - this.form.$column.javaField = this.form.${column.javaField}.split(",");
478   -#end
479   -#end
480   - this.open = true;
481   - this.title = "修改${functionName}";
482   - });
483   - },
484   - /** 提交按钮 */
485   - submitForm() {
486   - this.#[[$]]#refs["form"].validate(valid => {
487   - if (valid) {
488   -#foreach ($column in $columns)
489   -#if($column.htmlType == "checkbox")
490   - this.form.$column.javaField = this.form.${column.javaField}.join(",");
491   -#end
492   -#end
493   - if (this.form.${pkColumn.javaField} != null) {
494   - update${BusinessName}(this.form).then(response => {
495   - this.msgSuccess("修改成功");
496   - this.open = false;
497   - this.getList();
498   - });
499   - } else {
500   - add${BusinessName}(this.form).then(response => {
501   - this.msgSuccess("新增成功");
502   - this.open = false;
503   - this.getList();
504   - });
505   - }
506   - }
507   - });
508   - },
509   - /** 删除按钮操作 */
510   - handleDelete(row) {
511   - const ${pkColumn.javaField}s = row.${pkColumn.javaField} || this.ids;
512   - this.$confirm('是否确认删除${functionName}编号为"' + ${pkColumn.javaField}s + '"的数据项?', "警告", {
513   - confirmButtonText: "确定",
514   - cancelButtonText: "取消",
515   - type: "warning"
516   - }).then(function() {
517   - return del${BusinessName}(${pkColumn.javaField}s);
518   - }).then(() => {
519   - this.getList();
520   - this.msgSuccess("删除成功");
521   - })
522   - },
523   - /** 导出按钮操作 */
524   - handleExport() {
525   - const queryParams = this.queryParams;
526   - this.$confirm('是否确认导出所有${functionName}数据项?', "警告", {
527   - confirmButtonText: "确定",
528   - cancelButtonText: "取消",
529   - type: "warning"
530   - }).then(function() {
531   - return export${BusinessName}(queryParams);
532   - }).then(response => {
533   - this.download(response.msg);
534   - })
535   - }
536   - }
537   -};
538   -</script>
src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenEngine.java
... ... @@ -72,6 +72,8 @@ public class ToolCodegenEngine {
72 72 .put(javaTemplatePath("service/serviceImpl"),
73 73 javaFilePath("service/${table.businessName}/impl/${table.className}ServiceImpl"))
74 74 // Vue
  75 + .put(vueTemplatePath("views/index.vue"),
  76 + vueFilePath("views/${table.moduleName}/${table.businessName}/index.vue"))
75 77 // SQL
76 78 .build();
77 79  
... ... @@ -161,4 +163,12 @@ public class ToolCodegenEngine {
161 163 return "java/${basePackage}/${table.moduleName}/" + path + ".java";
162 164 }
163 165  
  166 + private static String vueTemplatePath(String path) {
  167 + return "codegen/vue/" + path + ".vm";
  168 + }
  169 +
  170 + private static String vueFilePath(String path) {
  171 + return "vue/" + path;
  172 + }
  173 +
164 174 }
... ...
src/main/resources/codegen/java/controller/vo/pageReqVO.vm
... ... @@ -36,7 +36,7 @@ public class ${table.className}PageReqVO extends PageParam {
36 36  
37 37 #columnTpl('end', '结束')
38 38 #else##情况二,非 Between 的时间
39   -#columnTpl('', '')
  39 + #columnTpl('', '')
40 40 #end
41 41  
42 42 #end
... ...
ruoyi-generator/src/main/resources/vm/vue/index-tree.vue.vm renamed to src/main/resources/codegen/vue/views/index.vue.vm
1   -<template>
2   - <div class="app-container">
3   - <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
4   -#foreach($column in $columns)
5   -#if($column.query)
6   -#set($dictType=$column.dictType)
7   -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
8   -#set($parentheseIndex=$column.columnComment.indexOf("("))
9   -#if($parentheseIndex != -1)
10   -#set($comment=$column.columnComment.substring(0, $parentheseIndex))
11   -#else
12   -#set($comment=$column.columnComment)
13   -#end
14   -#if($column.htmlType == "input")
15   - <el-form-item label="${comment}" prop="${column.javaField}">
16   - <el-input
17   - v-model="queryParams.${column.javaField}"
18   - placeholder="请输入${comment}"
19   - clearable
20   - size="small"
21   - @keyup.enter.native="handleQuery"
22   - />
23   - </el-form-item>
24   -#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
25   - <el-form-item label="${comment}" prop="${column.javaField}">
26   - <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small">
27   - <el-option
28   - v-for="dict in ${column.javaField}Options"
29   - :key="dict.dictValue"
30   - :label="dict.dictLabel"
31   - :value="dict.dictValue"
32   - />
33   - </el-select>
34   - </el-form-item>
35   -#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType)
36   - <el-form-item label="${comment}" prop="${column.javaField}">
37   - <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small">
38   - <el-option label="请选择字典生成" value="" />
39   - </el-select>
40   - </el-form-item>
41   -#elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN")
42   - <el-form-item label="${comment}" prop="${column.javaField}">
43   - <el-date-picker clearable size="small"
44   - v-model="queryParams.${column.javaField}"
45   - type="date"
46   - value-format="yyyy-MM-dd"
47   - placeholder="选择${comment}">
48   - </el-date-picker>
49   - </el-form-item>
50   -#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
51   - <el-form-item label="${comment}">
52   - <el-date-picker
53   - v-model="daterange${AttrName}"
54   - size="small"
55   - style="width: 240px"
56   - value-format="yyyy-MM-dd"
57   - type="daterange"
58   - range-separator="-"
59   - start-placeholder="开始日期"
60   - end-placeholder="结束日期"
61   - ></el-date-picker>
62   - </el-form-item>
63   -#end
64   -#end
65   -#end
66   - <el-form-item>
67   - <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
68   - <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
69   - </el-form-item>
70   - </el-form>
71   -
72   - <el-row :gutter="10" class="mb8">
73   - <el-col :span="1.5">
74   - <el-button
75   - type="primary"
76   - icon="el-icon-plus"
77   - size="mini"
78   - @click="handleAdd"
79   - v-hasPermi="['${moduleName}:${businessName}:add']"
80   - >新增</el-button>
81   - </el-col>
82   - <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
83   - </el-row>
84   -
85   - <el-table
86   - v-loading="loading"
87   - :data="${businessName}List"
88   - row-key="${treeCode}"
89   - default-expand-all
90   - :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
91   - >
92   -#foreach($column in $columns)
93   -#set($javaField=$column.javaField)
94   -#set($parentheseIndex=$column.columnComment.indexOf("("))
95   -#if($parentheseIndex != -1)
96   -#set($comment=$column.columnComment.substring(0, $parentheseIndex))
97   -#else
98   -#set($comment=$column.columnComment)
99   -#end
100   -#if($column.pk)
101   -#elseif($column.list && $column.htmlType == "datetime")
102   - <el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
103   - <template slot-scope="scope">
104   - <span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span>
105   - </template>
106   - </el-table-column>
107   -#elseif($column.list && "" != $column.dictType)
108   - <el-table-column label="${comment}" align="center" prop="${javaField}" :formatter="${javaField}Format" />
109   -#elseif($column.list && "" != $javaField)
110   - <el-table-column label="${comment}" align="center" prop="${javaField}" />
111   -#end
112   -#end
113   - <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
114   - <template slot-scope="scope">
115   - <el-button
116   - size="mini"
117   - type="text"
118   - icon="el-icon-edit"
119   - @click="handleUpdate(scope.row)"
120   - v-hasPermi="['${moduleName}:${businessName}:edit']"
121   - >修改</el-button>
122   - <el-button
123   - size="mini"
124   - type="text"
125   - icon="el-icon-delete"
126   - @click="handleDelete(scope.row)"
127   - v-hasPermi="['${moduleName}:${businessName}:remove']"
128   - >删除</el-button>
129   - </template>
130   - </el-table-column>
131   - </el-table>
132   -
133   - <!-- 添加或修改${functionName}对话框 -->
134   - <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
135   - <el-form ref="form" :model="form" :rules="rules" label-width="80px">
136   -#foreach($column in $columns)
137   -#set($field=$column.javaField)
138   -#if($column.insert && !$column.pk)
139   -#if(($column.usableColumn) || (!$column.superColumn))
140   -#set($parentheseIndex=$column.columnComment.indexOf("("))
141   -#if($parentheseIndex != -1)
142   -#set($comment=$column.columnComment.substring(0, $parentheseIndex))
143   -#else
144   -#set($comment=$column.columnComment)
145   -#end
146   -#set($dictType=$column.dictType)
147   -#if("" != $treeParentCode && $column.javaField == $treeParentCode)
148   - <el-form-item label="${comment}" prop="${treeParentCode}">
149   - <treeselect v-model="form.${treeParentCode}" :options="${businessName}Options" :normalizer="normalizer" placeholder="请选择${comment}" />
150   - </el-form-item>
151   -#elseif($column.htmlType == "input")
152   - <el-form-item label="${comment}" prop="${field}">
153   - <el-input v-model="form.${field}" placeholder="请输入${comment}" />
154   - </el-form-item>
155   -#elseif($column.htmlType == "uploadImage")
156   - <el-form-item label="${comment}">
157   - <uploadImage v-model="form.${field}"/>
158   - </el-form-item>
159   -#elseif($column.htmlType == "editor")
160   - <el-form-item label="${comment}">
161   - <editor v-model="form.${field}" :min-height="192"/>
162   - </el-form-item>
163   -#elseif($column.htmlType == "select" && "" != $dictType)
164   - <el-form-item label="${comment}" prop="${field}">
165   - <el-select v-model="form.${field}" placeholder="请选择${comment}">
166   - <el-option
167   - v-for="dict in ${field}Options"
168   - :key="dict.dictValue"
169   - :label="dict.dictLabel"
170   - #if($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.dictValue)"#else:value="dict.dictValue"#end
171   -
172   - ></el-option>
173   - </el-select>
174   - </el-form-item>
175   -#elseif($column.htmlType == "select" && $dictType)
176   - <el-form-item label="${comment}" prop="${field}">
177   - <el-select v-model="form.${field}" placeholder="请选择${comment}">
178   - <el-option label="请选择字典生成" value="" />
179   - </el-select>
180   - </el-form-item>
181   -#elseif($column.htmlType == "checkbox" && "" != $dictType)
182   - <el-form-item label="${comment}">
183   - <el-checkbox-group v-model="form.${field}">
184   - <el-checkbox
185   - v-for="dict in ${field}Options"
186   - :key="dict.dictValue"
187   - :label="dict.dictValue">
188   - {{dict.dictLabel}}
189   - </el-checkbox>
190   - </el-checkbox-group>
191   - </el-form-item>
192   -#elseif($column.htmlType == "checkbox" && $dictType)
193   - <el-form-item label="${comment}">
194   - <el-checkbox-group v-model="form.${field}">
195   - <el-checkbox>请选择字典生成</el-checkbox>
196   - </el-checkbox-group>
197   - </el-form-item>
198   -#elseif($column.htmlType == "radio" && "" != $dictType)
199   - <el-form-item label="${comment}">
200   - <el-radio-group v-model="form.${field}">
201   - <el-radio
202   - v-for="dict in ${field}Options"
203   - :key="dict.dictValue"
204   - #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.dictValue)"#else:label="dict.dictValue"#end
205   -
206   - >{{dict.dictLabel}}</el-radio>
207   - </el-radio-group>
208   - </el-form-item>
209   -#elseif($column.htmlType == "radio" && $dictType)
210   - <el-form-item label="${comment}">
211   - <el-radio-group v-model="form.${field}">
212   - <el-radio label="1">请选择字典生成</el-radio>
213   - </el-radio-group>
214   - </el-form-item>
215   -#elseif($column.htmlType == "datetime")
216   - <el-form-item label="${comment}" prop="${field}">
217   - <el-date-picker clearable size="small"
218   - v-model="form.${field}"
219   - type="date"
220   - value-format="yyyy-MM-dd"
221   - placeholder="选择${comment}">
222   - </el-date-picker>
223   - </el-form-item>
224   -#elseif($column.htmlType == "textarea")
225   - <el-form-item label="${comment}" prop="${field}">
226   - <el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" />
227   - </el-form-item>
228   -#end
229   -#end
230   -#end
231   -#end
232   - </el-form>
233   - <div slot="footer" class="dialog-footer">
234   - <el-button type="primary" @click="submitForm">确 定</el-button>
235   - <el-button @click="cancel">取 消</el-button>
236   - </div>
237   - </el-dialog>
238   - </div>
239   -</template>
240   -
241   -<script>
242   -import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName}, export${BusinessName} } from "@/api/${moduleName}/${businessName}";
243   -import Treeselect from "@riophae/vue-treeselect";
244   -import "@riophae/vue-treeselect/dist/vue-treeselect.css";
245   -#foreach($column in $columns)
246   -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "uploadImage")
247   -import UploadImage from '@/components/UploadImage';
248   -#break
249   -#end
250   -#end
251   -#foreach($column in $columns)
252   -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor")
253   -import Editor from '@/components/Editor';
254   -#break
255   -#end
256   -#end
257   -
258   -export default {
259   - name: "${BusinessName}",
260   - components: {
261   -#foreach($column in $columns)
262   -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "uploadImage")
263   - UploadImage,
264   -#break
265   -#end
266   -#end
267   -#foreach($column in $columns)
268   -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor")
269   - Editor,
270   -#break
271   -#end
272   -#end
273   - Treeselect
274   - },
275   - data() {
276   - return {
277   - // 遮罩层
278   - loading: true,
279   - // 显示搜索条件
280   - showSearch: true,
281   - // ${functionName}表格数据
282   - ${businessName}List: [],
283   - // ${functionName}树选项
284   - ${businessName}Options: [],
285   - // 弹出层标题
286   - title: "",
287   - // 是否显示弹出层
288   - open: false,
289   -#foreach ($column in $columns)
290   -#set($parentheseIndex=$column.columnComment.indexOf("("))
291   -#if($parentheseIndex != -1)
292   -#set($comment=$column.columnComment.substring(0, $parentheseIndex))
293   -#else
294   -#set($comment=$column.columnComment)
295   -#end
296   -#if(${column.dictType} != '')
297   - // $comment字典
298   - ${column.javaField}Options: [],
299   -#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
300   -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
301   - // $comment时间范围
302   - daterange${AttrName}: [],
303   -#end
304   -#end
305   - // 查询参数
306   - queryParams: {
307   -#foreach ($column in $columns)
308   -#if($column.query)
309   - $column.javaField: null#if($velocityCount != $columns.size()),#end
310   -
311   -#end
312   -#end
313   - },
314   - // 表单参数
315   - form: {},
316   - // 表单校验
317   - rules: {
318   -#foreach ($column in $columns)
319   -#if($column.required)
320   -#set($parentheseIndex=$column.columnComment.indexOf("("))
321   -#if($parentheseIndex != -1)
322   -#set($comment=$column.columnComment.substring(0, $parentheseIndex))
323   -#else
324   -#set($comment=$column.columnComment)
325   -#end
326   - $column.javaField: [
327   - { required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }
328   - ]#if($velocityCount != $columns.size()),#end
329   -
330   -#end
331   -#end
332   - }
333   - };
334   - },
335   - created() {
336   - this.getList();
337   -#foreach ($column in $columns)
338   -#if(${column.dictType} != '')
339   - this.getDicts("${column.dictType}").then(response => {
340   - this.${column.javaField}Options = response.data;
341   - });
342   -#end
343   -#end
344   - },
345   - methods: {
346   - /** 查询${functionName}列表 */
347   - getList() {
348   - this.loading = true;
349   -#foreach ($column in $columns)
350   -#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
351   - this.queryParams.params = {};
352   -#break
353   -#end
354   -#end
355   -#foreach ($column in $columns)
356   -#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
357   -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
358   - if (null != this.daterange${AttrName} && '' != this.daterange${AttrName}) {
359   - this.queryParams.params["begin${AttrName}"] = this.daterange${AttrName}[0];
360   - this.queryParams.params["end${AttrName}"] = this.daterange${AttrName}[1];
361   - }
362   -#end
363   -#end
364   - list${BusinessName}(this.queryParams).then(response => {
365   - this.${businessName}List = this.handleTree(response.data, "${treeCode}", "${treeParentCode}");
366   - this.loading = false;
367   - });
368   - },
369   - /** 转换${functionName}数据结构 */
370   - normalizer(node) {
371   - if (node.children && !node.children.length) {
372   - delete node.children;
373   - }
374   - return {
375   - id: node.${treeCode},
376   - label: node.${treeName},
377   - children: node.children
378   - };
379   - },
380   - /** 查询部门下拉树结构 */
381   - getTreeselect() {
382   - list${BusinessName}().then(response => {
383   - this.${businessName}Options = [];
384   - const data = { ${treeCode}: 0, ${treeName}: '顶级节点', children: [] };
385   - data.children = this.handleTree(response.data, "${treeCode}", "${treeParentCode}");
386   - this.${businessName}Options.push(data);
387   - });
388   - },
389   -#foreach ($column in $columns)
390   -#if(${column.dictType} != '')
391   -#set($parentheseIndex=$column.columnComment.indexOf("("))
392   -#if($parentheseIndex != -1)
393   -#set($comment=$column.columnComment.substring(0, $parentheseIndex))
394   -#else
395   -#set($comment=$column.columnComment)
396   -#end
397   - // $comment字典翻译
398   - ${column.javaField}Format(row, column) {
399   - return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField});
400   - },
401   -#end
402   -#end
403   - // 取消按钮
404   - cancel() {
405   - this.open = false;
406   - this.reset();
407   - },
408   - // 表单重置
409   - reset() {
410   - this.form = {
411   -#foreach ($column in $columns)
412   -#if($column.htmlType == "radio")
413   - $column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end
414   -
415   -#elseif($column.htmlType == "checkbox")
416   - $column.javaField: []#if($velocityCount != $columns.size()),#end
417   -
418   -#else
419   - $column.javaField: null#if($velocityCount != $columns.size()),#end
420   -
421   -#end
422   -#end
423   - };
424   - this.resetForm("form");
425   - },
426   - /** 搜索按钮操作 */
427   - handleQuery() {
428   - this.getList();
429   - },
430   - /** 重置按钮操作 */
431   - resetQuery() {
432   -#foreach ($column in $columns)
433   -#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
434   -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
435   - this.daterange${AttrName} = [];
436   -#end
437   -#end
438   - this.resetForm("queryForm");
439   - this.handleQuery();
440   - },
441   - /** 新增按钮操作 */
442   - handleAdd() {
443   - this.reset();
444   - this.getTreeselect();
445   - this.open = true;
446   - this.title = "添加${functionName}";
447   - },
448   - /** 修改按钮操作 */
449   - handleUpdate(row) {
450   - this.reset();
451   - this.getTreeselect();
452   - if (row != null) {
453   - this.form.${treeParentCode} = row.${treeCode};
454   - }
455   - get${BusinessName}(row.${pkColumn.javaField}).then(response => {
456   - this.form = response.data;
457   -#foreach ($column in $columns)
458   -#if($column.htmlType == "checkbox")
459   - this.form.$column.javaField = this.form.${column.javaField}.split(",");
460   -#end
461   -#end
462   - this.open = true;
463   - this.title = "修改${functionName}";
464   - });
465   - },
466   - /** 提交按钮 */
467   - submitForm() {
468   - this.#[[$]]#refs["form"].validate(valid => {
469   - if (valid) {
470   -#foreach ($column in $columns)
471   -#if($column.htmlType == "checkbox")
472   - this.form.$column.javaField = this.form.${column.javaField}.join(",");
473   -#end
474   -#end
475   - if (this.form.${pkColumn.javaField} != null) {
476   - update${BusinessName}(this.form).then(response => {
477   - this.msgSuccess("修改成功");
478   - this.open = false;
479   - this.getList();
480   - });
481   - } else {
482   - add${BusinessName}(this.form).then(response => {
483   - this.msgSuccess("新增成功");
484   - this.open = false;
485   - this.getList();
486   - });
487   - }
488   - }
489   - });
490   - },
491   - /** 删除按钮操作 */
492   - handleDelete(row) {
493   - this.$confirm('是否确认删除${functionName}编号为"' + row.${pkColumn.javaField} + '"的数据项?', "警告", {
494   - confirmButtonText: "确定",
495   - cancelButtonText: "取消",
496   - type: "warning"
497   - }).then(function() {
498   - return del${BusinessName}(row.${pkColumn.javaField});
499   - }).then(() => {
500   - this.getList();
501   - this.msgSuccess("删除成功");
502   - })
503   - }
504   - }
505   -};
506   -</script>
  1 +<template>
  2 + <div class="app-container">
  3 +## ========== 搜索区 ==========
  4 + <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  5 +#foreach($column in $columns)
  6 +#if ($column.listOperation)
  7 + #set ($dictType=$column.dictType)
  8 + #set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  9 + #set ($comment=$column.columnComment)
  10 + #set ($parentheseIndex=$column.columnComment.indexOf("("))
  11 + #if ($parentheseIndex >= 0) #set($comment=$column.columnComment.substring(0, $parentheseIndex)) #end
  12 +#if ($column.htmlType == "input")
  13 + <el-form-item label="${comment}" prop="${column.javaField}">
  14 + <el-input v-model="queryParams.${column.javaField}" placeholder="请输入${comment}" clearable size="small" @keyup.enter.native="handleQuery"/>
  15 + </el-form-item>
  16 +#elseif ($column.htmlType == "select" || $column.htmlType == "radio")
  17 + <el-form-item label="${comment}" prop="${column.javaField}">
  18 + <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small">
  19 + #if ("" != $dictType) ## 设置了 dictType 数据字典的情况
  20 + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
  21 + :key="parseInt(dict.dictValue)" :label="dict.dictLabel" :value="parseInt(dict.dictValue)"/>
  22 + #else ## 未设置 dictType 数据字典的情况
  23 + <el-option label="请选择字典生成" value="" />
  24 + #end
  25 + </el-select>
  26 + </el-form-item>
  27 +#elseif($column.htmlType == "datetime")
  28 + #if ($column.queryType != "BETWEEN") ## 非范围
  29 + <el-form-item label="${comment}" prop="${column.javaField}">
  30 + <el-date-picker clearable size="small" v-model="queryParams.${column.javaField}" type="date" value-format="yyyy-MM-dd" placeholder="选择${comment}" />
  31 + </el-form-item>
  32 + #else ## 范围
  33 + <el-form-item label="${comment}">
  34 + <el-date-picker v-model="dateRange${AttrName}" size="small" style="width: 240px" value-format="yyyy-MM-dd"
  35 + type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" />
  36 + </el-form-item>
  37 + #end
  38 +#end
  39 +#end
  40 +#end
  41 + <el-form-item>
  42 + <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  43 + <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  44 + </el-form-item>
  45 + </el-form>
  46 +
  47 +## ========== 操作区 ==========
  48 + <el-row :gutter="10" class="mb8">
  49 + <el-col :span="1.5">
  50 + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  51 + v-hasPermi="['${moduleName}:${businessName}:add']">新增</el-button>
  52 + </el-col>
  53 + <el-col :span="1.5">
  54 + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
  55 + v-hasPermi="['${moduleName}:${businessName}:export']">导出</el-button>
  56 + </el-col>
  57 + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  58 + </el-row>
  59 +
  60 +## ========== 列表区 ==========
  61 + <el-table v-loading="loading" :data="${businessName}List" @selection-change="handleSelectionChange">
  62 + <el-table-column type="selection" width="55" align="center" />
  63 +#foreach($column in $columns)
  64 + #set ($dictType=$column.dictType)
  65 + #set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  66 + #set ($comment=$column.columnComment)
  67 + #set ($parentheseIndex=$column.columnComment.indexOf("("))
  68 + #if ($parentheseIndex >= 0) #set($comment=$column.columnComment.substring(0, $parentheseIndex)) #end
  69 +#if ($column.pk) ## 主键
  70 + <el-table-column label="${comment}" align="center" prop="${javaField}" />
  71 +#elseif($column.list && $column.htmlType == "datetime")
  72 + <el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
  73 + <template slot-scope="scope">
  74 + <span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span>
  75 + </template>
  76 + </el-table-column>
  77 +#elseif($column.list && "" != $column.dictType)
  78 + <el-table-column label="${comment}" align="center" prop="${javaField}" :formatter="${javaField}Format" />
  79 +#elseif($column.list && "" != $javaField)
  80 + <el-table-column label="${comment}" align="center" prop="${javaField}" />
  81 +#end
  82 +#end
  83 + <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  84 + <template slot-scope="scope">
  85 + <el-button
  86 + size="mini"
  87 + type="text"
  88 + icon="el-icon-edit"
  89 + @click="handleUpdate(scope.row)"
  90 + v-hasPermi="['${moduleName}:${businessName}:edit']"
  91 + >修改</el-button>
  92 + <el-button
  93 + size="mini"
  94 + type="text"
  95 + icon="el-icon-delete"
  96 + @click="handleDelete(scope.row)"
  97 + v-hasPermi="['${moduleName}:${businessName}:remove']"
  98 + >删除</el-button>
  99 + </template>
  100 + </el-table-column>
  101 + </el-table>
  102 +
  103 + <pagination
  104 + v-show="total>0"
  105 + :total="total"
  106 + :page.sync="queryParams.pageNum"
  107 + :limit.sync="queryParams.pageSize"
  108 + @pagination="getList"
  109 + />
  110 +
  111 + <!-- 添加或修改${functionName}对话框 -->
  112 + <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  113 + <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  114 +#foreach($column in $columns)
  115 +#set($field=$column.javaField)
  116 +#if($column.insert && !$column.pk)
  117 +#if(($column.usableColumn) || (!$column.superColumn))
  118 +#set($parentheseIndex=$column.columnComment.indexOf("("))
  119 +#if($parentheseIndex != -1)
  120 +#set($comment=$column.columnComment.substring(0, $parentheseIndex))
  121 +#else
  122 +#set($comment=$column.columnComment)
  123 +#end
  124 +#set($dictType=$column.dictType)
  125 +#if($column.htmlType == "input")
  126 + <el-form-item label="${comment}" prop="${field}">
  127 + <el-input v-model="form.${field}" placeholder="请输入${comment}" />
  128 + </el-form-item>
  129 +#elseif($column.htmlType == "imageUpload")
  130 + <el-form-item label="${comment}">
  131 + <imageUpload v-model="form.${field}"/>
  132 + </el-form-item>
  133 +#elseif($column.htmlType == "fileUpload")
  134 + <el-form-item label="${comment}">
  135 + <fileUpload v-model="form.${field}"/>
  136 + </el-form-item>
  137 +#elseif($column.htmlType == "editor")
  138 + <el-form-item label="${comment}">
  139 + <editor v-model="form.${field}" :min-height="192"/>
  140 + </el-form-item>
  141 +#elseif($column.htmlType == "select" && "" != $dictType)
  142 + <el-form-item label="${comment}" prop="${field}">
  143 + <el-select v-model="form.${field}" placeholder="请选择${comment}">
  144 + <el-option
  145 + v-for="dict in ${field}Options"
  146 + :key="dict.dictValue"
  147 + :label="dict.dictLabel"
  148 + #if($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.dictValue)"#else:value="dict.dictValue"#end
  149 +
  150 + ></el-option>
  151 + </el-select>
  152 + </el-form-item>
  153 +#elseif($column.htmlType == "select" && $dictType)
  154 + <el-form-item label="${comment}" prop="${field}">
  155 + <el-select v-model="form.${field}" placeholder="请选择${comment}">
  156 + <el-option label="请选择字典生成" value="" />
  157 + </el-select>
  158 + </el-form-item>
  159 +#elseif($column.htmlType == "checkbox" && "" != $dictType)
  160 + <el-form-item label="${comment}">
  161 + <el-checkbox-group v-model="form.${field}">
  162 + <el-checkbox
  163 + v-for="dict in ${field}Options"
  164 + :key="dict.dictValue"
  165 + :label="dict.dictValue">
  166 + {{dict.dictLabel}}
  167 + </el-checkbox>
  168 + </el-checkbox-group>
  169 + </el-form-item>
  170 +#elseif($column.htmlType == "checkbox" && $dictType)
  171 + <el-form-item label="${comment}">
  172 + <el-checkbox-group v-model="form.${field}">
  173 + <el-checkbox>请选择字典生成</el-checkbox>
  174 + </el-checkbox-group>
  175 + </el-form-item>
  176 +#elseif($column.htmlType == "radio" && "" != $dictType)
  177 + <el-form-item label="${comment}">
  178 + <el-radio-group v-model="form.${field}">
  179 + <el-radio
  180 + v-for="dict in ${field}Options"
  181 + :key="dict.dictValue"
  182 + #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.dictValue)"#else:label="dict.dictValue"#end
  183 +
  184 + >{{dict.dictLabel}}</el-radio>
  185 + </el-radio-group>
  186 + </el-form-item>
  187 +#elseif($column.htmlType == "radio" && $dictType)
  188 + <el-form-item label="${comment}">
  189 + <el-radio-group v-model="form.${field}">
  190 + <el-radio label="1">请选择字典生成</el-radio>
  191 + </el-radio-group>
  192 + </el-form-item>
  193 +#elseif($column.htmlType == "datetime")
  194 + <el-form-item label="${comment}" prop="${field}">
  195 + <el-date-picker clearable size="small"
  196 + v-model="form.${field}"
  197 + type="date"
  198 + value-format="yyyy-MM-dd"
  199 + placeholder="选择${comment}">
  200 + </el-date-picker>
  201 + </el-form-item>
  202 +#elseif($column.htmlType == "textarea")
  203 + <el-form-item label="${comment}" prop="${field}">
  204 + <el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" />
  205 + </el-form-item>
  206 +#end
  207 +#end
  208 +#end
  209 +#end
  210 + </el-form>
  211 + <div slot="footer" class="dialog-footer">
  212 + <el-button type="primary" @click="submitForm">确 定</el-button>
  213 + <el-button @click="cancel">取 消</el-button>
  214 + </div>
  215 + </el-dialog>
  216 + </div>
  217 +</template>
  218 +
  219 +<script>
  220 +import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName}, export${BusinessName} } from "@/api/${moduleName}/${businessName}";
  221 +#foreach($column in $columns)
  222 +#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "imageUpload")
  223 +import ImageUpload from '@/components/ImageUpload';
  224 +#break
  225 +#end
  226 +#end
  227 +#foreach($column in $columns)
  228 +#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "fileUpload")
  229 +import FileUpload from '@/components/FileUpload';
  230 +#break
  231 +#end
  232 +#end
  233 +#foreach($column in $columns)
  234 +#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor")
  235 +import Editor from '@/components/Editor';
  236 +#break
  237 +#end
  238 +#end
  239 +
  240 +export default {
  241 + name: "${BusinessName}",
  242 + components: {
  243 +#foreach($column in $columns)
  244 +#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "imageUpload")
  245 + ImageUpload,
  246 +#break
  247 +#end
  248 +#end
  249 +#foreach($column in $columns)
  250 +#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "fileUpload")
  251 + FileUpload,
  252 +#break
  253 +#end
  254 +#end
  255 +#foreach($column in $columns)
  256 +#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor")
  257 + Editor,
  258 +#break
  259 +#end
  260 +#end
  261 + },
  262 + data() {
  263 + return {
  264 + // 遮罩层
  265 + loading: true,
  266 + // 选中数组
  267 + ids: [],
  268 +#if($table.sub)
  269 + // 子表选中数据
  270 + checked${subClassName}: [],
  271 +#end
  272 + // 非单个禁用
  273 + single: true,
  274 + // 非多个禁用
  275 + multiple: true,
  276 + // 显示搜索条件
  277 + showSearch: true,
  278 + // 总条数
  279 + total: 0,
  280 + // ${functionName}表格数据
  281 + ${businessName}List: [],
  282 +#if($table.sub)
  283 + // ${subTable.functionName}表格数据
  284 + ${subclassName}List: [],
  285 +#end
  286 + // 弹出层标题
  287 + title: "",
  288 + // 是否显示弹出层
  289 + open: false,
  290 +#foreach ($column in $columns)
  291 +#set($parentheseIndex=$column.columnComment.indexOf("("))
  292 +#if($parentheseIndex != -1)
  293 +#set($comment=$column.columnComment.substring(0, $parentheseIndex))
  294 +#else
  295 +#set($comment=$column.columnComment)
  296 +#end
  297 +#if(${column.dictType} != '')
  298 + // $comment字典
  299 + ${column.javaField}Options: [],
  300 +#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  301 +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  302 + // $comment时间范围
  303 + dateRange${AttrName}: [],
  304 +#end
  305 +#end
  306 + // 查询参数
  307 + queryParams: {
  308 + pageNum: 1,
  309 + pageSize: 10,
  310 +#foreach ($column in $columns)
  311 +#if($column.query)
  312 + $column.javaField: null#if($velocityCount != $columns.size()),#end
  313 +
  314 +#end
  315 +#end
  316 + },
  317 + // 表单参数
  318 + form: {},
  319 + // 表单校验
  320 + rules: {
  321 +#foreach ($column in $columns)
  322 +#if($column.required)
  323 +#set($parentheseIndex=$column.columnComment.indexOf("("))
  324 +#if($parentheseIndex != -1)
  325 +#set($comment=$column.columnComment.substring(0, $parentheseIndex))
  326 +#else
  327 +#set($comment=$column.columnComment)
  328 +#end
  329 + $column.javaField: [
  330 + { required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }
  331 + ]#if($velocityCount != $columns.size()),#end
  332 +
  333 +#end
  334 +#end
  335 + }
  336 + };
  337 + },
  338 + created() {
  339 + this.getList();
  340 +#foreach ($column in $columns)
  341 +#if(${column.dictType} != '')
  342 + this.getDicts("${column.dictType}").then(response => {
  343 + this.${column.javaField}Options = response.data;
  344 + });
  345 +#end
  346 +#end
  347 + },
  348 + methods: {
  349 + /** 查询${functionName}列表 */
  350 + getList() {
  351 + this.loading = true;
  352 +#foreach ($column in $columns)
  353 +#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  354 + this.queryParams.params = {};
  355 +#break
  356 +#end
  357 +#end
  358 +#foreach ($column in $columns)
  359 +#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  360 +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  361 + if (null != this.dateRange${AttrName} && '' != this.dateRange${AttrName}) {
  362 + this.queryParams.params["begin${AttrName}"] = this.dateRange${AttrName}[0];
  363 + this.queryParams.params["end${AttrName}"] = this.dateRange${AttrName}[1];
  364 + }
  365 +#end
  366 +#end
  367 + list${BusinessName}(this.queryParams).then(response => {
  368 + this.${businessName}List = response.rows;
  369 + this.total = response.total;
  370 + this.loading = false;
  371 + });
  372 + },
  373 + // 取消按钮
  374 + cancel() {
  375 + this.open = false;
  376 + this.reset();
  377 + },
  378 + // 表单重置
  379 + reset() {
  380 + this.form = {
  381 +#foreach ($column in $columns)
  382 +#if($column.htmlType == "radio")
  383 + $column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end
  384 +
  385 +#elseif($column.htmlType == "checkbox")
  386 + $column.javaField: []#if($velocityCount != $columns.size()),#end
  387 +
  388 +#else
  389 + $column.javaField: null#if($velocityCount != $columns.size()),#end
  390 +
  391 +#end
  392 +#end
  393 + };
  394 +#if($table.sub)
  395 + this.${subclassName}List = [];
  396 +#end
  397 + this.resetForm("form");
  398 + },
  399 + /** 搜索按钮操作 */
  400 + handleQuery() {
  401 + this.queryParams.pageNum = 1;
  402 + this.getList();
  403 + },
  404 + /** 重置按钮操作 */
  405 + resetQuery() {
  406 +#foreach ($column in $columns)
  407 +#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  408 +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  409 + this.dateRange${AttrName} = [];
  410 +#end
  411 +#end
  412 + this.resetForm("queryForm");
  413 + this.handleQuery();
  414 + },
  415 + // 多选框选中数据
  416 + handleSelectionChange(selection) {
  417 + this.ids = selection.map(item => item.${pkColumn.javaField})
  418 + this.single = selection.length!==1
  419 + this.multiple = !selection.length
  420 + },
  421 + /** 新增按钮操作 */
  422 + handleAdd() {
  423 + this.reset();
  424 + this.open = true;
  425 + this.title = "添加${functionName}";
  426 + },
  427 + /** 修改按钮操作 */
  428 + handleUpdate(row) {
  429 + this.reset();
  430 + const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids
  431 + get${BusinessName}(${pkColumn.javaField}).then(response => {
  432 + this.form = response.data;
  433 +#foreach ($column in $columns)
  434 +#if($column.htmlType == "checkbox")
  435 + this.form.$column.javaField = this.form.${column.javaField}.split(",");
  436 +#end
  437 +#end
  438 +#if($table.sub)
  439 + this.${subclassName}List = response.data.${subclassName}List;
  440 +#end
  441 + this.open = true;
  442 + this.title = "修改${functionName}";
  443 + });
  444 + },
  445 + /** 提交按钮 */
  446 + submitForm() {
  447 + this.#[[$]]#refs["form"].validate(valid => {
  448 + if (valid) {
  449 +#foreach ($column in $columns)
  450 +#if($column.htmlType == "checkbox")
  451 + this.form.$column.javaField = this.form.${column.javaField}.join(",");
  452 +#end
  453 +#end
  454 +#if($table.sub)
  455 + this.form.${subclassName}List = this.${subclassName}List;
  456 +#end
  457 + if (this.form.${pkColumn.javaField} != null) {
  458 + update${BusinessName}(this.form).then(response => {
  459 + this.msgSuccess("修改成功");
  460 + this.open = false;
  461 + this.getList();
  462 + });
  463 + } else {
  464 + add${BusinessName}(this.form).then(response => {
  465 + this.msgSuccess("新增成功");
  466 + this.open = false;
  467 + this.getList();
  468 + });
  469 + }
  470 + }
  471 + });
  472 + },
  473 + /** 删除按钮操作 */
  474 + handleDelete(row) {
  475 + const ${pkColumn.javaField}s = row.${pkColumn.javaField} || this.ids;
  476 + this.$confirm('是否确认删除${functionName}编号为"' + ${pkColumn.javaField}s + '"的数据项?', "警告", {
  477 + confirmButtonText: "确定",
  478 + cancelButtonText: "取消",
  479 + type: "warning"
  480 + }).then(function() {
  481 + return del${BusinessName}(${pkColumn.javaField}s);
  482 + }).then(() => {
  483 + this.getList();
  484 + this.msgSuccess("删除成功");
  485 + })
  486 + },
  487 +#if($table.sub)
  488 + /** ${subTable.functionName}序号 */
  489 + row${subClassName}Index({ row, rowIndex }) {
  490 + row.index = rowIndex + 1;
  491 + },
  492 + /** ${subTable.functionName}添加按钮操作 */
  493 + handleAdd${subClassName}() {
  494 + let obj = {};
  495 +#foreach($column in $subTable.columns)
  496 +#if($column.pk || $column.javaField == ${subTableFkclassName})
  497 +#elseif($column.list && "" != $javaField)
  498 + obj.$column.javaField = "";
  499 +#end
  500 +#end
  501 + this.${subclassName}List.push(obj);
  502 + },
  503 + /** ${subTable.functionName}删除按钮操作 */
  504 + handleDelete${subClassName}() {
  505 + if (this.checked${subClassName}.length == 0) {
  506 + this.$alert("请先选择要删除的${subTable.functionName}数据", "提示", { confirmButtonText: "确定", });
  507 + } else {
  508 + this.${subclassName}List.splice(this.checked${subClassName}[0].index - 1, 1);
  509 + }
  510 + },
  511 + /** 单选框选中数据 */
  512 + handle${subClassName}SelectionChange(selection) {
  513 + if (selection.length > 1) {
  514 + this.$refs.${subclassName}.clearSelection();
  515 + this.$refs.${subclassName}.toggleRowSelection(selection.pop());
  516 + } else {
  517 + this.checked${subClassName} = selection;
  518 + }
  519 + },
  520 +#end
  521 + /** 导出按钮操作 */
  522 + handleExport() {
  523 + const queryParams = this.queryParams;
  524 + this.$confirm('是否确认导出所有${functionName}数据项?', "警告", {
  525 + confirmButtonText: "确定",
  526 + cancelButtonText: "取消",
  527 + type: "warning"
  528 + }).then(function() {
  529 + return export${BusinessName}(queryParams);
  530 + }).then(response => {
  531 + this.download(response.msg);
  532 + })
  533 + }
  534 + }
  535 +};
  536 +</script>
... ...
src/test/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenEngineTest.java
... ... @@ -10,6 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest;
10 10  
11 11 import javax.annotation.Resource;
12 12 import java.util.List;
  13 +import java.util.Map;
13 14  
14 15 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
15 16 public class ToolCodegenEngineTest {
... ... @@ -24,9 +25,10 @@ public class ToolCodegenEngineTest {
24 25  
25 26 @Test
26 27 public void testExecute() {
27   - ToolCodegenTableDO table = codegenTableMapper.selectById(14);
  28 + ToolCodegenTableDO table = codegenTableMapper.selectById(10);
28 29 List<ToolCodegenColumnDO> columns = codegenColumnMapper.selectListByTableId(table.getId());
29   - codegenEngine.execute(table, columns);
  30 + Map<String, String> result = codegenEngine.execute(table, columns);
  31 + System.out.println(result.get("vue/views/system/test/index.vue"));
30 32 }
31 33  
32 34 }
... ...