xm
2024-06-14 722af26bc6fec32bb289b1df51a9016a4935610f
提交 | 用户 | 时间
722af2 1 <template>
X 2   <div class="app-container">
3     <el-form :model="queryParams" ref="queryForm" size="small" :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" || $column.htmlType == "textarea")
15       <el-form-item label="${comment}" prop="${column.javaField}">
16         <el-input
17           v-model="queryParams.${column.javaField}"
18           placeholder="请输入${comment}"
19           clearable
20           @keyup.enter.native="handleQuery"
21         />
22       </el-form-item>
23 #elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
24       <el-form-item label="${comment}" prop="${column.javaField}">
25         <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable>
26           <el-option
27             v-for="dict in dict.type.${dictType}"
28             :key="dict.value"
29             :label="dict.label"
30             :value="dict.value"
31           />
32         </el-select>
33       </el-form-item>
34 #elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType)
35       <el-form-item label="${comment}" prop="${column.javaField}">
36         <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable>
37           <el-option label="请选择字典生成" value="" />
38         </el-select>
39       </el-form-item>
40 #elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN")
41       <el-form-item label="${comment}" prop="${column.javaField}">
42         <el-date-picker clearable
43           v-model="queryParams.${column.javaField}"
44           type="date"
45           value-format="yyyy-MM-dd"
46           placeholder="选择${comment}">
47         </el-date-picker>
48       </el-form-item>
49 #elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
50       <el-form-item label="${comment}">
51         <el-date-picker
52           v-model="daterange${AttrName}"
53           style="width: 240px"
54           value-format="yyyy-MM-dd HH:mm:ss"
55           type="daterange"
56           range-separator="-"
57           start-placeholder="开始日期"
58           end-placeholder="结束日期"
59           :default-time="['00:00:00', '23:59:59']"
60         ></el-date-picker>
61       </el-form-item>
62 #end
63 #end
64 #end
65       <el-form-item>
66         <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
67         <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
68       </el-form-item>
69     </el-form>
70
71     <el-row :gutter="10" class="mb8">
72       <el-col :span="1.5">
73         <el-button
74           type="primary"
75           plain
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="info"
85           plain
86           icon="el-icon-sort"
87           size="mini"
88           @click="toggleExpandAll"
89         >展开/折叠</el-button>
90       </el-col>
91       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
92     </el-row>
93
94     <el-table
95       v-if="refreshTable"
96       v-loading="loading"
97       :data="${businessName}List"
98       row-key="${treeCode}"
99       :default-expand-all="isExpandAll"
100       :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
101     >
102 #foreach($column in $columns)
103 #set($javaField=$column.javaField)
104 #set($parentheseIndex=$column.columnComment.indexOf("("))
105 #if($parentheseIndex != -1)
106 #set($comment=$column.columnComment.substring(0, $parentheseIndex))
107 #else
108 #set($comment=$column.columnComment)
109 #end
110 #if($column.pk)
111 #elseif($column.list && $column.htmlType == "datetime")
112       <el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
113         <template slot-scope="scope">
114           <span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span>
115         </template>
116       </el-table-column>
117 #elseif($column.list && $column.htmlType == "imageUpload")
118       <el-table-column label="${comment}" align="center" prop="${javaField}" width="100">
119           <template #default="scope">
120               <image-preview :src="scope.row.${javaField}" :width="50" :height="50"/>
121           </template>
122       </el-table-column>
123 #elseif($column.list && $column.dictType && "" != $column.dictType)
124       <el-table-column label="${comment}" align="center" prop="${javaField}">
125         <template slot-scope="scope">
126 #if($column.htmlType == "checkbox")
127           <dict-tag :options="dict.type.${column.dictType}" :value="scope.row.${javaField} ? scope.row.${javaField}.split(',') : []"/>
128 #else
129           <dict-tag :options="dict.type.${column.dictType}" :value="scope.row.${javaField}"/>
130 #end
131         </template>
132       </el-table-column>
133 #elseif($column.list && "" != $javaField)
134 #if(${foreach.index} == 1)
135       <el-table-column label="${comment}" prop="${javaField}" />
136 #else
137       <el-table-column label="${comment}" align="center" prop="${javaField}" />
138 #end
139 #end
140 #end
141       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
142         <template slot-scope="scope">
143           <el-button
144             size="mini"
145             type="text"
146             icon="el-icon-edit"
147             @click="handleUpdate(scope.row)"
148             v-hasPermi="['${moduleName}:${businessName}:edit']"
149           >修改</el-button>
150           <el-button
151             size="mini"
152             type="text"
153             icon="el-icon-plus"
154             @click="handleAdd(scope.row)"
155             v-hasPermi="['${moduleName}:${businessName}:add']"
156           >新增</el-button>
157           <el-button
158             size="mini"
159             type="text"
160             icon="el-icon-delete"
161             @click="handleDelete(scope.row)"
162             v-hasPermi="['${moduleName}:${businessName}:remove']"
163           >删除</el-button>
164         </template>
165       </el-table-column>
166     </el-table>
167
168     <!-- 添加或修改${functionName}对话框 -->
169     <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
170       <el-form ref="form" :model="form" :rules="rules" label-width="80px">
171 #foreach($column in $columns)
172 #set($field=$column.javaField)
173 #if($column.insert && !$column.pk)
174 #set($parentheseIndex=$column.columnComment.indexOf("("))
175 #if($parentheseIndex != -1)
176 #set($comment=$column.columnComment.substring(0, $parentheseIndex))
177 #else
178 #set($comment=$column.columnComment)
179 #end
180 #set($dictType=$column.dictType)
181 #if("" != $treeParentCode && $column.javaField == $treeParentCode)
182         <el-form-item label="${comment}" prop="${treeParentCode}">
183           <treeselect v-model="form.${treeParentCode}" :options="${businessName}Options" :normalizer="normalizer" placeholder="请选择${comment}" />
184         </el-form-item>
185 #elseif($column.htmlType == "input")
186         <el-form-item label="${comment}" prop="${field}">
187           <el-input v-model="form.${field}" placeholder="请输入${comment}" />
188         </el-form-item>
189 #elseif($column.htmlType == "imageUpload")
190         <el-form-item label="${comment}" prop="${field}">
191           <image-upload v-model="form.${field}"/>
192         </el-form-item>
193 #elseif($column.htmlType == "fileUpload")
194         <el-form-item label="${comment}" prop="${field}">
195           <file-upload v-model="form.${field}"/>
196         </el-form-item>
197 #elseif($column.htmlType == "editor")
198         <el-form-item label="${comment}">
199           <editor v-model="form.${field}" :min-height="192"/>
200         </el-form-item>
201 #elseif($column.htmlType == "select" && "" != $dictType)
202         <el-form-item label="${comment}" prop="${field}">
203           <el-select v-model="form.${field}" placeholder="请选择${comment}">
204             <el-option
205               v-for="dict in dict.type.${dictType}"
206               :key="dict.value"
207               :label="dict.label"
208 #if($column.javaType == "Integer" || $column.javaType == "Long")
209               :value="parseInt(dict.value)"
210 #else
211               :value="dict.value"
212 #end
213             ></el-option>
214           </el-select>
215         </el-form-item>
216 #elseif($column.htmlType == "select" && $dictType)
217         <el-form-item label="${comment}" prop="${field}">
218           <el-select v-model="form.${field}" placeholder="请选择${comment}">
219             <el-option label="请选择字典生成" value="" />
220           </el-select>
221         </el-form-item>
222 #elseif($column.htmlType == "checkbox" && "" != $dictType)
223         <el-form-item label="${comment}" prop="${field}">
224           <el-checkbox-group v-model="form.${field}">
225             <el-checkbox
226               v-for="dict in dict.type.${dictType}"
227               :key="dict.value"
228               :label="dict.value">
229               {{dict.label}}
230             </el-checkbox>
231           </el-checkbox-group>
232         </el-form-item>
233 #elseif($column.htmlType == "checkbox" && $dictType)
234         <el-form-item label="${comment}" prop="${field}">
235           <el-checkbox-group v-model="form.${field}">
236             <el-checkbox>请选择字典生成</el-checkbox>
237           </el-checkbox-group>
238         </el-form-item>
239 #elseif($column.htmlType == "radio" && "" != $dictType)
240         <el-form-item label="${comment}" prop="${field}">
241           <el-radio-group v-model="form.${field}">
242             <el-radio
243               v-for="dict in dict.type.${dictType}"
244               :key="dict.value"
245 #if($column.javaType == "Integer" || $column.javaType == "Long")
246               :label="parseInt(dict.value)"
247 #else
248               :label="dict.value"
249 #end
250             >{{dict.label}}</el-radio>
251           </el-radio-group>
252         </el-form-item>
253 #elseif($column.htmlType == "radio" && $dictType)
254         <el-form-item label="${comment}" prop="${field}">
255           <el-radio-group v-model="form.${field}">
256             <el-radio label="1">请选择字典生成</el-radio>
257           </el-radio-group>
258         </el-form-item>
259 #elseif($column.htmlType == "datetime")
260         <el-form-item label="${comment}" prop="${field}">
261           <el-date-picker clearable
262             v-model="form.${field}"
263             type="datetime"
264             value-format="yyyy-MM-dd HH:mm:ss"
265             placeholder="选择${comment}">
266           </el-date-picker>
267         </el-form-item>
268 #elseif($column.htmlType == "textarea")
269         <el-form-item label="${comment}" prop="${field}">
270           <el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" />
271         </el-form-item>
272 #end
273 #end
274 #end
275       </el-form>
276       <div slot="footer" class="dialog-footer">
277         <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
278         <el-button @click="cancel">取 消</el-button>
279       </div>
280     </el-dialog>
281   </div>
282 </template>
283
284 <script>
285 import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName} } from "@/api/${moduleName}/${businessName}";
286 import Treeselect from "@riophae/vue-treeselect";
287 import "@riophae/vue-treeselect/dist/vue-treeselect.css";
288
289 export default {
290   name: "${BusinessName}",
291 #if(${dicts} != '')
292   dicts: [${dicts}],
293 #end
294   components: {
295     Treeselect
296   },
297   data() {
298     return {
299       // 按钮loading
300       buttonLoading: false,
301       // 遮罩层
302       loading: true,
303       // 显示搜索条件
304       showSearch: true,
305       // ${functionName}表格数据
306       ${businessName}List: [],
307       // ${functionName}树选项
308       ${businessName}Options: [],
309       // 弹出层标题
310       title: "",
311       // 是否显示弹出层
312       open: false,
313       // 是否展开,默认全部展开
314       isExpandAll: true,
315       // 重新渲染表格状态
316       refreshTable: true,
317 #foreach ($column in $columns)
318 #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
319 #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
320       // $comment时间范围
321       daterange${AttrName}: [],
322 #end
323 #end
324       // 查询参数
325       queryParams: {
326 #foreach ($column in $columns)
327 #if($column.query)
328         $column.javaField: undefined#if($foreach.count != $columns.size()),#end
329 #end
330 #end
331       },
332       // 表单参数
333       form: {},
334       // 表单校验
335       rules: {
336 #foreach ($column in $columns)
337 #if($column.required)
338 #set($parentheseIndex=$column.columnComment.indexOf("("))
339 #if($parentheseIndex != -1)
340 #set($comment=$column.columnComment.substring(0, $parentheseIndex))
341 #else
342 #set($comment=$column.columnComment)
343 #end
344         $column.javaField: [
345           { required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
346         ]#if($foreach.count != $columns.size()),#end
347 #end
348 #end
349       }
350     };
351   },
352   created() {
353     this.getList();
354   },
355   methods: {
356     /** 查询${functionName}列表 */
357     getList() {
358       this.loading = true;
359 #foreach ($column in $columns)
360 #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
361       this.queryParams.params = {};
362 #break
363 #end
364 #end
365 #foreach ($column in $columns)
366 #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
367 #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
368       if (null != this.daterange${AttrName} && '' != this.daterange${AttrName}) {
369         this.queryParams.params["begin${AttrName}"] = this.daterange${AttrName}[0];
370         this.queryParams.params["end${AttrName}"] = this.daterange${AttrName}[1];
371       }
372 #end
373 #end
374       list${BusinessName}(this.queryParams).then(response => {
375         this.${businessName}List = this.handleTree(response.data, "${treeCode}", "${treeParentCode}");
376         this.loading = false;
377       });
378     },
379     /** 转换${functionName}数据结构 */
380     normalizer(node) {
381       if (node.children && !node.children.length) {
382         delete node.children;
383       }
384       return {
385         id: node.${treeCode},
386         label: node.${treeName},
387         children: node.children
388       };
389     },
390     /** 查询${functionName}下拉树结构 */
391     getTreeselect() {
392       list${BusinessName}().then(response => {
393         this.${businessName}Options = [];
394         const data = { ${treeCode}: 0, ${treeName}: '顶级节点', children: [] };
395         data.children = this.handleTree(response.data, "${treeCode}", "${treeParentCode}");
396         this.${businessName}Options.push(data);
397       });
398     },
399     // 取消按钮
400     cancel() {
401       this.open = false;
402       this.reset();
403     },
404     // 表单重置
405     reset() {
406       this.form = {
407 #foreach ($column in $columns)
408 #if($column.htmlType == "checkbox")
409         $column.javaField: []#if($foreach.count != $columns.size()),#end
410 #else
411         $column.javaField: null#if($foreach.count != $columns.size()),#end
412 #end
413 #end
414       };
415       this.resetForm("form");
416     },
417     /** 搜索按钮操作 */
418     handleQuery() {
419       this.getList();
420     },
421     /** 重置按钮操作 */
422     resetQuery() {
423 #foreach ($column in $columns)
424 #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
425 #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
426       this.daterange${AttrName} = [];
427 #end
428 #end
429       this.resetForm("queryForm");
430       this.handleQuery();
431     },
432     /** 新增按钮操作 */
433     handleAdd(row) {
434       this.reset();
435       this.getTreeselect();
436       if (row != null && row.${treeCode}) {
437         this.form.${treeParentCode} = row.${treeCode};
438       } else {
439         this.form.${treeParentCode} = 0;
440       }
441       this.open = true;
442       this.title = "添加${functionName}";
443     },
444     /** 展开/折叠操作 */
445     toggleExpandAll() {
446       this.refreshTable = false;
447       this.isExpandAll = !this.isExpandAll;
448       this.$nextTick(() => {
449         this.refreshTable = true;
450       });
451     },
452     /** 修改按钮操作 */
453     handleUpdate(row) {
454       this.loading = true;
455       this.reset();
456       this.getTreeselect();
457       if (row != null) {
458         this.form.${treeParentCode} = row.${treeCode};
459       }
460       get${BusinessName}(row.${pkColumn.javaField}).then(response => {
461         this.loading = false;
462         this.form = response.data;
463 #foreach ($column in $columns)
464 #if($column.htmlType == "checkbox")
465         this.form.$column.javaField = this.form.${column.javaField}.split(",");
466 #end
467 #end
468         this.open = true;
469         this.title = "修改${functionName}";
470       });
471     },
472     /** 提交按钮 */
473     submitForm() {
474       this.#[[$]]#refs["form"].validate(valid => {
475         if (valid) {
476           this.buttonLoading = true;
477 #foreach ($column in $columns)
478 #if($column.htmlType == "checkbox")
479           this.form.$column.javaField = this.form.${column.javaField}.join(",");
480 #end
481 #end
482           if (this.form.${pkColumn.javaField} != null) {
483             update${BusinessName}(this.form).then(response => {
484               this.#[[$modal]]#.msgSuccess("修改成功");
485               this.open = false;
486               this.getList();
487             }).finally(() => {
488               this.buttonLoading = false;
489             });
490           } else {
491             add${BusinessName}(this.form).then(response => {
492               this.#[[$modal]]#.msgSuccess("新增成功");
493               this.open = false;
494               this.getList();
495             }).finally(() => {
496               this.buttonLoading = false;
497             });
498           }
499         }
500       });
501     },
502     /** 删除按钮操作 */
503     handleDelete(row) {
504       this.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + row.${pkColumn.javaField} + '"的数据项?').then(() => {
505         this.loading = true;
506         return del${BusinessName}(row.${pkColumn.javaField});
507       }).then(() => {
508         this.loading = false;
509         this.getList();
510         this.#[[$modal]]#.msgSuccess("删除成功");
511       }).catch(() => {
512       }).finally(() => {
513         this.loading = false;
514       });
515     }
516   }
517 };
518 </script>