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       <el-form-item label="参数名称" prop="configName">
5         <el-input
6           v-model="queryParams.configName"
7           placeholder="请输入参数名称"
8           clearable
9           style="width: 240px"
10           @keyup.enter.native="handleQuery"
11         />
12       </el-form-item>
13       <el-form-item label="参数键名" prop="configKey">
14         <el-input
15           v-model="queryParams.configKey"
16           placeholder="请输入参数键名"
17           clearable
18           style="width: 240px"
19           @keyup.enter.native="handleQuery"
20         />
21       </el-form-item>
22       <el-form-item label="系统内置" prop="configType">
23         <el-select v-model="queryParams.configType" placeholder="系统内置" clearable>
24           <el-option
25             v-for="dict in dict.type.sys_yes_no"
26             :key="dict.value"
27             :label="dict.label"
28             :value="dict.value"
29           />
30         </el-select>
31       </el-form-item>
32       <el-form-item label="创建时间">
33         <el-date-picker
34           v-model="dateRange"
35           style="width: 240px"
36           value-format="yyyy-MM-dd HH:mm:ss"
37           type="daterange"
38           range-separator="-"
39           start-placeholder="开始日期"
40           end-placeholder="结束日期"
41           :default-time="['00:00:00', '23:59:59']"
42         ></el-date-picker>
43       </el-form-item>
44       <el-form-item>
45         <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
46         <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
47       </el-form-item>
48     </el-form>
49
50     <el-row :gutter="10" class="mb8">
51       <el-col :span="1.5">
52         <el-button
53           type="primary"
54           plain
55           icon="el-icon-plus"
56           size="mini"
57           @click="handleAdd"
58           v-hasPermi="['system:config:add']"
59         >新增</el-button>
60       </el-col>
61       <el-col :span="1.5">
62         <el-button
63           type="success"
64           plain
65           icon="el-icon-edit"
66           size="mini"
67           :disabled="single"
68           @click="handleUpdate"
69           v-hasPermi="['system:config:edit']"
70         >修改</el-button>
71       </el-col>
72       <el-col :span="1.5">
73         <el-button
74           type="danger"
75           plain
76           icon="el-icon-delete"
77           size="mini"
78           :disabled="multiple"
79           @click="handleDelete"
80           v-hasPermi="['system:config:remove']"
81         >删除</el-button>
82       </el-col>
83       <el-col :span="1.5">
84         <el-button
85           type="warning"
86           plain
87           icon="el-icon-download"
88           size="mini"
89           @click="handleExport"
90           v-hasPermi="['system:config:export']"
91         >导出</el-button>
92       </el-col>
93       <el-col :span="1.5">
94         <el-button
95           type="danger"
96           plain
97           icon="el-icon-refresh"
98           size="mini"
99           @click="handleRefreshCache"
100           v-hasPermi="['system:config:remove']"
101         >刷新缓存</el-button>
102       </el-col>
103       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
104     </el-row>
105
106     <el-table v-loading="loading" :data="configList" @selection-change="handleSelectionChange">
107       <el-table-column type="selection" width="55" align="center" />
108       <el-table-column label="参数主键" align="center" prop="configId" />
109       <el-table-column label="参数名称" align="center" prop="configName" :show-overflow-tooltip="true" />
110       <el-table-column label="参数键名" align="center" prop="configKey" :show-overflow-tooltip="true" />
111       <el-table-column label="参数键值" align="center" prop="configValue" :show-overflow-tooltip="true" />
112       <el-table-column label="系统内置" align="center" prop="configType">
113         <template slot-scope="scope">
114           <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.configType"/>
115         </template>
116       </el-table-column>
117       <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
118       <el-table-column label="创建时间" align="center" prop="createTime" width="180">
119         <template slot-scope="scope">
120           <span>{{ parseTime(scope.row.createTime) }}</span>
121         </template>
122       </el-table-column>
123       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
124         <template slot-scope="scope">
125           <el-button
126             size="mini"
127             type="text"
128             icon="el-icon-edit"
129             @click="handleUpdate(scope.row)"
130             v-hasPermi="['system:config:edit']"
131           >修改</el-button>
132           <el-button
133             size="mini"
134             type="text"
135             icon="el-icon-delete"
136             @click="handleDelete(scope.row)"
137             v-hasPermi="['system:config:remove']"
138           >删除</el-button>
139         </template>
140       </el-table-column>
141     </el-table>
142
143     <pagination
144       v-show="total>0"
145       :total="total"
146       :page.sync="queryParams.pageNum"
147       :limit.sync="queryParams.pageSize"
148       @pagination="getList"
149     />
150
151     <!-- 添加或修改参数配置对话框 -->
152     <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
153       <el-form ref="form" :model="form" :rules="rules" label-width="80px">
154         <el-form-item label="参数名称" prop="configName">
155           <el-input v-model="form.configName" placeholder="请输入参数名称" />
156         </el-form-item>
157         <el-form-item label="参数键名" prop="configKey">
158           <el-input v-model="form.configKey" placeholder="请输入参数键名" />
159         </el-form-item>
160         <el-form-item label="参数键值" prop="configValue">
161           <el-input v-model="form.configValue" placeholder="请输入参数键值" />
162         </el-form-item>
163         <el-form-item label="系统内置" prop="configType">
164           <el-radio-group v-model="form.configType">
165             <el-radio
166               v-for="dict in dict.type.sys_yes_no"
167               :key="dict.value"
168               :label="dict.value"
169             >{{dict.label}}</el-radio>
170           </el-radio-group>
171         </el-form-item>
172         <el-form-item label="备注" prop="remark">
173           <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
174         </el-form-item>
175       </el-form>
176       <div slot="footer" class="dialog-footer">
177         <el-button type="primary" @click="submitForm">确 定</el-button>
178         <el-button @click="cancel">取 消</el-button>
179       </div>
180     </el-dialog>
181   </div>
182 </template>
183
184 <script>
185 import { listConfig, getConfig, delConfig, addConfig, updateConfig, refreshCache } from "@/api/system/config";
186
187 export default {
188   name: "Config",
189   dicts: ['sys_yes_no'],
190   data() {
191     return {
192       // 遮罩层
193       loading: true,
194       // 选中数组
195       ids: [],
196       // 非单个禁用
197       single: true,
198       // 非多个禁用
199       multiple: true,
200       // 显示搜索条件
201       showSearch: true,
202       // 总条数
203       total: 0,
204       // 参数表格数据
205       configList: [],
206       // 弹出层标题
207       title: "",
208       // 是否显示弹出层
209       open: false,
210       // 日期范围
211       dateRange: [],
212       // 查询参数
213       queryParams: {
214         pageNum: 1,
215         pageSize: 10,
216         configName: undefined,
217         configKey: undefined,
218         configType: undefined
219       },
220       // 表单参数
221       form: {},
222       // 表单校验
223       rules: {
224         configName: [
225           { required: true, message: "参数名称不能为空", trigger: "blur" }
226         ],
227         configKey: [
228           { required: true, message: "参数键名不能为空", trigger: "blur" }
229         ],
230         configValue: [
231           { required: true, message: "参数键值不能为空", trigger: "blur" }
232         ]
233       }
234     };
235   },
236   created() {
237     this.getList();
238   },
239   methods: {
240     /** 查询参数列表 */
241     getList() {
242       this.loading = true;
243       listConfig(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
244           this.configList = response.rows;
245           this.total = response.total;
246           this.loading = false;
247         }
248       );
249     },
250     // 取消按钮
251     cancel() {
252       this.open = false;
253       this.reset();
254     },
255     // 表单重置
256     reset() {
257       this.form = {
258         configId: undefined,
259         configName: undefined,
260         configKey: undefined,
261         configValue: undefined,
262         configType: "Y",
263         remark: undefined
264       };
265       this.resetForm("form");
266     },
267     /** 搜索按钮操作 */
268     handleQuery() {
269       this.queryParams.pageNum = 1;
270       this.getList();
271     },
272     /** 重置按钮操作 */
273     resetQuery() {
274       this.dateRange = [];
275       this.resetForm("queryForm");
276       this.handleQuery();
277     },
278     /** 新增按钮操作 */
279     handleAdd() {
280       this.reset();
281       this.open = true;
282       this.title = "添加参数";
283     },
284     // 多选框选中数据
285     handleSelectionChange(selection) {
286       this.ids = selection.map(item => item.configId)
287       this.single = selection.length!=1
288       this.multiple = !selection.length
289     },
290     /** 修改按钮操作 */
291     handleUpdate(row) {
292       this.reset();
293       const configId = row.configId || this.ids
294       getConfig(configId).then(response => {
295         this.form = response.data;
296         this.open = true;
297         this.title = "修改参数";
298       });
299     },
300     /** 提交按钮 */
301     submitForm: function() {
302       this.$refs["form"].validate(valid => {
303         if (valid) {
304           if (this.form.configId != undefined) {
305             updateConfig(this.form).then(response => {
306               this.$modal.msgSuccess("修改成功");
307               this.open = false;
308               this.getList();
309             });
310           } else {
311             addConfig(this.form).then(response => {
312               this.$modal.msgSuccess("新增成功");
313               this.open = false;
314               this.getList();
315             });
316           }
317         }
318       });
319     },
320     /** 删除按钮操作 */
321     handleDelete(row) {
322       const configIds = row.configId || this.ids;
323       this.$modal.confirm('是否确认删除参数编号为"' + configIds + '"的数据项?').then(function() {
324           return delConfig(configIds);
325         }).then(() => {
326           this.getList();
327           this.$modal.msgSuccess("删除成功");
328         }).catch(() => {});
329     },
330     /** 导出按钮操作 */
331     handleExport() {
332       this.download('system/config/export', {
333         ...this.queryParams
334       }, `config_${new Date().getTime()}.xlsx`)
335     },
336     /** 刷新缓存按钮操作 */
337     handleRefreshCache() {
338       refreshCache().then(() => {
339         this.$modal.msgSuccess("刷新成功");
340       });
341     }
342   }
343 };
344 </script>