|
|
1
|
+<template>
|
|
|
2
|
+ <section>
|
|
|
3
|
+ <!--工具条-->
|
|
|
4
|
+ <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
|
|
|
5
|
+ <el-form :inline="true" :model="filters">
|
|
|
6
|
+ <el-form-item>
|
|
|
7
|
+ <el-input v-model="filters.account" placeholder="姓名"></el-input>
|
|
|
8
|
+ </el-form-item>
|
|
|
9
|
+ <el-form-item>
|
|
|
10
|
+ <el-input v-model="filters.name" placeholder="账号"></el-input>
|
|
|
11
|
+ </el-form-item>
|
|
|
12
|
+ <el-form-item>
|
|
|
13
|
+ <el-button type="primary" v-on:click="getUsers">查询</el-button>
|
|
|
14
|
+ </el-form-item>
|
|
|
15
|
+ </el-form>
|
|
|
16
|
+ </el-col>
|
|
|
17
|
+
|
|
|
18
|
+ <!--列表-->
|
|
|
19
|
+ <el-table :data="users" highlight-current-row border v-loading="listLoading" @selection-change="selsChange"
|
|
|
20
|
+ style="width: 100%;">
|
|
|
21
|
+ <el-table-column type="selection" width="55" align="center">
|
|
|
22
|
+ </el-table-column>
|
|
|
23
|
+ <!--<el-table-column type="index" width="60">-->
|
|
|
24
|
+ <!--</el-table-column>-->
|
|
|
25
|
+ <el-table-column prop="id" label="ID" width="100" align="center" sortable>
|
|
|
26
|
+ </el-table-column>
|
|
|
27
|
+ <el-table-column prop="account" label="账号" width="120" align="center" sortable>
|
|
|
28
|
+ </el-table-column>
|
|
|
29
|
+ <el-table-column prop="name" label="姓名" width="120" align="center" sortable>
|
|
|
30
|
+ </el-table-column>
|
|
|
31
|
+ <el-table-column prop="sex" label="性别" width="100" :formatter="formatSex" align="center" sortable>
|
|
|
32
|
+ </el-table-column>
|
|
|
33
|
+ <el-table-column prop="phone" label="电话" width="130" align="center">
|
|
|
34
|
+ </el-table-column>
|
|
|
35
|
+ <el-table-column prop="createTime" label="创建时间" width="175" align="center" sortable>
|
|
|
36
|
+ </el-table-column>
|
|
|
37
|
+ <el-table-column prop="status" label="启用" width="100" :formatter="formatState" align="center" sortable>
|
|
|
38
|
+ </el-table-column>
|
|
|
39
|
+ </el-table>
|
|
|
40
|
+
|
|
|
41
|
+ <!--工具条-->
|
|
|
42
|
+ <el-col :span="24" class="toolbar">
|
|
|
43
|
+ <el-pagination layout="total, prev, pager, next" @current-change="handleCurrentChange" :page-size="10"
|
|
|
44
|
+ :total="total" style="float:right;">
|
|
|
45
|
+ </el-pagination>
|
|
|
46
|
+ </el-col>
|
|
|
47
|
+ </section>
|
|
|
48
|
+</template>
|
|
|
49
|
+
|
|
|
50
|
+<script>
|
|
|
51
|
+ import util from '../../common/js/util'
|
|
|
52
|
+ import NProgress from 'nprogress'
|
|
|
53
|
+ import {getUserList, removeUser, batchRemoveUser, editUser, addUser, setUserRole} from 'api/user';
|
|
|
54
|
+ import {getList} from '../../api/role_api';
|
|
|
55
|
+ import moment from 'moment'
|
|
|
56
|
+ import {getServerAndHostList, insertUserInfo} from "../../api/message_bus";
|
|
|
57
|
+
|
|
|
58
|
+ export default {
|
|
|
59
|
+ name:"UserList",
|
|
|
60
|
+ data() {
|
|
|
61
|
+ return {
|
|
|
62
|
+ user_config: {
|
|
|
63
|
+ server_hostList: [],
|
|
|
64
|
+ defaultParams: {
|
|
|
65
|
+ label: 'aliasName',
|
|
|
66
|
+ children: 'aliasList'
|
|
|
67
|
+ }
|
|
|
68
|
+ },
|
|
|
69
|
+ filters: {
|
|
|
70
|
+ account: '',
|
|
|
71
|
+ name: ''
|
|
|
72
|
+ },
|
|
|
73
|
+ treeDefaultProps: {
|
|
|
74
|
+ children: 'children',
|
|
|
75
|
+ label: 'roleName',
|
|
|
76
|
+ },
|
|
|
77
|
+ users: [],
|
|
|
78
|
+ total: 0,
|
|
|
79
|
+ pageNum: 1,
|
|
|
80
|
+ pageSize: 10,
|
|
|
81
|
+ faceImageUrl: '',
|
|
|
82
|
+ listLoading: false,
|
|
|
83
|
+ sels: [],//列表选中列
|
|
|
84
|
+ //编辑界面是否显示
|
|
|
85
|
+ editFormVisible: false,
|
|
|
86
|
+ editLoading: false,
|
|
|
87
|
+ editFormRules: {
|
|
|
88
|
+ name: [
|
|
|
89
|
+ {required: true, message: '请输入姓名', trigger: 'blur'}
|
|
|
90
|
+ ],
|
|
|
91
|
+ mobilephone: [
|
|
|
92
|
+ {required: true, message: '请输入手机号码', trigger: ['blur', 'change']}
|
|
|
93
|
+ ]
|
|
|
94
|
+ },
|
|
|
95
|
+ //编辑界面数据
|
|
|
96
|
+ editForm: {
|
|
|
97
|
+ userId: 1,
|
|
|
98
|
+ username: '',
|
|
|
99
|
+ password: '',
|
|
|
100
|
+ sex: '1',
|
|
|
101
|
+ creattime: undefined,
|
|
|
102
|
+ address: '',
|
|
|
103
|
+ realname: '',
|
|
|
104
|
+ email: '',
|
|
|
105
|
+ mobilephone: '',
|
|
|
106
|
+ state: true
|
|
|
107
|
+ },
|
|
|
108
|
+
|
|
|
109
|
+ addFormVisible: false,//新增界面是否显示
|
|
|
110
|
+ addLoading: false,
|
|
|
111
|
+ addFormRules: {
|
|
|
112
|
+ username: [
|
|
|
113
|
+ {required: true, message: '请输入姓名,用户名长度在5-11位,支持英文和数字', trigger: 'blur'},
|
|
|
114
|
+ ],
|
|
|
115
|
+ password: [
|
|
|
116
|
+ {required: true, message: '请输入密码,用户名长度在6-18位,支持英文和数字和非空字符', trigger: 'blur'}
|
|
|
117
|
+ ],
|
|
|
118
|
+ mobilephone: [
|
|
|
119
|
+ {required: true, message: '请输入手机号码', trigger: ['blur', 'change']},
|
|
|
120
|
+ ],
|
|
|
121
|
+ virtualHostId: [
|
|
|
122
|
+ {required: true, message: '请选择虚拟主机', trigger: ['blur', 'change']},
|
|
|
123
|
+ ],
|
|
|
124
|
+ serverId: [
|
|
|
125
|
+ {required: true, message: '请选择服务器', trigger: ['blur', 'change']},
|
|
|
126
|
+ ],
|
|
|
127
|
+ },
|
|
|
128
|
+ //用户角色配置
|
|
|
129
|
+ roleFormVisible: false,
|
|
|
130
|
+ //新增界面数据
|
|
|
131
|
+ addForm: {
|
|
|
132
|
+ username: '',
|
|
|
133
|
+ password: '',
|
|
|
134
|
+ sex: 1,
|
|
|
135
|
+ address: '',
|
|
|
136
|
+ realname: '',
|
|
|
137
|
+ email: '',
|
|
|
138
|
+ mobilephone: '',
|
|
|
139
|
+ age: 1,
|
|
|
140
|
+ virtualHostId: '',
|
|
|
141
|
+ serverId: '',
|
|
|
142
|
+ },
|
|
|
143
|
+ roleEditForm: {
|
|
|
144
|
+ userId: 1,
|
|
|
145
|
+ username: "",
|
|
|
146
|
+ roles: []
|
|
|
147
|
+ },
|
|
|
148
|
+ roles: [],
|
|
|
149
|
+ roleIds: []
|
|
|
150
|
+
|
|
|
151
|
+ }
|
|
|
152
|
+ },
|
|
|
153
|
+ methods: {
|
|
|
154
|
+ // 性别显示转换
|
|
|
155
|
+ formatSex: function (row, column) {
|
|
|
156
|
+ return row.sex == 1 ? '男' : row.sex == 0 ? '女' : '未知';
|
|
|
157
|
+ },
|
|
|
158
|
+ formatState: function (row, column) {
|
|
|
159
|
+ return row.state == true ? '是' : row.state == false ? '否' : '未知';
|
|
|
160
|
+ },
|
|
|
161
|
+ handleCurrentChange(val) {
|
|
|
162
|
+ this.pageNum = val;
|
|
|
163
|
+ this.getUsers();
|
|
|
164
|
+ },
|
|
|
165
|
+ // 获取用户列表
|
|
|
166
|
+ getUsers: function () {
|
|
|
167
|
+ let para = {
|
|
|
168
|
+ pageNo: this.pageNum,
|
|
|
169
|
+ pageSize: this.pageSize,
|
|
|
170
|
+ account: this.filters.account,
|
|
|
171
|
+ name: this.filters.name
|
|
|
172
|
+ };
|
|
|
173
|
+ this.listLoading = true;
|
|
|
174
|
+ getUserList(para).then((res) => {
|
|
|
175
|
+ let response = res.data;
|
|
|
176
|
+ this.total = response.totalCount;
|
|
|
177
|
+ this.users = response.data;
|
|
|
178
|
+ this.listLoading = false;
|
|
|
179
|
+ //NProgress.done();
|
|
|
180
|
+ }).catch((error) => {
|
|
|
181
|
+ this.listLoading = false;
|
|
|
182
|
+ this.$message.error(error.toString());
|
|
|
183
|
+ });
|
|
|
184
|
+
|
|
|
185
|
+ },
|
|
|
186
|
+ //删除
|
|
|
187
|
+ handleDel: function (index, row) {
|
|
|
188
|
+ this.$confirm('确认删除该记录吗?', '提示', {
|
|
|
189
|
+ type: 'warning'
|
|
|
190
|
+ }).then(() => {
|
|
|
191
|
+ this.listLoading = true;
|
|
|
192
|
+ //NProgress.start();
|
|
|
193
|
+ let para = {userId: row.userId};
|
|
|
194
|
+ removeUser(para).then((res) => {
|
|
|
195
|
+ this.listLoading = false;
|
|
|
196
|
+ //NProgress.done();
|
|
|
197
|
+ this.$message({
|
|
|
198
|
+ message: '删除成功',
|
|
|
199
|
+ type: 'success'
|
|
|
200
|
+ });
|
|
|
201
|
+ this.getUsers();
|
|
|
202
|
+ }).catch((error) => {
|
|
|
203
|
+ this.listLoading = false;
|
|
|
204
|
+ alert(error);
|
|
|
205
|
+ });
|
|
|
206
|
+ }).catch();
|
|
|
207
|
+ },
|
|
|
208
|
+ /**
|
|
|
209
|
+ * 显示编辑界面
|
|
|
210
|
+ * @param index
|
|
|
211
|
+ * @param row 为这行的数据对象
|
|
|
212
|
+ */
|
|
|
213
|
+ handleEdit: function (index, row) {
|
|
|
214
|
+ this.editFormVisible = true;
|
|
|
215
|
+ this.editForm = Object.assign({}, row);
|
|
|
216
|
+ },
|
|
|
217
|
+ roleEdit: function (index, row) {
|
|
|
218
|
+ this.roleFormVisible = true;
|
|
|
219
|
+ this.getRoles();
|
|
|
220
|
+ var _this = this;
|
|
|
221
|
+ _this.roleIds = [];
|
|
|
222
|
+ this.roleEditForm = Object.assign({}, row);
|
|
|
223
|
+ let roles = this.roleEditForm.roles;
|
|
|
224
|
+
|
|
|
225
|
+ if (util.checkNull(roles)) {
|
|
|
226
|
+ roles.forEach(function (role, v_index, v_arr) {
|
|
|
227
|
+ if (util.checkNull(role)) {
|
|
|
228
|
+ _this.roleIds[v_index] = role.roleId;
|
|
|
229
|
+ }
|
|
|
230
|
+ });
|
|
|
231
|
+ }
|
|
|
232
|
+ this.$nextTick(() => {
|
|
|
233
|
+ //反向适配
|
|
|
234
|
+ this.$refs.tree.setCheckedKeys(this.roleIds);
|
|
|
235
|
+ });
|
|
|
236
|
+ },
|
|
|
237
|
+ getRoles() {
|
|
|
238
|
+ let para = {
|
|
|
239
|
+ pageNum: 1,
|
|
|
240
|
+ pageSize: 100
|
|
|
241
|
+ };
|
|
|
242
|
+ NProgress.start();
|
|
|
243
|
+ getList(para).then((res) => {
|
|
|
244
|
+ this.roles = res.data.list;
|
|
|
245
|
+ NProgress.done();
|
|
|
246
|
+ }).catch((error) => {
|
|
|
247
|
+ if (null != error.response && error.response !== undefined) {
|
|
|
248
|
+ let status = error.response.status;
|
|
|
249
|
+ let msg = error.response.statusText;
|
|
|
250
|
+ alert(status + msg);
|
|
|
251
|
+ } else {
|
|
|
252
|
+ alert(error);
|
|
|
253
|
+ }
|
|
|
254
|
+ });
|
|
|
255
|
+
|
|
|
256
|
+
|
|
|
257
|
+ },
|
|
|
258
|
+ //显示新增界面,每次点开初始化数据
|
|
|
259
|
+ handleAdd: function () {
|
|
|
260
|
+ this.addFormVisible = true;
|
|
|
261
|
+ this.addForm = {
|
|
|
262
|
+ username: '',
|
|
|
263
|
+ password: '',
|
|
|
264
|
+ sex: 1,
|
|
|
265
|
+ address: '',
|
|
|
266
|
+ realname: '',
|
|
|
267
|
+ email: '',
|
|
|
268
|
+ mobilephone: '',
|
|
|
269
|
+ age: 1,
|
|
|
270
|
+ virtualHostId: '',
|
|
|
271
|
+ serverId: '',
|
|
|
272
|
+ };
|
|
|
273
|
+ },
|
|
|
274
|
+ //编辑
|
|
|
275
|
+ editSubmit: function () {
|
|
|
276
|
+ this.$refs.editForm.validate((valid) => {
|
|
|
277
|
+ if (valid) {
|
|
|
278
|
+ this.$confirm('确认提交吗?', '提示', {}).then(() => {
|
|
|
279
|
+ this.editLoading = true;
|
|
|
280
|
+ //NProgress.start();
|
|
|
281
|
+ // let para = Object.assign({}, this.editForm);
|
|
|
282
|
+ //不需要提交的 去掉,后端不好接收
|
|
|
283
|
+ this.editForm.authorities = null;
|
|
|
284
|
+ this.editForm.permissions = null;
|
|
|
285
|
+ this.editForm.roles = null;
|
|
|
286
|
+// para.birth = (!para.birth || para.birth == '') ? '' : util.formatDate.format(new Date(para.birth), 'yyyy-MM-dd');
|
|
|
287
|
+ /*
|
|
|
288
|
+ 查询之后格式this.filters.column.create_start_date中日期发生变化;
|
|
|
289
|
+ Wed Aug 09 2017 00:00:00 GMT+0800 (中国标准时间) 变成了 "2017-08-08T16:00:00.000Z";
|
|
|
290
|
+ 所以使用 moment 日期格式化插件将时间转换成 [ Wed Aug 09 2017 00:00:00 GMT+0800 (中国标准时间) ] 格
|
|
|
291
|
+ 式;
|
|
|
292
|
+ */
|
|
|
293
|
+ /*moment 安装 npm install moment --save*/
|
|
|
294
|
+// para.creattime = moment(para.creattime).format('YYYY-MM-DD HH:mm:ss');
|
|
|
295
|
+ this.editLoading = false;
|
|
|
296
|
+ editUser(this.editForm).then((res) => {
|
|
|
297
|
+
|
|
|
298
|
+ //NProgress.done();
|
|
|
299
|
+ this.$message({
|
|
|
300
|
+ message: '提交成功',
|
|
|
301
|
+ type: 'success'
|
|
|
302
|
+ });
|
|
|
303
|
+ this.$refs['editForm'].resetFields();
|
|
|
304
|
+ this.editFormVisible = false;
|
|
|
305
|
+ this.getUsers();
|
|
|
306
|
+ }).catch(error => alert(error));
|
|
|
307
|
+ });
|
|
|
308
|
+ }
|
|
|
309
|
+ });
|
|
|
310
|
+ },
|
|
|
311
|
+ //新增
|
|
|
312
|
+ addSubmit: function () {
|
|
|
313
|
+ this.$refs.addForm.validate((valid) => {
|
|
|
314
|
+ if (valid) {
|
|
|
315
|
+ this.$confirm('确认提交吗?', '提示', {}).then(() => {
|
|
|
316
|
+ this.addLoading = true;
|
|
|
317
|
+ let para = Object.assign({}, this.addForm);
|
|
|
318
|
+// para.birth = (!para.birth || para.birth == '') ? '' : util.formatDate.format(new Date(para.birth), 'yyyy-MM-dd');
|
|
|
319
|
+
|
|
|
320
|
+ // 添加MQ用户信息
|
|
|
321
|
+ this.addForm.virtualHostId = this.$refs.tree.getCheckedKeys().join();
|
|
|
322
|
+ const params = {
|
|
|
323
|
+ username: this.addForm.username,
|
|
|
324
|
+ password: this.addForm.password,
|
|
|
325
|
+ realName: this.addForm.realname,
|
|
|
326
|
+ virtualHostId: this.addForm.virtualHostId,
|
|
|
327
|
+ }
|
|
|
328
|
+ insertUserInfo(params).then((response) => {
|
|
|
329
|
+ let res = response.data;
|
|
|
330
|
+ // 添加失败
|
|
|
331
|
+ if (res.code !== '200') {
|
|
|
332
|
+ return this.$message.error("MQ:" + res.msg);
|
|
|
333
|
+ }
|
|
|
334
|
+ // 添加,成功
|
|
|
335
|
+ this.$message.success('添加MQ用戶信息,成功');
|
|
|
336
|
+ }).catch(error => {
|
|
|
337
|
+ this.$message.error(error.toString());
|
|
|
338
|
+ });
|
|
|
339
|
+
|
|
|
340
|
+ addUser(para).then((res) => {
|
|
|
341
|
+ this.addLoading = false;
|
|
|
342
|
+ //NProgress.done();
|
|
|
343
|
+ this.$message({
|
|
|
344
|
+ message: '提交成功',
|
|
|
345
|
+ type: 'success'
|
|
|
346
|
+ });
|
|
|
347
|
+ this.$refs['addForm'].resetFields();
|
|
|
348
|
+ this.addFormVisible = false;
|
|
|
349
|
+ this.getUsers();
|
|
|
350
|
+ }).catch(error => {
|
|
|
351
|
+ this.addLoading = false;
|
|
|
352
|
+ this.$message({
|
|
|
353
|
+ message: error.message,
|
|
|
354
|
+ type: 'error'
|
|
|
355
|
+ });
|
|
|
356
|
+ });
|
|
|
357
|
+
|
|
|
358
|
+ });
|
|
|
359
|
+ }
|
|
|
360
|
+ });
|
|
|
361
|
+ },
|
|
|
362
|
+ selsChange: function (sels) {
|
|
|
363
|
+ //传递给父组件
|
|
|
364
|
+ this.$emit("getUserMessageEvent",sels);
|
|
|
365
|
+ this.sels = sels;
|
|
|
366
|
+ },
|
|
|
367
|
+ //批量删除
|
|
|
368
|
+ batchRemove: function () {
|
|
|
369
|
+ var ids = this.sels.map(item => item.userId).toString();
|
|
|
370
|
+ this.$confirm('确认删除选中记录吗?', '提示', {
|
|
|
371
|
+ type: 'warning'
|
|
|
372
|
+ }).then(() => {
|
|
|
373
|
+ this.listLoading = true;
|
|
|
374
|
+ //NProgress.start();
|
|
|
375
|
+ let para = {ids: ids};
|
|
|
376
|
+ batchRemoveUser(para).then((res) => {
|
|
|
377
|
+ this.listLoading = false;
|
|
|
378
|
+ //NProgress.done();
|
|
|
379
|
+ this.$message({
|
|
|
380
|
+ message: '删除成功',
|
|
|
381
|
+ type: 'success'
|
|
|
382
|
+ });
|
|
|
383
|
+ this.getUsers();
|
|
|
384
|
+ });
|
|
|
385
|
+ }).catch(() => {
|
|
|
386
|
+
|
|
|
387
|
+ });
|
|
|
388
|
+ },
|
|
|
389
|
+ roleEditSubmit: function () {
|
|
|
390
|
+ this.$confirm('确认提交吗?', '提示', {}).then(() => {
|
|
|
391
|
+// this.editLoading = true;
|
|
|
392
|
+ let userId = this.roleEditForm.userId;
|
|
|
393
|
+ let roleIds = this.$refs.tree.getCheckedKeys();
|
|
|
394
|
+ let para = {userId, roleIds};
|
|
|
395
|
+ setUserRole(para).then((res) => {
|
|
|
396
|
+ if (res.status === 200) {
|
|
|
397
|
+ this.$message({
|
|
|
398
|
+ message: '岗位设置成功',
|
|
|
399
|
+ type: 'success'
|
|
|
400
|
+ });
|
|
|
401
|
+ }
|
|
|
402
|
+ this.getUsers();
|
|
|
403
|
+ this.roleFormVisible = false;
|
|
|
404
|
+ }).catch(err => {
|
|
|
405
|
+ alert(err);
|
|
|
406
|
+ });
|
|
|
407
|
+ console.log(para);
|
|
|
408
|
+ });
|
|
|
409
|
+ },
|
|
|
410
|
+ handleAvatarSuccess: function (response) {
|
|
|
411
|
+ this.faceImageUrl = 'http://127.0.0.1:7003/' + response.data;
|
|
|
412
|
+ },
|
|
|
413
|
+ beforeAvatarUpload: function () {
|
|
|
414
|
+
|
|
|
415
|
+ },
|
|
|
416
|
+ treeHandleCheckChange: function (data, checked, indeterminate) {
|
|
|
417
|
+ if (checked) {
|
|
|
418
|
+ this.roleIds.push(data.roleId);
|
|
|
419
|
+ } else {
|
|
|
420
|
+ this.roleIds.splice(this.roleIds.contains(data.roleId), 1);
|
|
|
421
|
+ }
|
|
|
422
|
+// console.log(data, checked, indeterminate);
|
|
|
423
|
+ console.log(this.roleIds);
|
|
|
424
|
+ },
|
|
|
425
|
+
|
|
|
426
|
+ /**
|
|
|
427
|
+ * 选择用户关系
|
|
|
428
|
+ * MQ服务器与虚拟主机(1:n)的列表
|
|
|
429
|
+ */
|
|
|
430
|
+ selectUserRelation() {
|
|
|
431
|
+ getServerAndHostList().then((response) => {
|
|
|
432
|
+ let res = response.data;
|
|
|
433
|
+ if (res.code !== '200') {
|
|
|
434
|
+ return this.$message.error('获取服务器与虚拟主机信息,失败!');
|
|
|
435
|
+ }
|
|
|
436
|
+ // 获取列表数据
|
|
|
437
|
+ this.user_config.server_hostList = res.data;
|
|
|
438
|
+ }).catch(error => {
|
|
|
439
|
+ this.$message.error(error.toString());
|
|
|
440
|
+ });
|
|
|
441
|
+ },
|
|
|
442
|
+
|
|
|
443
|
+ },
|
|
|
444
|
+ mounted() {
|
|
|
445
|
+ this.getUsers();
|
|
|
446
|
+ this.selectUserRelation();
|
|
|
447
|
+ },
|
|
|
448
|
+ computed: {
|
|
|
449
|
+ hideShow() {//当图片多于一张的时候,就隐藏上传框
|
|
|
450
|
+ return this.file === '' ? false : true
|
|
|
451
|
+ }
|
|
|
452
|
+ },
|
|
|
453
|
+ }
|
|
|
454
|
+
|
|
|
455
|
+</script>
|
|
|
456
|
+
|
|
|
457
|
+<style scoped>
|
|
|
458
|
+
|
|
|
459
|
+</style> |