adminList.vue
11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<template>
<div class="app-container">
<div class="seetingsDiv" style="">
<el-button type="primary" @click="dialogClassIVIsible=true">添加
</el-button>
</div>
<el-table :data="userList" id="QuestionTable" border
style="width: 100%;border-radius: 5px;box-shadow: 0 0 10px #efefef;margin-top: 10px;" :stripe='true'>
<el-table-column type="index" prop="date" width="50" align="center"></el-table-column>
<el-table-column prop="date" label="名称">
<template slot-scope="scope">
<span>{{ scope.row.fullName }}</span>
</template>
</el-table-column>
<el-table-column prop="date" label="电话号码">
<template slot-scope="scope">
<el-tooltip class="item" effect="dark" :content="scope.row.phone " placement="top-start">
<span>{{ scope.row.phone1 }}</span>
</el-tooltip>
</template>
</el-table-column>
<el-table-column prop="username" label="登录账号">
</el-table-column>
<el-table-column fixed="right" label="操作" width="150">
<template slot-scope="scope">
<el-dropdown @command="(e)=>{handleCommand(e,scope.row)}">
<span class="el-dropdown-link">
操作<i class="el-icon-arrow-down el-icon--right"></i>
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item command="update">编辑</el-dropdown-item>
<el-dropdown-item command="updatePassword">修改密码</el-dropdown-item>
<el-dropdown-item command="del" v-if="scope.row.username!='admin'">删除</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</template>
</el-table-column>
</el-table>
<el-pagination background @current-change="currentchange"
style="position:static;bottom: 3px;text-align: center;margin-top: 5px;" :page-size="this.query.PageSize"
layout="total,prev, pager, next" :total="Count">
</el-pagination>
<el-dialog :title="title" :visible.sync="dialogClassIVIsible" @close="closeClassDialog" width="450"
:close-on-click-modal="false">
<el-form ref="adminUserInfo" :rules="rules" :model="adminUserInfo" label-width="90px" style="margin-left: 40px;">
<el-form-item label="名称" prop="fullName">
<el-input v-model="adminUserInfo.fullName " placeholder="请输入管理员名称" style="width: 40%;"></el-input>
</el-form-item>
<el-form-item label="联系方式" >
<el-input v-model="adminUserInfo.phone " placeholder="请输入联系方式" style="width: 40%;" maxlength="11"></el-input>
</el-form-item>
<el-form-item label="登录账号" style="margin-top: 40px;" prop="username">
<el-input v-model="adminUserInfo.username" placeholder="请输入登录账号" style="width: 40%;"></el-input>
</el-form-item>
<el-form-item label="密码" prop="password" v-if="title=='添加管理员'">
<el-input v-model="adminUserInfo.password " placeholder="请输入密码" show-password style="width: 40%;"></el-input>
</el-form-item>
<el-form-item style="text-align: right;">
<el-button @click="dialogClassIVIsible=false">取消</el-button>
<el-button type="primary" @click="submitForm('adminUserInfo')">{{buttonText}}</el-button>
</el-form-item>
</el-form>
<div style="clear: both;"></div>
</el-dialog>
<el-dialog title="修改密码" :visible.sync="dialogClassIVIsibleT" @close="closeClassDialogT" width="450"
:close-on-click-modal="false">
<el-form :model="ruleForm" status-icon :rules="rulesT" ref="ruleForm" label-width="100px" class="demo-ruleForm" style="width: 320px;">
<el-form-item label="密码" prop="Password">
<el-input type="password" v-model="ruleForm.Password" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="确认密码" prop="checkPass">
<el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitFormT('ruleForm')">提交</el-button>
<el-button @click="resetForm('ruleForm')">重置</el-button>
</el-form-item>
</el-form>
<div style="clear: both;"></div>
</el-dialog>
</div>
</template>
<script>
import {
GetUserList,
UsersCreate,
UsersUpdate,
UsersDelete,
AccountRegister,
GetUserListByAdmin,
UpdateCurrentPasswordById
} from '@/api/user'
import {
formatTime
} from '@/utils/util.js'
export default {
data() {
var checkPhone = (rule, value, callback) => {
const phoneReg = /^1[3|4|5|7|8][0-9]{9}$/
if (!value) {
return callback(new Error('电话号码不能为空'))
}
setTimeout(() => {
if (!Number.isInteger(+value)) {
callback(new Error('请输入数字值'))
} else {
if (phoneReg.test(value)) {
callback()
} else {
callback(new Error('电话号码格式不正确'))
}
}
}, 100)
}
var validatePass = (rule, value, callback) => {
if (value === '') {
callback(new Error('请输入密码'));
} else {
if (this.ruleForm.checkPass !== '') {
this.$refs.ruleForm.validateField('checkPass');
}
callback();
}
};
var validatePass2 = (rule, value, callback) => {
if (value === '') {
callback(new Error('请再次输入密码'));
} else if (value !== this.ruleForm.Password) {
callback(new Error('两次输入密码不一致!'));
} else {
callback();
}
};
return {
title: '添加管理员',
buttonText: '立即创建',
userList: [],
dialogClassIVIsible: false,
dialogClassIVIsibleT:false,
adminUserInfo: {
username: "",
password: "",
// type: 4,
fullName: "",
// remark: "",
phone: "",
// sex: "",
// card: "",
// address: "",
// birthday: "",
status: 1,
},
ruleForm: {
UserId:0,
Password: '',
checkPass: '',
},
rulesT: {
Password: [
{ validator: validatePass, trigger: 'blur' }
],
checkPass: [
{ validator: validatePass2, trigger: 'blur' }
],
},
Count: 0,
query: {
UserTypeEnum: 5, //0:管理员,1普通用户
PageIndex: 1,
PageSize: 10,
},
rules: {
fullName: [{
required: true,
message: '请输入管理员名称',
trigger: 'blur'
}],
phone: [{
required: true,
message: '请输入联系方式',
trigger: 'blur'
}],
username: [{
required: true,
message: '请输入登录账号',
trigger: 'blur'
}],
phone: [{
required: true,
trigger: 'blur',
validator: checkPhone
}],
password: [{
required: true,
message: '请输入密码',
trigger: 'blur'
}]
}
}
},
created() {
this.GetUser()
},
methods: {
closeClassDialog() {
this.title = '添加管理员'
this.buttonText = '立即创建'
this.GetUser();
},
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
if (this.title == '添加管理员') {
this.adminUserInfo.addTime = formatTime(new Date(), 'yyyy-MM-dd HH:mm:ss')
AccountRegister(this.adminUserInfo).then(res => {
this.$notify({
title: '成功',
message: res.data.message,
type: 'success'
});
// this.$confirm(res.data.message, '消息')
this.dialogClassIVIsible = false
})
} else {
this.adminUserInfo.updateTime = formatTime(new Date(), 'yyyy-MM-dd HH:mm:ss')
this.adminUserInfo.status = 1
UsersUpdate(this.adminUserInfo).then(res => {
this.$notify({
title: '成功',
message: res.data.message,
type: 'success'
});
// this.$confirm(res.data.message, '消息')
this.dialogClassIVIsible = false
})
}
} else {
return false;
}
});
},
GetUser() {
GetUserListByAdmin(this.query).then(res => {
this.userList = res.data.data.rows.map(t => {
if (t.phone) {
t.phone1 = t.phone.replace(t.phone.substring(3, 7), '****')
}
return t
})
this.Count = res.data.data.total
console.log(this.userList)
})
},
currentchange(page) {
this.query.PageIndex = page;
this.GetUser();
},
closeClassDialogT(){
this.dialogClassIVIsibleT=false
},
submitFormT(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
UpdateCurrentPasswordById({UserId:this.ruleForm.UserId,Password:this.ruleForm.Password}).then(res=>{
if (res.data.code==200) {
this.$notify({
title: 'Success',
message: res.data.message,
type: 'success',
duration: 1000
})
this.dialogClassIVIsibleT=false
// setTimeout(()=>{
// this.$store.dispatch('user/logout')
// this.$router.push(`/login?redirect=${this.$route.fullPath}`)
// },1000)
}
})
} else {
console.log('error submit!!');
return false;
}
});
},
resetForm(formName) {
this.$refs[formName].resetFields();
},
handleCommand(value, val) {
let that = this;
if (value == "update") {
this.dialogClassIVIsible = true;
this.adminUserInfo = val
this.title = '编辑信息'
this.buttonText = '保存'
}
if(value=='updatePassword'){
this.ruleForm.UserId=val.id
this.dialogClassIVIsibleT=true
}
if (value == "del") {
this.$confirm('确定删除该管理员?', '消息', {
confirmButtonText: '确认',
cancelButtonText: '取消',
callback: (action) => {
if (action == "confirm") {
UsersDelete({
ids: val.id
}).then(res => {
if (res.data.code == 200) {
this.$notify({
title: '成功',
message: res.data.message,
type: 'success'
});
this.GetUser();
}
});
}
},
})
}
},
}
}
</script>
<style scoped>
.seetingsDiv {
width: 100%;
height: 60px;
background: #efefef;
border-radius: 5px;
box-shadow: 0 0 5px #cdcdcd;
}
.seetingsDiv button {
background-color: #304156;
border: 0px;
margin-left: 10px;
box-shadow: 0 0 5px #cdcdcd;
float: left;
margin-top: 12px;
margin-right: 10px;
}
</style>