matched.js
25.1 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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
import React from "react";
import { Form, Table, Input, Select, Button, Row, Col, Icon, Modal ,message,Tooltip } from "antd";
import UserManageBar from '../../../components/Common/WhiteBar/index';
import OrgOptionsForm from '@components/Common/OrgOptions/index';
import './index.less';
import { API_ROLE_MANAGE, API_CHANNEL_MANAGE, API_SYSORORG_MANAGE ,} from '@src/Api';
import Utils from '@src/utils/utils';
import axios from '@src/axios/index';
import storage from '@src/utils/localStorage'
class RoleManageAdd extends React.Component {
constructor (props) {
super(props);
this.state = {
// 添加用户弹框
visible: false,
// 用户列表数据
list: [],
pagination: '',
isLoading: true, // 是否正在加载
// 角色信息
userInfo: '',
role: '',
// 渠道信息
channelList: [],
channelObj: {},
// 机构
orgOptionsArr: [],
getOrgOptionsName: {},
agency: '机构',
// 要从角色里删除的用户
selectDelUser: [],
selectedRowKeys: [],
// 搜索条件
searchData: {},
expandStatus: false,
btnAuth: null,
isShowOpt: true
};
}
params = {
page: 1,
pageSize: 10
};
componentWillMount() {
const btnAuth = storage.get('btnAuth')
this.setState({btnAuth})
if(
btnAuth.indexOf('cancelUserAuthor') === -1){
this.setState({isShowOpt: false})
}
}
componentDidMount () {
this.getRouterParams();
this.getChannelAll();
}
// 获取渠道
getChannelAll = () => {
axios.ajax({
url: API_CHANNEL_MANAGE.getParamChannel,
data: {
pageNum: 1,
pageSize: 100
}
}).then(res => {
res = res.records;
this.setState({channelList: res});
// 转换渠道对象
let channelObj = {};
channelObj[0]="其他"
res.forEach((item) => {
channelObj[item.channelId] = item.name;
});
this.setState({channelObj: channelObj});
// 加载机构列表
this.getOrgTreeList();
})
}
// 获取机构列表
getOrgTreeList = () => {
return new Promise((resolve, reject) => {
axios.ajax({
url: API_SYSORORG_MANAGE.getOrgTreeList,
}).then(res => {
if (res && res.length > 0) {
this.setState({
orgOptionsArr: res
})
resolve(this.getOrgOptionsName(res))
// 加载列表数据
this.getRoleUser();
} else {
return
}
})
})
}
// 列表扁平化
getOrgOptionsName = (data) => {
const { getOrgOptionsName } = this.state;
let that = this;
if (data && data.length > 0) {
data.map(item => {
let id = item.id, name = item.name
if (item.childOrgs && item.childOrgs.length > 0) {
that.getOrgOptionsName(item.childOrgs)
}
Object.assign(getOrgOptionsName, { [id]: name })
})
}
return getOrgOptionsName
}
// 查询用户信息
search = (searchData) => {
this.setState({searchData}, () => {
this.params.page = 1;
this.getRoleUser();
// Utils.trim(searchData)
});
}
// 重置
reset = () => {
this.setState({searchData: {}}, () => {
this.params.page = 1;
this.getRoleUser();
});
}
//获取路由参数及用户id
getRouterParams() {
const params = this.props.match.params;
// const { uid } = this.props.location;
this.setState({userInfo:params,role:params.role});
}
// 加载角色用户
getRoleUser = () => {
var searchData = this.state.searchData;
// 开启加载动画
this.setState({isLoading: true});
let _this = this;
axios.ajax({
url: API_ROLE_MANAGE.getRoleGiveUser,
data: {
...searchData,
roleId: this.state.userInfo.uid,
pageNum: this.params.page,
pageSize: this.params.pageSize
}
}).then(res => {
if (res.records.length == 0 && this.params.page > 1) {
this.params.page = this.params.page - 1;
this.getRoleUser();
return;
}
// 关闭加载动画
this.setState({isLoading: false});
// 添加key属性
let keyList = res.records.map((item) => {
return {key: item.uid, ...item};
});
console.log(keyList);
this.setState({
list: keyList,
pagination: Utils.pagination(res, (current) => {
_this.params.page = current;
this.getRoleUser();
})
});
})
}
// 跳转到添加用户页
addUser = () => {
this.props.history.push({
pathname: `/home/permission/role/matchedAdd/${this.state.userInfo.uid}/${this.state.userInfo.role}`
});
}
// 返回到上级
toBack = () => {
this.props.history.push({
pathname: '/home/permission/role'
});
}
// 单行取消用户授权
handleDelete = (item,uid,loginName) => {
let _this = this;
Modal.confirm({
title: `是否取消对账号:${loginName}的授权?`,
cancelText: '取消',
okText: '确定',
onOk () {
let userIdList = [];
userIdList.push(uid);
_this.deleteRole(userIdList);
},
onCancel () {}
});
}
// 批量取消用户授权
cancelRole = () => {
let _this = this;
// 进行提交前判断
if (this.state.selectedRowKeys.length == 0) {
message.warn('请先选择取消的用户');
return false;
}
Modal.confirm({
title: `您是否确定要取消选中的用户?`,
cancelText: '取消',
okText: '确定',
onOk () {
_this.deleteRole(_this.state.selectedRowKeys);
},
onCancel () {}
});
// this.deleteRole(this.state.selectedRowKeys);
}
// 取消角色授权
deleteRole = (userIdList) => {
const roleId = this.state.userInfo.uid;
axios.ajax({
url: API_ROLE_MANAGE.deleteByRoleIdBatchUser,
data: {
roleId: roleId,
userIdList: userIdList
}
}).then((res) => {
if (res === true) {
// 成功
message.success('成功取消角色授权');
// 清空选择框
this.setState({selectedRowKeys: []});
this.getRoleUser();
} else {
message.warn('取消角色授权失败');
}
});
}
// 表格行点击事件
onRowClick = (record,index) => {
let newKey = record.uid;
let newKeyIndex = this.state.selectedRowKeys.findIndex((value) => {
return value == newKey;
});
if (newKeyIndex == -1) {
// 没有选中 进行选中
let selectedRowKeys = [...this.state.selectedRowKeys,newKey];
this.setState({selectedRowKeys});
} else {
// 已经选中进行取消
let selectedRowKeys = [...this.state.selectedRowKeys];
selectedRowKeys.splice(newKeyIndex,1);
this.setState({selectedRowKeys});
}
}
// 对名字判断过长时进行截取处理
judgeStr (str) {
if (str.length >= 8) {
return (<Tooltip style={{maxWidth: 100}} placement="bottom" content={str}>{str.slice(0,8) + '...'}</Tooltip>)
} else {
return str;
}
}
// 展开条件
expandMenu = ()=> {
this.setState({
expandStatus: !this.state.expandStatus,
})
}
render () {
const { channelObj,getOrgOptionsName,selectedRowKeys } = this.state;
// 表格配置
const columns = [
{
title: '账号',
key: 'loginName',
dataIndex: 'loginName',
maxWidth: 100,
className: 'tdWidth',
render(loginName) {
return Utils.formatTableColumn(loginName)
}
},
{
title: '姓名',
key: 'userName',
dataIndex: 'userName',
maxWidth: 100,
className: 'tdWidth',
render(userName) {
return Utils.formatTableColumn(userName)
}
},
{
title: '机构名称',
key: 'orgId',
dataIndex: 'orgId',
className: 'tdWidth',
render(orgId) {
return Utils.formatTableColumn(getOrgOptionsName[orgId])
}
},
{
title: '所属渠道',
key: 'channelId',
dataIndex: 'channelId',
render: (channelId) => {
return channelObj[channelId];
}
},
{
title: '在职状态',
key: 'jobStatus',
dataIndex: 'jobStatus',
render: (jobStatus) => {
return {
0: <div>其他</div>,
1: <div style={{color:'#00BB29'}}>在职</div>,
2: <div style={{color:'#ED1719'}}>离职</div>,
3: <div style={{color:'#F0B856'}}>暂离</div>
}[jobStatus];
}
},
{
title: '账户状态',
key: 'status',
dataIndex: 'status',
render: (status) => {
return {
0: <div>其他</div>,
1: <div>未激活</div> ,
2: <div style={{color:'#00BB29'}}>正常</div>,
3: <div style={{color:'#ED1719'}}>禁用</div>,
4: <div style={{color:'#F0B856'}}>锁定</div>
}[status];
}
},
{
title: '创建时间',
key: 'createTime',
dataIndex: 'createTime',
render: (createTime) => {
return Utils.formateDateToYMD(createTime);
}
},
];
if (this.state.isShowOpt) {
columns.push(
{
title: '操作',
key: 'action',
className:'pRight',
align: 'right',
render: (item) => {
let {uid,loginName} = item;
return (
this.state.btnAuth.indexOf('cancelUserAuthor') !== -1 ?
<Button onClick={(item) => {this.handleDelete(item,uid,loginName)}}>取消角色授权</Button>
: ''
);
}
}
)
}
const rowSelection = {
type: 'checkbox',
selectedRowKeys,
onChange: (selectedRowKeys, selectedRows) => {
this.setState({selectedRowKeys});
},
onSelect: (record, selected, selectedRows) => {
// console.log(record);
},
};
return (
<div className="allocatedUser">
<div className="nav">
<a href="#/home/permission/role">角色管理</a> > <a href="#/home/permission/role"> {Utils.formatTableColumn(this.state.role)}角色 </a> > <span className="threeTitle">已分配用户</span>
</div>
<div className="searchWrap">
<UserManageBar title="筛选信息" />
<div className='expandMenu iconfont icon-chazhaobiaodanliebiao' onClick={this.expandMenu} ></div>
{
this.state.expandStatus ?
<div className="userForm-box">
<SearchForm
agency={this.state.agency}
channelList={this.state.channelList}
showAgency={this.showAgency}
search={this.search}
reset={this.reset}
></SearchForm>
</div>
: ''
}
</div>
<div className="btnWrapper">
{
this.state.btnAuth.indexOf('addUserAuthor') !== -1 ?
<Button onClick={this.addUser}>添加用户</Button>
: ''
}
{
this.state.btnAuth.indexOf('batchCancel') !== -1 ?
<Button onClick={this.cancelRole}>批量取消</Button>
: ''
}
<Button onClick={this.toBack}>返回</Button>
</div>
<UserManageBar title="详细数据" />
<div className="detData">
<div style={{ backgroundColor: '#fff', margin: '10px 26px 10px 26px',minHeight:200 }}>
<Table
rowkey= 'uid'
bordered={false}
columns={columns}
rowSelection={rowSelection}
dataSource={this.state.list}
pagination={this.state.pagination}
loading={this.state.isLoading}
onRow={(record, index) => {
return {
onClick: () => {
this.onRowClick(record, index);
}
}
}}
></Table>
</div>
</div>
</div>
);
}
}
// 查询表单组件
const SearchForm = Form.create()(
class extends React.Component {
constructor (props) {
super(props);
this.state = {
// 机构选择框控制
agencyVisible: false,
// 机构对应的key
agencyKey: ''
};
}
// 查询列表
search = () => {
let searchData = this.props.form.getFieldsValue();
if (searchData.orgId) {
searchData.orgId = this.state.agencyKey;
}
this.props.search(searchData);
}
// 重置列表
reset = () => {
this.props.form.resetFields();
this.props.reset();
}
// 机构选择控制
showAgency = () => {
this.setState({agencyVisible: true});
}
closeAgency = () => {
this.setState({agencyVisible: false});
}
setAgency = (agency) => {
this.setState({agencyKey: agency.key});
this.props.form.setFieldsValue({orgId: agency.val});
}
render () {
const FormItem = Form.Item;
const Option = Select.Option;
const { getFieldDecorator } = this.props.form;
return (
<div className="com-searchForm">
<Form layout="vertical" className="userForm">
<Row>
<Col span={5}>
<FormItem label="姓名">
{
getFieldDecorator('userName',{
rules: []
})(<Input type="text" placeholder="姓名" />)
}
</FormItem>
</Col>
<Col span={5}>
<FormItem label="账号">
{
getFieldDecorator('loginName',{
rules: []
})(<Input placeholder="账号" type="text" />)
}
</FormItem>
</Col>
<Col span={5}>
<FormItem label="所属机构">
{
getFieldDecorator('orgId',{
rules: []
})(<Input disabled placeholder="所属机构" type="text" />)
}
</FormItem>
</Col>
<Col span={5}>
<div className="iconstore">
<Icon onClick={this.showAgency} type="appstore" />
</div>
</Col>
</Row>
<Row>
<Col span={5}>
<FormItem label="所属渠道">
{
getFieldDecorator('channelId', {
// initialValue: 1,
rules: []
})(
<Select placeholder="所属渠道">
{
this.props.channelList.map((item) => {
return (
<Option key = {item.channelId} value={item.channelId}>{item.name}</Option>
);
})
}
</Select>
)
}
</FormItem>
</Col>
<Col span={5}>
<FormItem label="在职状态">
{
getFieldDecorator('jobStatus', {
// initialValue: 1,
rules: []
})(
<Select placeholder="在职状态">
<Option value={1}>在职</Option>
<Option value={2}>离职</Option>
<Option value={3}>暂离</Option>
<Option value={0}>其他</Option>
</Select>
)
}
</FormItem>
</Col>
<Col span={5}>
<FormItem label="账户状态">
{
getFieldDecorator('status',{
// initialValue: 1,
rules: []
})(
<Select placeholder="账户状态">
<Option value={1}>未激活</Option>
<Option value={2}>正常</Option>
<Option value={3}>禁用</Option>
<Option value={4}>锁定</Option>
<Option value={0}>其他</Option>
</Select>
)
}
</FormItem>
</Col>
<Col span={5}>
<FormItem className="btnform">
<Button onClick={this.search} className="searchBtn">查询</Button>
<Button onClick={this.reset} className="resetBtn">重置</Button>
</FormItem>
</Col>
</Row>
</Form>
{/* 机构 */}
<Agency
visible={this.state.agencyVisible}
closeAgency = {this.closeAgency}
setAgency = {this.setAgency}>
</Agency>
</div>
);
}
}
);
// 机构查询弹框
class Agency extends React.Component {
constructor (props) {
super(props);
this.state = {
orgOptionsArr: [],
getOrgOptionsName: {},
checkedObj: {}
};
}
componentDidMount () {
// 获取机构列表
this.getOrgTreeList();
}
//根据名称获取机构
getOrgByName = (orgName) => {
axios.ajax({
url: API_SYSORORG_MANAGE.getOrgByName,
data: {
name: orgName
}
}).then(res => {
if (res) {
this.setState({orgOptionsArr: res});
}
})
}
//对机构进行扁平处理
getOrgOptionsName = (data) => {
const { getOrgOptionsName } = this.state;
let that = this;
if (data && data.length > 0) {
data.map(item => {
let id = item.id, name = item.name
if (item.childOrgs && item.childOrgs.length > 0) {
that.getOrgOptionsName(item.childOrgs)
}
Object.assign(getOrgOptionsName, { [id]: name })
})
}
return getOrgOptionsName
}
// 获取树形机构列表
getOrgTreeList = () => {
return new Promise((resolve, reject) => {
axios.ajax({
url: API_SYSORORG_MANAGE.getOrgTreeList,
}).then(res => {
if (res && res.length > 0) {
this.setState({
orgOptionsArr: res
})
resolve(this.getOrgOptionsName(res))
} else {
return
}
})
})
}
getCheckedObj = (obj) => {
this.setState({
checkedObj: obj
})
}
// 关闭机构弹框
onCancel = () => {
this.child.reset();
this.props.closeAgency();
}
//机构弹窗
handleOrgOptions = () => {
const checkedObj = this.state.checkedObj
console.log(checkedObj);
if (Object.keys(checkedObj).length == 0 || !checkedObj) {
message.warn('请选择对应的机构');
return;
} else {
// 把选中机构传递给父组件
this.props.setAgency(checkedObj);
// 关闭弹框
this.onCancel();
}
}
// 重置机构搜索
onRef = (ref) => {
this.child = ref;
}
render () {
return (
<Modal
className="com-agency"
onCancel={this.onCancel}
visible={this.props.visible}
onOk={this.handleOrgOptions}
title="所属机构"
okText="确认"
cancelText="取消"
width={965
}>
{/* 树形控件 */}
<OrgOptionsForm
getOrgByName={(orgName) => this.getOrgByName(orgName)}
getOrgTreeList={this.getOrgTreeList}
orgOptionsArr={this.state.orgOptionsArr}
getCheckedObj={this.getCheckedObj}
onRef={this.onRef}
></OrgOptionsForm>
</Modal>
);
}
}
export default Form.create()(RoleManageAdd);