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