import React, { PureComponent } from 'react';
import { connect } from 'dva';
import {
Upload,
Icon,
Button,
Col,
Form,
Input,
message,
Modal,
Row,
Tree,
} from 'antd';
import Panel from '../../../components/Panel';
import Grid from '../../../components/Sword/Grid';
import { USER_INIT, USER_LIST, USER_ROLE_GRANT } from '../../../actions/user';
import { resetPassword } from '../../../services/user';
import { tenantMode } from '../../../defaultSettings';
import { getAccessToken, getToken } from '../../../utils/authority';
const FormItem = Form.Item;
const { TreeNode } = Tree;
const { Dragger } = Upload;
@connect(({ user, loading }) => ({
user,
loading: loading.models.user,
}))
@Form.create()
class User extends PureComponent {
state = {
visible: false,
excelVisible: false,
confirmLoading: false,
selectedRows: [],
checkedTreeKeys: [],
params: {},
onReset: () => {},
};
componentWillMount() {
const { dispatch } = this.props;
dispatch(USER_INIT());
}
onSelectRow = rows => {
this.setState({
selectedRows: rows,
});
};
getSelectKeys = () => {
const { selectedRows } = this.state;
return selectedRows.map(row => row.id);
};
// ============ 查询 ===============
handleSearch = params => {
this.setState({ params });
const { dispatch } = this.props;
dispatch(USER_LIST(params));
};
// ============ 处理按钮点击回调事件 ===============
handleBtnCallBack = payload => {
const { btn, keys } = payload;
if (btn.code === 'user_role') {
if (keys.length === 0) {
message.warn('请先选择一条数据!');
return;
}
this.showModal();
return;
}
if (btn.code === 'user_reset') {
if (keys.length === 0) {
message.warn('请先选择一条数据!');
return;
}
Modal.confirm({
title: '重置密码确认',
content: '确定将选择账号密码重置为123456?',
okText: '确定',
okType: 'danger',
cancelText: '取消',
async onOk() {
const response = await resetPassword({ userIds: keys });
if (response.success) {
message.success(response.msg);
} else {
message.error(response.msg || '重置失败');
}
},
onCancel() {},
});
}
};
handleGrant = () => {
const { checkedTreeKeys } = this.state;
const keys = this.getSelectKeys();
this.setState({
confirmLoading: true,
});
const { dispatch } = this.props;
dispatch(
USER_ROLE_GRANT({ userIds: keys, roleIds: checkedTreeKeys.checked }, () => {
this.setState({
visible: false,
confirmLoading: false,
});
message.success('配置成功');
this.setState({
checkedTreeKeys: [],
});
})
);
};
showModal = () => {
this.setState({
visible: true,
});
};
handleCancel = () =>
this.setState({
visible: false,
});
onCheck = checkedTreeKeys => this.setState({ checkedTreeKeys });
renderTreeNodes = data =>
data.map(item => {
if (item.children) {
return (