xm
2024-06-14 722af26bc6fec32bb289b1df51a9016a4935610f
提交 | 用户 | 时间
722af2 1 <template>
X 2   <div class="app-container">
3     <el-form :model="queryParams" ref="queryRef" :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="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 ${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}" style="width: 308px">
51         <el-date-picker
52           v-model="daterange${AttrName}"
53           value-format="YYYY-MM-DD HH:mm:ss"
54           type="daterange"
55           range-separator="-"
56           start-placeholder="开始日期"
57           :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
58         ></el-date-picker>
59       </el-form-item>
60 #end
61 #end
62 #end
63       <el-form-item>
64         <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
65         <el-button icon="Refresh" @click="resetQuery">重置</el-button>
66       </el-form-item>
67     </el-form>
68
69     <el-row :gutter="10" class="mb8">
70       <el-col :span="1.5">
71         <el-button
72           type="primary"
73           plain
74           icon="Plus"
75           @click="handleAdd"
76           v-hasPermi="['${moduleName}:${businessName}:add']"
77         >新增</el-button>
78       </el-col>
79       <el-col :span="1.5">
80         <el-button
81           type="success"
82           plain
83           icon="Edit"
84           :disabled="single"
85           @click="handleUpdate"
86           v-hasPermi="['${moduleName}:${businessName}:edit']"
87         >修改</el-button>
88       </el-col>
89       <el-col :span="1.5">
90         <el-button
91           type="danger"
92           plain
93           icon="Delete"
94           :disabled="multiple"
95           @click="handleDelete"
96           v-hasPermi="['${moduleName}:${businessName}:remove']"
97         >删除</el-button>
98       </el-col>
99       <el-col :span="1.5">
100         <el-button
101           type="warning"
102           plain
103           icon="Download"
104           @click="handleExport"
105           v-hasPermi="['${moduleName}:${businessName}:export']"
106         >导出</el-button>
107       </el-col>
108       <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
109     </el-row>
110
111     <el-table v-loading="loading" :data="${businessName}List" @selection-change="handleSelectionChange">
112       <el-table-column type="selection" width="55" align="center" />
113 #foreach($column in $columns)
114 #set($javaField=$column.javaField)
115 #set($parentheseIndex=$column.columnComment.indexOf("("))
116 #if($parentheseIndex != -1)
117 #set($comment=$column.columnComment.substring(0, $parentheseIndex))
118 #else
119 #set($comment=$column.columnComment)
120 #end
121 #if($column.pk)
122       <el-table-column label="${comment}" align="center" prop="${javaField}" v-if="${column.list}"/>
123 #elseif($column.list && $column.htmlType == "datetime")
124       <el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
125         <template #default="scope">
126           <span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span>
127         </template>
128       </el-table-column>
129 #elseif($column.list && $column.htmlType == "imageUpload")
130       <el-table-column label="${comment}" align="center" prop="${javaField}" width="100">
131           <template #default="scope">
132               <image-preview :src="scope.row.${javaField}" :width="50" :height="50"/>
133           </template>
134       </el-table-column>
135 #elseif($column.list && $column.dictType && "" != $column.dictType)
136       <el-table-column label="${comment}" align="center" prop="${javaField}">
137         <template #default="scope">
138 #if($column.htmlType == "checkbox")
139           <dict-tag :options="${column.dictType}" :value="scope.row.${javaField} ? scope.row.${javaField}.split(',') : []"/>
140 #else
141           <dict-tag :options="${column.dictType}" :value="scope.row.${javaField}"/>
142 #end
143         </template>
144       </el-table-column>
145 #elseif($column.list && "" != $javaField)
146       <el-table-column label="${comment}" align="center" prop="${javaField}" />
147 #end
148 #end
149       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
150           <template #default="scope">
151               <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['${moduleName}:${businessName}:edit']">修改</el-button>
152               <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['${moduleName}:${businessName}:remove']">删除</el-button>
153           </template>
154       </el-table-column>
155     </el-table>
156
157     <pagination
158       v-show="total>0"
159       :total="total"
160       v-model:page="queryParams.pageNum"
161       v-model:limit="queryParams.pageSize"
162       @pagination="getList"
163     />
164
165     <!-- 添加或修改${functionName}对话框 -->
166     <el-dialog :title="title" v-model="open" width="500px" append-to-body>
167       <el-form ref="${businessName}Ref" :model="form" :rules="rules" label-width="80px">
168 #foreach($column in $columns)
169 #set($field=$column.javaField)
170 #if($column.insert && !$column.pk)
171 #set($parentheseIndex=$column.columnComment.indexOf("("))
172 #if($parentheseIndex != -1)
173 #set($comment=$column.columnComment.substring(0, $parentheseIndex))
174 #else
175 #set($comment=$column.columnComment)
176 #end
177 #set($dictType=$column.dictType)
178 #if($column.htmlType == "input")
179         <el-form-item label="${comment}" prop="${field}">
180           <el-input v-model="form.${field}" placeholder="请输入${comment}" />
181         </el-form-item>
182 #elseif($column.htmlType == "imageUpload")
183         <el-form-item label="${comment}" prop="${field}">
184           <image-upload v-model="form.${field}"/>
185         </el-form-item>
186 #elseif($column.htmlType == "fileUpload")
187         <el-form-item label="${comment}" prop="${field}">
188           <file-upload v-model="form.${field}"/>
189         </el-form-item>
190 #elseif($column.htmlType == "editor")
191         <el-form-item label="${comment}">
192           <editor v-model="form.${field}" :min-height="192"/>
193         </el-form-item>
194 #elseif($column.htmlType == "select" && "" != $dictType)
195         <el-form-item label="${comment}" prop="${field}">
196           <el-select v-model="form.${field}" placeholder="请选择${comment}">
197             <el-option
198               v-for="dict in ${dictType}"
199               :key="dict.value"
200               :label="dict.label"
201 #if($column.javaType == "Integer" || $column.javaType == "Long")
202               :value="parseInt(dict.value)"
203 #else
204               :value="dict.value"
205 #end
206             ></el-option>
207           </el-select>
208         </el-form-item>
209 #elseif($column.htmlType == "select" && $dictType)
210         <el-form-item label="${comment}" prop="${field}">
211           <el-select v-model="form.${field}" placeholder="请选择${comment}">
212             <el-option label="请选择字典生成" value="" />
213           </el-select>
214         </el-form-item>
215 #elseif($column.htmlType == "checkbox" && "" != $dictType)
216         <el-form-item label="${comment}" prop="${field}">
217           <el-checkbox-group v-model="form.${field}">
218             <el-checkbox
219               v-for="dict in ${dictType}"
220               :key="dict.value"
221               :label="dict.value">
222               {{dict.label}}
223             </el-checkbox>
224           </el-checkbox-group>
225         </el-form-item>
226 #elseif($column.htmlType == "checkbox" && $dictType)
227         <el-form-item label="${comment}" prop="${field}">
228           <el-checkbox-group v-model="form.${field}">
229             <el-checkbox>请选择字典生成</el-checkbox>
230           </el-checkbox-group>
231         </el-form-item>
232 #elseif($column.htmlType == "radio" && "" != $dictType)
233         <el-form-item label="${comment}" prop="${field}">
234           <el-radio-group v-model="form.${field}">
235             <el-radio
236               v-for="dict in ${dictType}"
237               :key="dict.value"
238 #if($column.javaType == "Integer" || $column.javaType == "Long")
239               :label="parseInt(dict.value)"
240 #else
241               :label="dict.value"
242 #end
243             >{{dict.label}}</el-radio>
244           </el-radio-group>
245         </el-form-item>
246 #elseif($column.htmlType == "radio" && $dictType)
247         <el-form-item label="${comment}" prop="${field}">
248           <el-radio-group v-model="form.${field}">
249             <el-radio label="1">请选择字典生成</el-radio>
250           </el-radio-group>
251         </el-form-item>
252 #elseif($column.htmlType == "datetime")
253         <el-form-item label="${comment}" prop="${field}">
254           <el-date-picker clearable
255             v-model="form.${field}"
256             type="datetime"
257             value-format="YYYY-MM-DD HH:mm:ss"
258             placeholder="请选择${comment}">
259           </el-date-picker>
260         </el-form-item>
261 #elseif($column.htmlType == "textarea")
262         <el-form-item label="${comment}" prop="${field}">
263           <el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" />
264         </el-form-item>
265 #end
266 #end
267 #end
268 #if($table.sub)
269         <el-divider content-position="center">${subTable.functionName}信息</el-divider>
270         <el-row :gutter="10" class="mb8">
271           <el-col :span="1.5">
272             <el-button type="primary" icon="Plus" @click="handleAdd${subClassName}">添加</el-button>
273           </el-col>
274           <el-col :span="1.5">
275             <el-button type="danger" icon="Delete" @click="handleDelete${subClassName}">删除</el-button>
276           </el-col>
277         </el-row>
278         <el-table :data="${subclassName}List" :row-class-name="row${subClassName}Index" @selection-change="handle${subClassName}SelectionChange" ref="${subclassName}">
279           <el-table-column type="selection" width="50" align="center" />
280           <el-table-column label="序号" align="center" prop="index" width="50"/>
281 #foreach($column in $subTable.columns)
282 #set($javaField=$column.javaField)
283 #set($parentheseIndex=$column.columnComment.indexOf("("))
284 #if($parentheseIndex != -1)
285 #set($comment=$column.columnComment.substring(0, $parentheseIndex))
286 #else
287 #set($comment=$column.columnComment)
288 #end
289 #if($column.pk || $javaField == ${subTableFkclassName})
290 #elseif($column.list && $column.htmlType == "input")
291           <el-table-column label="$comment" prop="${javaField}" width="150">
292             <template #default="scope">
293               <el-input v-model="scope.row.$javaField" placeholder="请输入$comment" />
294             </template>
295           </el-table-column>
296 #elseif($column.list && $column.htmlType == "datetime")
297           <el-table-column label="$comment" prop="${javaField}" width="240">
298             <template #default="scope">
299               <el-date-picker clearable
300                 v-model="scope.row.$javaField"
301                 type="date"
302                 value-format="YYYY-MM-DD"
303                 placeholder="请选择$comment">
304               </el-date-picker>
305             </template>
306           </el-table-column>
307 #elseif($column.list && ($column.htmlType == "select" || $column.htmlType == "radio") && "" != $column.dictType)
308           <el-table-column label="$comment" prop="${javaField}" width="150">
309             <template #default="scope">
310               <el-select v-model="scope.row.$javaField" placeholder="请选择$comment">
311                 <el-option
312                   v-for="dict in $column.dictType"
313                   :key="dict.value"
314                   :label="dict.label"
315                   :value="dict.value"
316                 ></el-option>
317               </el-select>
318             </template>
319           </el-table-column>
320 #elseif($column.list && ($column.htmlType == "select" || $column.htmlType == "radio") && "" == $column.dictType)
321           <el-table-column label="$comment" prop="${javaField}" width="150">
322             <template #default="scope">
323               <el-select v-model="scope.row.$javaField" placeholder="请选择$comment">
324                 <el-option label="请选择字典生成" value="" />
325               </el-select>
326             </template>
327           </el-table-column>
328 #end
329 #end
330         </el-table>
331 #end
332       </el-form>
333       <template #footer>
334         <div class="dialog-footer">
335           <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
336           <el-button @click="cancel">取 消</el-button>
337         </div>
338       </template>
339     </el-dialog>
340   </div>
341 </template>
342
343 <script setup name="${BusinessName}">
344 import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName} } from "@/api/${moduleName}/${businessName}";
345
346 const { proxy } = getCurrentInstance();
347 #if(${dicts} != '')
348 #set($dictsNoSymbol=$dicts.replace("'", ""))
349 const { ${dictsNoSymbol} } = proxy.useDict(${dicts});
350 #end
351
352 const ${businessName}List = ref([]);
353 #if($table.sub)
354 const ${subclassName}List = ref([]);
355 #end
356 const open = ref(false);
357 const buttonLoading = ref(false);
358 const loading = ref(true);
359 const showSearch = ref(true);
360 const ids = ref([]);
361 #if($table.sub)
362 const checked${subClassName} = ref([]);
363 #end
364 const single = ref(true);
365 const multiple = ref(true);
366 const total = ref(0);
367 const title = ref("");
368 #foreach ($column in $columns)
369 #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
370 #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
371 const daterange${AttrName} = ref([]);
372 #end
373 #end
374
375 const data = reactive({
376   form: {},
377   queryParams: {
378     pageNum: 1,
379     pageSize: 10,
380 #foreach ($column in $columns)
381 #if($column.query)
382     $column.javaField: undefined#if($foreach.count != $columns.size()),#end
383 #end
384 #end
385   },
386   rules: {
387 #foreach ($column in $columns)
388 #if($column.required)
389 #set($parentheseIndex=$column.columnComment.indexOf("("))
390 #if($parentheseIndex != -1)
391 #set($comment=$column.columnComment.substring(0, $parentheseIndex))
392 #else
393 #set($comment=$column.columnComment)
394 #end
395     $column.javaField: [
396       { required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
397     ]#if($foreach.count != $columns.size()),#end
398 #end
399 #end
400   }
401 });
402
403 const { queryParams, form, rules } = toRefs(data);
404
405 /** 查询${functionName}列表 */
406 function getList() {
407   loading.value = true;
408 #foreach ($column in $columns)
409 #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
410   queryParams.value.params = {};
411 #break
412 #end
413 #end
414 #foreach ($column in $columns)
415 #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
416 #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
417   if (null != daterange${AttrName} && '' != daterange${AttrName}) {
418     queryParams.value.params["begin${AttrName}"] = daterange${AttrName}.value[0];
419     queryParams.value.params["end${AttrName}"] = daterange${AttrName}.value[1];
420   }
421 #end
422 #end
423   list${BusinessName}(queryParams.value).then(response => {
424     ${businessName}List.value = response.rows;
425     total.value = response.total;
426     loading.value = false;
427   });
428 }
429
430 // 取消按钮
431 function cancel() {
432   open.value = false;
433   reset();
434 }
435
436 // 表单重置
437 function reset() {
438   form.value = {
439 #foreach ($column in $columns)
440 #if($column.htmlType == "checkbox")
441     $column.javaField: []#if($foreach.count != $columns.size()),#end
442 #else
443     $column.javaField: null#if($foreach.count != $columns.size()),#end
444 #end
445 #end
446   };
447 #if($table.sub)
448   ${subclassName}List.value = [];
449 #end
450   proxy.resetForm("${businessName}Ref");
451 }
452
453 /** 搜索按钮操作 */
454 function handleQuery() {
455   queryParams.value.pageNum = 1;
456   getList();
457 }
458
459 /** 重置按钮操作 */
460 function resetQuery() {
461 #foreach ($column in $columns)
462 #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
463 #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
464   daterange${AttrName}.value = [];
465 #end
466 #end
467   proxy.resetForm("queryRef");
468   handleQuery();
469 }
470
471 // 多选框选中数据
472 function handleSelectionChange(selection) {
473   ids.value = selection.map(item => item.${pkColumn.javaField});
474   single.value = selection.length != 1;
475   multiple.value = !selection.length;
476 }
477
478 /** 新增按钮操作 */
479 function handleAdd() {
480   reset();
481   open.value = true;
482   title.value = "添加${functionName}";
483 }
484
485 /** 修改按钮操作 */
486 function handleUpdate(row) {
487   loading.value = true
488   reset();
489   const _${pkColumn.javaField} = row.${pkColumn.javaField} || ids.value
490   get${BusinessName}(_${pkColumn.javaField}).then(response => {
491     loading.value = false;
492     form.value = response.data;
493 #foreach ($column in $columns)
494 #if($column.htmlType == "checkbox")
495     form.value.$column.javaField = form.value.${column.javaField}.split(",");
496 #end
497 #end
498 #if($table.sub)
499     ${subclassName}List.value = response.data.${subclassName}List;
500 #end
501     open.value = true;
502     title.value = "修改${functionName}";
503   });
504 }
505
506 /** 提交按钮 */
507 function submitForm() {
508   proxy.#[[$]]#refs["${businessName}Ref"].validate(valid => {
509     if (valid) {
510       buttonLoading.value = true;
511 #foreach ($column in $columns)
512 #if($column.htmlType == "checkbox")
513       form.value.$column.javaField = form.value.${column.javaField}.join(",");
514 #end
515 #end
516 #if($table.sub)
517       form.value.${subclassName}List = ${subclassName}List.value;
518 #end
519       if (form.value.${pkColumn.javaField} != null) {
520         update${BusinessName}(form.value).then(response => {
521           proxy.#[[$modal]]#.msgSuccess("修改成功");
522           open.value = false;
523           getList();
524         }).finally(() => {
525           buttonLoading.value = false;
526         });
527       } else {
528         add${BusinessName}(form.value).then(response => {
529           proxy.#[[$modal]]#.msgSuccess("新增成功");
530           open.value = false;
531           getList();
532         }).finally(() => {
533           buttonLoading.value = false;
534         });
535       }
536     }
537   });
538 }
539
540 /** 删除按钮操作 */
541 function handleDelete(row) {
542   const _${pkColumn.javaField}s = row.${pkColumn.javaField} || ids.value;
543   proxy.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + _${pkColumn.javaField}s + '"的数据项?').then(function() {
544     loading.value = true;
545     return del${BusinessName}(_${pkColumn.javaField}s);
546   }).then(() => {
547     loading.value = true;
548     getList();
549     proxy.#[[$modal]]#.msgSuccess("删除成功");
550   }).catch(() => {
551   }).finally(() => {
552     loading.value = false;
553   });
554 }
555
556 #if($table.sub)
557 /** ${subTable.functionName}序号 */
558 function row${subClassName}Index({ row, rowIndex }) {
559   row.index = rowIndex + 1;
560 }
561
562 /** ${subTable.functionName}添加按钮操作 */
563 function handleAdd${subClassName}() {
564   let obj = {};
565 #foreach($column in $subTable.columns)
566 #if($column.pk || $column.javaField == ${subTableFkclassName})
567 #elseif($column.list && "" != $javaField)
568   obj.$column.javaField = "";
569 #end
570 #end
571   ${subclassName}List.value.push(obj);
572 }
573
574 /** ${subTable.functionName}删除按钮操作 */
575 function handleDelete${subClassName}() {
576   if (checked${subClassName}.value.length == 0) {
577     proxy.#[[$modal]]#.msgError("请先选择要删除的${subTable.functionName}数据");
578   } else {
579     const ${subclassName}s = ${subclassName}List.value;
580     const checked${subClassName}s = checked${subClassName}.value;
581     ${subclassName}List.value = ${subclassName}s.filter(function(item) {
582       return checked${subClassName}s.indexOf(item.index) == -1
583     });
584   }
585 }
586
587 /** 复选框选中数据 */
588 function handle${subClassName}SelectionChange(selection) {
589   checked${subClassName}.value = selection.map(item => item.index)
590 }
591
592 #end
593 /** 导出按钮操作 */
594 function handleExport() {
595   proxy.download('${moduleName}/${businessName}/export', {
596     ...queryParams.value
597   }, `${businessName}_#[[${new Date().getTime()}]]#.xlsx`)
598 }
599
600 getList();
601 </script>