account.js
3.11 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
import React from 'react';
import { Input, Table, message } from 'antd';
import axios from '../../libs/axios';
import dayjs from 'dayjs';
const { Search } = Input;
class Account extends React.Component {
constructor() {
super();
this.state = {
userList: []
};
this.columns = [
{
title: '账号',
dataIndex: 'name',
key: 'name',
render: (name) => (
<span>{name}@yoho.cn</span>
)
},
{
title: '添加时间',
dataIndex: 'time',
key: 'time',
render: (time) => (
<span>{dayjs(time * 1000).format('YYYY-MM-DD HH:mm:ss')}</span>
)
},
{
title: '操作',
key: 'action',
render: (record) => (
<a onClick={() => this.deleteAccount(record)}>删除</a>
)
},
];
}
componentDidMount() {
return axios.get('/api/passport/account/list').then(res => {
if (res.code !== 200) {
return;
}
if (res.data && res.data.list) {
this.setState({
userList: res.data.list
});
}
});
}
addAccount(user) {
if (!user) {
return;
}
return axios.post('/api/passport/account/add', {
account: user,
needList: true
}).then(res => {
if (res.code !== 200) {
return;
}
if (res.data && res.data.list) {
this.setState({
userList: res.data.list
});
}
if (this.refs.addInput) {
this.refs.addInput.input.handleReset();
}
});
}
deleteAccount(record) {
return axios.post('/api/passport/account/delete', {
id: record._id
}).then(res => {
if (res.code !== 200) {
return;
}
let userList = [];
this.state.userList.forEach(val => {
if (val._id !== record._id) {
userList.push(val);
}
});
this.setState({ userList });
});
}
render() {
return (
<div>
<Search
ref="addInput"
placeholder="请输入OA账号名,多个以逗号分割"
enterButton="添加"
allowClear
onSearch={this.addAccount.bind(this)}
/>
<Table
columns={this.columns}
dataSource={this.state.userList}
rowKey="_id"
size="small"
pagination={false}
bordered
style={{ marginTop: '20px' }}
/>
</div>
)
}
}
export default Account;