mirror of
https://github.com/YMFE/yapi.git
synced 2025-03-13 14:26:50 +08:00
feat: 修改组成员权限的功能
This commit is contained in:
parent
4a181c563a
commit
fdb2e7efc0
@ -5,7 +5,7 @@ import { connect } from 'react-redux';
|
||||
import { Select, Button, Modal, Row, Col, message, Popconfirm } from 'antd';
|
||||
import './MemberList.scss';
|
||||
import { autobind } from 'core-decorators';
|
||||
import { fetchGroupMemberList, fetchGroupMsg, addMember, delMember } from '../../../reducer/modules/group.js'
|
||||
import { fetchGroupMemberList, fetchGroupMsg, addMember, delMember, changeMemberRole } from '../../../reducer/modules/group.js'
|
||||
import UsernameAutoComplete from '../../../components/UsernameAutoComplete/UsernameAutoComplete.js';
|
||||
const Option = Select.Option;
|
||||
|
||||
@ -30,7 +30,8 @@ const arrayAddKey = (arr) => {
|
||||
fetchGroupMemberList,
|
||||
fetchGroupMsg,
|
||||
addMember,
|
||||
delMember
|
||||
delMember,
|
||||
changeMemberRole
|
||||
}
|
||||
)
|
||||
class MemberList extends Component {
|
||||
@ -52,13 +53,10 @@ class MemberList extends Component {
|
||||
fetchGroupMsg: PropTypes.func,
|
||||
addMember: PropTypes.func,
|
||||
delMember: PropTypes.func,
|
||||
changeMemberRole: PropTypes.func,
|
||||
role: PropTypes.string
|
||||
}
|
||||
|
||||
@autobind
|
||||
handleChange(value) {
|
||||
console.log(`selected ${value}`);
|
||||
}
|
||||
|
||||
@autobind
|
||||
showAddMemberModal() {
|
||||
@ -67,6 +65,7 @@ class MemberList extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
// 重新获取列表
|
||||
@autobind
|
||||
reFetchList() {
|
||||
this.props.fetchGroupMemberList(this.props.currGroup._id).then((res) => {
|
||||
@ -77,19 +76,7 @@ class MemberList extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
@autobind
|
||||
deleteConfirm(member_uid) {
|
||||
return () => {
|
||||
const id = this.props.currGroup._id;
|
||||
this.props.delMember({ id, member_uid }).then((res) => {
|
||||
if (!res.payload.data.errcode) {
|
||||
message.success(res.payload.data.errmsg);
|
||||
this.reFetchList(); // 添加成功后重新获取分组成员列表
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 增 - 添加成员
|
||||
@autobind
|
||||
handleOk() {
|
||||
console.log(this.props.currGroup._id, this.state.inputUid);
|
||||
@ -104,21 +91,51 @@ class MemberList extends Component {
|
||||
}
|
||||
});
|
||||
}
|
||||
// 添加成员时 选择新增成员权限
|
||||
@autobind
|
||||
changeNewMemberRole(value) {
|
||||
return () => {
|
||||
console.log(this.props.currGroup._id, value);
|
||||
}
|
||||
}
|
||||
|
||||
// 删 - 删除分组成员
|
||||
@autobind
|
||||
deleteConfirm(member_uid) {
|
||||
return () => {
|
||||
const id = this.props.currGroup._id;
|
||||
this.props.delMember({ id, member_uid }).then((res) => {
|
||||
if (!res.payload.data.errcode) {
|
||||
message.success(res.payload.data.errmsg);
|
||||
this.reFetchList(); // 添加成功后重新获取分组成员列表
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 改 - 修改成员权限
|
||||
@autobind
|
||||
changeUserRole(e) {
|
||||
console.log(e);
|
||||
const id = this.props.currGroup._id;
|
||||
const role = e.split('-')[0];
|
||||
const member_uid = e.split('-')[1];
|
||||
this.props.changeMemberRole({ id, member_uid, role }).then((res) => {
|
||||
if (!res.payload.data.errcode) {
|
||||
message.success(res.payload.data.errmsg);
|
||||
this.reFetchList(); // 添加成功后重新获取分组成员列表
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 关闭模态框
|
||||
@autobind
|
||||
handleCancel() {
|
||||
// 取消模态框的时候重置模态框中的值
|
||||
this.setState({
|
||||
visible: false
|
||||
});
|
||||
}
|
||||
|
||||
@autobind
|
||||
changeMemberRole(value) {
|
||||
return () => {
|
||||
console.log(this.props.currGroup._id, value);
|
||||
}
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (this.props.currGroup !== nextProps.currGroup) {
|
||||
@ -176,9 +193,9 @@ class MemberList extends Component {
|
||||
if (this.state.role === 'owner' || this.state.role === 'admin') {
|
||||
return (
|
||||
<div>
|
||||
<Select defaultValue={record.role} className="select" onChange={this.handleChange}>
|
||||
<Option value="owner">组长</Option>
|
||||
<Option value="dev">开发者</Option>
|
||||
<Select defaultValue={record.role+'-'+record.uid} className="select" onChange={this.changeUserRole}>
|
||||
<Option value={'owner-'+record.uid}>组长</Option>
|
||||
<Option value={'dev-'+record.uid}>开发者</Option>
|
||||
</Select>
|
||||
<Popconfirm placement="topRight" title="你确定要删除吗? " onConfirm={this.deleteConfirm(record.uid)} okText="确定" cancelText="">
|
||||
<Button type="danger" icon="minus" className="btn-danger" />
|
||||
@ -207,7 +224,7 @@ class MemberList extends Component {
|
||||
<Row gutter={6} className="modal-input">
|
||||
<Col span="5"><div className="label">权限: </div></Col>
|
||||
<Col span="15">
|
||||
<Select size="large" defaultValue="dev" className="select" onChange={this.changeMemberRole}>
|
||||
<Select size="large" defaultValue="dev" className="select" onChange={this.changeNewMemberRole}>
|
||||
<Option value="owner">组长</Option>
|
||||
<Option value="dev">开发者</Option>
|
||||
</Select>
|
||||
|
@ -7,6 +7,7 @@ const FETCH_GROUP_MEMBER = 'yapi/group/FETCH_GROUP_MEMBER';
|
||||
const FETCH_GROUP_MSG = 'yapi/group/FETCH_GROUP_MSG';
|
||||
const ADD_GROUP_MEMBER = 'yapi/group/ADD_GROUP_MEMBER';
|
||||
const DEL_GROUP_MEMBER = 'yapi/group/DEL_GROUP_MEMBER';
|
||||
const CHANGE_GROUP_MEMBER = 'yapi/group/CHANGE_GROUP_MEMBER';
|
||||
|
||||
// Reducer
|
||||
const initialState = {
|
||||
@ -58,7 +59,7 @@ export function fetchGroupMsg(id) {
|
||||
}
|
||||
}
|
||||
|
||||
// 添加项目分组成员
|
||||
// 添加分组成员
|
||||
export function addMember(param) {
|
||||
return {
|
||||
type: ADD_GROUP_MEMBER,
|
||||
@ -66,7 +67,7 @@ export function addMember(param) {
|
||||
}
|
||||
}
|
||||
|
||||
// 删除项目分组成员
|
||||
// 删除分组成员
|
||||
export function delMember(param) {
|
||||
return {
|
||||
type: DEL_GROUP_MEMBER,
|
||||
@ -74,6 +75,14 @@ export function delMember(param) {
|
||||
}
|
||||
}
|
||||
|
||||
// 修改分组成员权限
|
||||
export function changeMemberRole(param) {
|
||||
return {
|
||||
type: CHANGE_GROUP_MEMBER,
|
||||
payload: axios.post('/api/group/change_member_role', param)
|
||||
}
|
||||
}
|
||||
|
||||
// 获取分组成员列表
|
||||
export function fetchGroupMemberList(id) {
|
||||
return {
|
||||
|
Loading…
x
Reference in New Issue
Block a user