潘志宝
3 天以前 e14de70a3c4b393498d3e95717b19240c4426c22
提交 | 用户 | 时间
e7c126 1 #set ($subTable = $subTables.get($subIndex))##当前表
H 2 #set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
3 #set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
4 #set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
5 #set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
6 #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
7 <template>
8   <div class="app-container">
9 #if ($table.templateType == 11)
10     <!-- 操作工具栏 -->
11     <el-row :gutter="10" class="mb8">
12       <el-col :span="1.5">
13         <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)"
14                    v-hasPermi="['${permissionPrefix}:create']">新增</el-button>
15       </el-col>
16     </el-row>
17 #end
18       ## 列表
19       <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
20           #foreach($column in $subColumns)
21               #if ($column.listOperationResult)
22                   #set ($dictType=$column.dictType)
23                   #set ($javaField = $column.javaField)
24                   #set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
25                   #set ($comment=$column.columnComment)
26                   #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
27                   #elseif ($column.javaType == "LocalDateTime")## 时间类型
28                 <el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
29                   <template v-slot="scope">
30                     <span>{{ parseTime(scope.row.${javaField}) }}</span>
31                   </template>
32                 </el-table-column>
33                   #elseif($column.dictType && "" != $column.dictType)## 数据字典
34                 <el-table-column label="${comment}" align="center" prop="${javaField}">
35                   <template v-slot="scope">
36                     <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.${column.javaField}" />
37                   </template>
38                 </el-table-column>
39               #else
40                 <el-table-column label="${comment}" align="center" prop="${javaField}" />
41               #end
42           #end
43       #end
44     <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
45       <template v-slot="scope">
46         <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.${primaryColumn.javaField})"
47                    v-hasPermi="['${permissionPrefix}:update']">修改</el-button>
48         <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
49                    v-hasPermi="['${permissionPrefix}:delete']">删除</el-button>
50       </template>
51     </el-table-column>
52   </el-table>
53 #if ($table.templateType == 11)
54     <!-- 分页组件 -->
55     <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
56                 @pagination="getList"/>
57   <!-- 对话框(添加 / 修改) -->
58   <${subSimpleClassName}Form ref="formRef" @success="getList" />
59 #end
60   </div>
61 </template>
62
63 <script>
64   import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}';
65   #if ($table.templateType == 11)
66   import ${subSimpleClassName}Form from './${subSimpleClassName}Form.vue';
67   #end
68   export default {
69     name: "${subSimpleClassName}List",
70 #if ($table.templateType == 11)
71     components: {
72        ${subSimpleClassName}Form
73     },
74 #end
75     props:[
76       '${subJoinColumn.javaField}'
77     ],// ${subJoinColumn.columnComment}(主表的关联字段)
78     data() {
79       return {
80         // 遮罩层
81         loading: true,
82         // 列表的数据
83         list: [],
84 #if ($table.templateType == 11)
85         // 列表的总页数
86         total: 0,
87         // 查询参数
88         queryParams: {
89           pageNo: 1,
90           pageSize: 10,
91           ${subJoinColumn.javaField}: undefined
92         }
93 #end
94       };
95     },
96 #if ($table.templateType != 11)
97     created() {
98       this.getList();
99     },
100 #end
101     watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */
102         ${subJoinColumn.javaField}:{
103             handler(val) {
104               this.queryParams.${subJoinColumn.javaField} = val;
105               if (val){
106                 this.handleQuery();
107               }
108             },
109             immediate: true
110       }
111     },
112     methods: {
113       /** 查询列表 */
114       async getList() {
115         try {
116           this.loading = true;
117           #if ($table.templateType == 11)
118             const res = await ${simpleClassName}Api.get${subSimpleClassName}Page(this.queryParams);
119             this.list = res.data.list;
120             this.total = res.data.total;
121           #else
122               #if ( $subTable.subJoinMany )
123                 const res = await ${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(this.${subJoinColumn.javaField});
124                 this.list = res.data;
125               #else
126                 const res = await  ${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(this.${subJoinColumn.javaField});
127                 const data = res.data;
128                 if (!data) {
129                   return;
130                 }
131                 this.list.push(data);
132               #end
133           #end
134         } finally {
135           this.loading = false;
136         }
137       },
138       /** 搜索按钮操作 */
139       handleQuery() {
140         this.queryParams.pageNo = 1;
141         this.getList();
142       },
143 #if ($table.templateType == 11)
144       /** 添加/修改操作 */
145       openForm(id) {
146         if (!this.${subJoinColumn.javaField}) {
147           this.#[[$modal]]#.msgError('请选择一个${table.classComment}');
148           return;
149         }
150         this.#[[$]]#refs["formRef"].open(id, this.${subJoinColumn.javaField});
151       },
152       /** 删除按钮操作 */
153       async handleDelete(row) {
154         const ${primaryColumn.javaField} = row.${primaryColumn.javaField};
155         await this.#[[$modal]]#.confirm('是否确认删除${table.classComment}编号为"' + ${primaryColumn.javaField} + '"的数据项?');
156         try {
157           await ${simpleClassName}Api.delete${subSimpleClassName}(${primaryColumn.javaField});
158           await this.getList();
159           this.#[[$modal]]#.msgSuccess("删除成功");
160         } catch {}
161       },
162 #end
163     }
164   };
165 </script>