提交 | 用户 | age
|
2a61f6
|
1 |
<template> |
L |
2 |
<div class="app-container"> |
|
3 |
<!-- 搜索区 ↓↓↓↓↓↓↓↓↓↓ --> |
|
4 |
<el-form v-show="showSearch" ref="searchForm" :inline="true"> |
|
5 |
<el-form-item label="管理员搜索"> |
|
6 |
<el-input |
|
7 |
v-model="keyWord" |
|
8 |
placeholder="请输入管理员名称/账号" |
|
9 |
clearable |
|
10 |
size="small" |
|
11 |
style="width: 240px" |
|
12 |
@keyup.enter.native="reGetList" |
|
13 |
/> |
|
14 |
</el-form-item> |
|
15 |
<el-form-item> |
|
16 |
<el-button type="cyan" icon="el-icon-search" size="mini" @click="reGetList">搜索</el-button> |
|
17 |
<el-button icon="el-icon-refresh" size="mini" @click="resetHandle">重置</el-button> |
|
18 |
</el-form-item> |
|
19 |
</el-form> |
|
20 |
<!-- 搜索区 ↑↑↑↑↑↑↑↑↑↑ --> |
|
21 |
|
|
22 |
<!-- 操作区 ↓↓↓↓↓↓↓↓↓↓ --> |
|
23 |
<el-row :gutter="10" class="mb8"> |
|
24 |
<el-col :span="1.5"> |
|
25 |
<el-button |
|
26 |
v-if="getAuthValueFN('sys_admin_add')" |
|
27 |
type="primary" |
|
28 |
icon="el-icon-plus" |
|
29 |
size="mini" |
|
30 |
@click="showAddAdminDialog" |
|
31 |
>新增</el-button> |
|
32 |
</el-col> |
|
33 |
<right-toolbar :show-search.sync="showSearch" @queryTable="getList" /> |
|
34 |
</el-row> |
|
35 |
<!-- 操作区 ↑↑↑↑↑↑↑↑↑↑ --> |
|
36 |
|
|
37 |
<el-table :data="list"> |
|
38 |
<el-table-column type="index" label="序号" align="center" width="60" /> |
|
39 |
<el-table-column label="姓名" prop="name" align="center" min-width="120" /> |
|
40 |
<el-table-column label="账号" prop="account" align="center" min-width="120" /> |
|
41 |
<el-table-column label="角色" prop="roleName" align="center" min-width="120" /> |
|
42 |
<!-- <el-table-column label="最近登录时间" prop="loginTime" align="center" min-width="180" /> --> |
|
43 |
<el-table-column label="状态" align="center" min-width="100"> |
|
44 |
<template slot-scope="scope"> |
|
45 |
<el-switch |
|
46 |
v-model="scope.row.isUse" |
|
47 |
:active-value="1" |
|
48 |
:inactive-value="0" |
|
49 |
:disabled="!getAuthValueFN('sys_admin_edit')" |
|
50 |
@change="handleStatusChange(scope.row)" |
|
51 |
/> |
|
52 |
</template> |
|
53 |
</el-table-column> |
|
54 |
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="100"> |
|
55 |
<template slot-scope="scope"> |
|
56 |
<el-button |
|
57 |
v-if="getAuthValueFN('sys_admin_edit')" |
|
58 |
size="mini" |
|
59 |
type="text" |
|
60 |
icon="el-icon-edit" |
|
61 |
@click="showEditAdminDialog(scope.row)" |
|
62 |
>编辑</el-button> |
|
63 |
<el-button |
|
64 |
v-if="getAuthValueFN('sys_admin_del')" |
|
65 |
size="mini" |
|
66 |
type="text warn" |
|
67 |
icon="el-icon-delete" |
|
68 |
@click="handleDelete(scope.row)" |
|
69 |
>删除</el-button> |
|
70 |
</template> |
|
71 |
</el-table-column> |
|
72 |
</el-table> |
|
73 |
|
|
74 |
<pagination |
|
75 |
v-show="total>0" |
|
76 |
:total="total" |
|
77 |
:page.sync="pageNum" |
|
78 |
:limit.sync="pageSize" |
|
79 |
@pagination="getList" |
|
80 |
/> |
|
81 |
|
|
82 |
<!-- 新增&编辑 --> |
|
83 |
<el-dialog :title="adminDialogData.type=='add'?'新增管理员':'编辑管理员'" width="500px" :visible.sync="isShowadminDialog" append-to-body> |
|
84 |
<el-form ref="adminDialog" :model="adminDialogData" label-width="80px" :rules="rules"> |
|
85 |
<el-form-item label="名称" prop="name"> |
|
86 |
<el-input v-model="adminDialogData.name" placeholder="请输入名称" /> |
|
87 |
</el-form-item> |
|
88 |
<el-form-item label="账号" prop="account"> |
|
89 |
<el-input v-model="adminDialogData.account" placeholder="请输入帐号" :disabled="adminDialogData.type!='add'" /> |
|
90 |
</el-form-item> |
|
91 |
<el-form-item label="密码" prop="password"> |
|
92 |
<el-input v-model="adminDialogData.password" type="password" placeholder="请输入密码" /> |
|
93 |
</el-form-item> |
|
94 |
<el-form-item label="确认密码" prop="passwordSure"> |
|
95 |
<el-input v-model="adminDialogData.passwordSure" type="password" placeholder="请输入确认密码" /> |
|
96 |
</el-form-item> |
|
97 |
<!-- 角色 --> |
|
98 |
<!-- 选择框 --> |
|
99 |
<el-form-item label="角色" prop="sysRoleId"> |
|
100 |
<el-select |
|
101 |
v-model="adminDialogData.sysRoleId" |
|
102 |
clearable |
|
103 |
placeholder="角色" |
|
104 |
class="com-edit-input" |
|
105 |
> |
|
106 |
<el-option v-for="item in roleArr" :key="item.id" :label="item.name" :value="item.id" /> |
|
107 |
</el-select> |
|
108 |
</el-form-item> |
|
109 |
|
|
110 |
</el-form> |
|
111 |
<div slot="footer" class="dialog-footer"> |
|
112 |
<el-button @click="hideAdminDialog">取消</el-button> |
|
113 |
<el-button type="primary" @click="submitAdmin(adminDialogData.type)">确定</el-button> |
|
114 |
</div> |
|
115 |
</el-dialog> |
|
116 |
</div> |
|
117 |
</template> |
|
118 |
|
|
119 |
<script> |
|
120 |
|
|
121 |
export default { |
|
122 |
name: 'Admin', |
|
123 |
data() { |
|
124 |
const equalToPassword = (rule, value, callback) => { |
|
125 |
if (this.adminDialogData.password !== value) { |
|
126 |
callback(new Error('两次输入的密码不一致')) |
|
127 |
} else { |
|
128 |
callback() |
|
129 |
} |
|
130 |
} |
|
131 |
return { |
|
132 |
showSearch: true, // 是否显示搜索区 |
|
133 |
keyWord: '', |
|
134 |
|
|
135 |
list: [], |
|
136 |
|
|
137 |
// 角色列表 |
|
138 |
roleArr: [], |
|
139 |
|
|
140 |
isShowadminDialog: false, |
|
141 |
adminDialogData: {}, |
|
142 |
|
|
143 |
// 分页 ↓↓↓↓↓↓↓↓↓↓ |
|
144 |
total: 0, |
|
145 |
pageNum: 1, |
|
146 |
pageSize: 20, |
|
147 |
// 分页 ↑↑↑↑↑↑↑↑↑↑ |
|
148 |
|
|
149 |
// 表单校验 |
|
150 |
rules: { |
|
151 |
name: [ |
|
152 |
{ required: true, message: '名称不能为空', trigger: 'change' } |
|
153 |
], |
|
154 |
account: [ |
|
155 |
{ required: true, message: '账号不能为空', trigger: 'change' } |
|
156 |
], |
|
157 |
password: [ |
|
158 |
{ required: true, message: '密码不能为空', trigger: 'change' } |
|
159 |
], |
|
160 |
passwordSure: [ |
|
161 |
{ required: true, message: '确认密码不能为空', trigger: 'change' }, |
|
162 |
{ required: true, validator: equalToPassword, trigger: 'change' } |
|
163 |
], |
|
164 |
sysRoleId: [ |
|
165 |
{ required: true, message: '角色不能为空', trigger: 'change' } |
|
166 |
] |
|
167 |
} |
|
168 |
} |
|
169 |
}, |
|
170 |
mounted() { |
|
171 |
this.init() |
|
172 |
}, |
|
173 |
methods: { |
|
174 |
// 初始化 |
|
175 |
init() { |
|
176 |
this.getList() |
|
177 |
this.getRoleList() |
|
178 |
}, |
|
179 |
|
|
180 |
// 获取角色列表 |
|
181 |
getRoleList() { |
|
182 |
this.postFN({ |
|
183 |
url: 'admin/roleList', |
|
184 |
mockData: { |
|
185 |
code: 100, |
|
186 |
msg: '', |
|
187 |
data: [{ |
|
188 |
id: 'xxx', |
|
189 |
name: '野马发' |
|
190 |
}] |
|
191 |
} |
|
192 |
}, (inf) => { |
|
193 |
this.roleArr = inf || [] |
|
194 |
}) |
|
195 |
}, |
|
196 |
|
|
197 |
// 获取列表 |
|
198 |
getList() { |
|
199 |
var { pageNum, pageSize, keyWord } = this |
|
200 |
this.postFN({ |
|
201 |
url: 'admin/list', |
|
202 |
params: { |
|
203 |
pageNum: pageNum, |
|
204 |
rowCount: pageSize, |
|
205 |
keyWord: keyWord |
|
206 |
}, |
|
207 |
mockData: { |
|
208 |
code: 100, |
|
209 |
msg: '', |
|
210 |
data: { |
|
211 |
list: [{ |
|
212 |
id: 'xxx', |
|
213 |
account: 'xasdasd2123123', |
|
214 |
name: '野马发', |
|
215 |
roleName: '超级管理员', |
|
216 |
tel: '13760749294', |
|
217 |
loginTime: '2020-08-08 12:10:10', |
|
218 |
isUse: 1 |
|
219 |
}], |
|
220 |
total: 100 |
|
221 |
} |
|
222 |
} |
|
223 |
}, (inf) => { |
|
224 |
this.list = inf.list || [] |
|
225 |
this.total = inf.total |
|
226 |
}) |
|
227 |
}, |
|
228 |
// 重新获取列表 |
|
229 |
reGetList() { |
|
230 |
this.pageNum = 1 |
|
231 |
this.getList() |
|
232 |
}, |
|
233 |
// 重置 |
|
234 |
resetHandle() { |
|
235 |
this.keyWord = '' |
|
236 |
this.reGetList() |
|
237 |
}, |
|
238 |
// 修改状态 |
|
239 |
handleStatusChange(item) { |
|
240 |
const text = item.isUse === 1 ? '启用' : '停用' |
|
241 |
this.$confirm('确认要' + text + '"' + item.roleName + '"角色吗?', '提示', { |
|
242 |
confirmButtonText: '确定', |
|
243 |
cancelButtonText: '取消', |
|
244 |
type: 'warning' |
|
245 |
}).then(() => { |
|
246 |
this.postFN({ |
|
247 |
url: 'admin/editUse', |
|
248 |
params: { |
|
249 |
id: item.id |
|
250 |
}, |
|
251 |
mockData: { |
|
252 |
code: 100, |
|
253 |
msg: '', |
|
254 |
data: {} |
|
255 |
} |
|
256 |
}, () => { |
|
257 |
this.$messageSuc(text + '成功') |
|
258 |
}) |
|
259 |
}).catch(() => { |
|
260 |
item.isUse = item.isUse === 1 ? 0 : 1 |
|
261 |
}) |
|
262 |
}, |
|
263 |
// 删除 |
|
264 |
handleDelete(item) { |
|
265 |
// 打开二次确认弹窗 |
|
266 |
this.$confirm('是否确认删除该帐号?', '提示', { |
|
267 |
confirmButtonText: '确定', |
|
268 |
cancelButtonText: '取消', |
|
269 |
type: 'warning' |
|
270 |
}).then(() => { |
|
271 |
// 确定回调 |
|
272 |
this.postFN({ |
|
273 |
url: 'admin/delete/one', |
|
274 |
params: { |
|
275 |
id: item.id |
|
276 |
}, |
|
277 |
mockData: { |
|
278 |
code: 100, |
|
279 |
msg: '', |
|
280 |
data: {} |
|
281 |
} |
|
282 |
}, () => { |
|
283 |
this.getList() |
|
284 |
this.$messageSuc('删除成功') |
|
285 |
}) |
|
286 |
}).catch(() => {}) |
|
287 |
}, |
|
288 |
|
|
289 |
// 打开新增分类弹窗 |
|
290 |
showAddAdminDialog() { |
|
291 |
var adminDialogData = { |
|
292 |
type: 'add', |
|
293 |
name: '', |
|
294 |
account: '', |
|
295 |
password: '', |
|
296 |
passwordSure: '', |
|
297 |
sysRoleId: '' |
|
298 |
} |
|
299 |
this.adminDialogData = adminDialogData |
|
300 |
this.isShowadminDialog = true |
|
301 |
}, |
|
302 |
// 打开编辑分类弹框 |
|
303 |
showEditAdminDialog(item) { |
|
304 |
var adminDialogData = { |
|
305 |
type: 'edit', |
|
306 |
name: item.name, |
|
307 |
account: item.account, |
|
308 |
password: '', |
|
309 |
passwordSure: '', |
|
310 |
sysRoleId: item.roId, |
|
311 |
id: item.id |
|
312 |
} |
|
313 |
this.adminDialogData = adminDialogData |
|
314 |
this.isShowadminDialog = true |
|
315 |
}, |
|
316 |
// 关闭编辑弹窗 |
|
317 |
hideAdminDialog() { |
|
318 |
this.adminDialogData = {} |
|
319 |
this.isShowadminDialog = false |
|
320 |
}, |
|
321 |
// 提交新增&编辑 |
|
322 |
submitAdmin(type) { |
|
323 |
this.$refs['adminDialog'].validate(valid => { |
|
324 |
if (valid) { |
|
325 |
var { adminDialogData } = this |
|
326 |
var params = { |
|
327 |
name: adminDialogData.name, |
|
328 |
account: adminDialogData.account, |
|
329 |
password: adminDialogData.password, |
|
330 |
sysAdRoleId: adminDialogData.sysRoleId |
|
331 |
} |
|
332 |
var isAdd = adminDialogData.type === 'add' |
|
333 |
var url = isAdd ? 'admin/add' : 'admin/update' |
|
334 |
|
|
335 |
!isAdd && (params.id = adminDialogData.id) |
|
336 |
|
|
337 |
this.postFN({ |
|
338 |
url: url, |
|
339 |
params: params, |
|
340 |
mockData: { |
|
341 |
code: 100, |
|
342 |
msg: '', |
|
343 |
data: {} |
|
344 |
} |
|
345 |
}, () => { |
|
346 |
this.$messageSuc('保存成功') |
|
347 |
this.hideAdminDialog() |
|
348 |
this.getList() |
|
349 |
}) |
|
350 |
} |
|
351 |
}) |
|
352 |
} |
|
353 |
|
|
354 |
} |
|
355 |
} |
|
356 |
</script> |
|
357 |
|
|
358 |
<style lang="scss" scoped> |
|
359 |
|
|
360 |
</style> |