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