mirror of
https://github.com/YMFE/yapi.git
synced 2025-01-06 12:45:22 +08:00
feat: 删除分组
This commit is contained in:
parent
9ddac64fee
commit
db920c84a9
@ -6,6 +6,7 @@ import { autobind } from 'core-decorators';
|
||||
import axios from 'axios';
|
||||
|
||||
const Search = Input.Search;
|
||||
const confirm = Modal.confirm;
|
||||
const TYPE_EDIT = 'edit';
|
||||
|
||||
import {
|
||||
@ -95,6 +96,7 @@ export default class GroupList extends Component {
|
||||
addGroupModalVisible: false
|
||||
});
|
||||
this.props.fetchGroupList()
|
||||
this.props.setCurrGroup(res.data.data)
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -137,6 +139,29 @@ export default class GroupList extends Component {
|
||||
this.props.setCurrGroup(currGroup);
|
||||
}
|
||||
|
||||
@autobind
|
||||
deleteGroup() {
|
||||
const self = this;
|
||||
const { currGroup } = self.props;
|
||||
confirm({
|
||||
title: `你确定要删除分组 ${currGroup.group_name}?`,
|
||||
content: `分组简介:${currGroup.group_desc}`,
|
||||
onOk() {
|
||||
axios.post('/group/del', {id: currGroup._id}).then(res => {
|
||||
if (res.data.errcode) {
|
||||
message.error(res.data.errmsg);
|
||||
} else {
|
||||
message.success('删除成功');
|
||||
self.props.fetchGroupList().then(() => {
|
||||
const currGroup = self.props.groupList[0] || { group_name: '', group_desc: '' };
|
||||
self.props.setCurrGroup(currGroup)
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render () {
|
||||
const { groupList, currGroup } = this.props;
|
||||
|
||||
@ -146,7 +171,8 @@ export default class GroupList extends Component {
|
||||
<div className="curr-group">
|
||||
<div className="curr-group-name">
|
||||
{currGroup.group_name}
|
||||
<Icon className="edit-group" type="edit" onClick={() => this.showModal(TYPE_EDIT)}/>
|
||||
<Icon className="edit-group" type="edit" title="编辑分组" onClick={() => this.showModal(TYPE_EDIT)}/>
|
||||
<Icon className="delete-group" type="delete" title="删除分组" onClick={this.deleteGroup}/>
|
||||
</div>
|
||||
<div className="curr-group-desc">简介:{currGroup.group_desc}</div>
|
||||
</div>
|
||||
|
@ -12,11 +12,12 @@
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
}
|
||||
.edit-group {
|
||||
.delete-group, .edit-group {
|
||||
font-size: 18px;
|
||||
margin-left: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.edit-group:hover {
|
||||
.delete-group:hover, .edit-group:hover {
|
||||
color: #ccc;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import {
|
||||
FETCH_GROUP_LIST,
|
||||
SET_CURR_GROUP
|
||||
} from '../../constants/action-types';
|
||||
import { message } from 'antd'
|
||||
|
||||
const initialState = {
|
||||
groupList: [],
|
||||
@ -11,7 +12,9 @@ const initialState = {
|
||||
export default (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case FETCH_GROUP_LIST: {
|
||||
if (!action.payload.data.errcode) {
|
||||
if (action.payload.data.errcode) {
|
||||
message.error(action.payload.data.errmsg);
|
||||
} else {
|
||||
return {
|
||||
...state,
|
||||
groupList: action.payload.data.data
|
||||
|
Loading…
Reference in New Issue
Block a user