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