2017-08-07 19:34:34 +08:00
|
|
|
import axios from 'axios';
|
2017-07-11 16:35:39 +08:00
|
|
|
|
2017-08-07 19:34:34 +08:00
|
|
|
// Actions
|
|
|
|
const FETCH_GROUP_LIST = 'yapi/group/FETCH_GROUP_LIST';
|
|
|
|
const SET_CURR_GROUP = 'yapi/group/SET_CURR_GROUP';
|
2017-08-16 17:13:14 +08:00
|
|
|
const FETCH_GROUP_MEMBER = 'yapi/group/FETCH_GROUP_MEMBER';
|
|
|
|
const FETCH_GROUP_MSG = 'yapi/group/FETCH_GROUP_MSG';
|
2017-08-16 20:31:59 +08:00
|
|
|
const ADD_GROUP_MEMBER = 'yapi/group/ADD_GROUP_MEMBER';
|
|
|
|
const DEL_GROUP_MEMBER = 'yapi/group/DEL_GROUP_MEMBER';
|
2017-08-16 21:29:01 +08:00
|
|
|
const CHANGE_GROUP_MEMBER = 'yapi/group/CHANGE_GROUP_MEMBER';
|
2017-08-07 19:34:34 +08:00
|
|
|
|
|
|
|
// Reducer
|
2017-07-11 16:35:39 +08:00
|
|
|
const initialState = {
|
2017-07-12 16:38:42 +08:00
|
|
|
groupList: [],
|
2017-08-16 17:13:14 +08:00
|
|
|
currGroup: { group_name: '' },
|
|
|
|
member: [],
|
|
|
|
role: ''
|
2017-07-11 16:35:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default (state = initialState, action) => {
|
|
|
|
switch (action.type) {
|
|
|
|
case FETCH_GROUP_LIST: {
|
2017-08-08 15:41:07 +08:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
groupList: action.payload.data.data
|
|
|
|
};
|
2017-07-11 16:35:39 +08:00
|
|
|
}
|
2017-07-17 10:17:29 +08:00
|
|
|
case SET_CURR_GROUP: {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
currGroup: action.payload
|
|
|
|
};
|
2017-07-11 16:35:39 +08:00
|
|
|
}
|
2017-08-16 17:13:14 +08:00
|
|
|
case FETCH_GROUP_MEMBER: {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
member: action.payload.data.data
|
|
|
|
};
|
|
|
|
}
|
|
|
|
case FETCH_GROUP_MSG: {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
role: action.payload.data.data.role
|
|
|
|
};
|
|
|
|
}
|
2017-07-11 16:35:39 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
2017-08-07 19:34:34 +08:00
|
|
|
|
2017-08-16 17:13:14 +08:00
|
|
|
// 获取 group 信息 (权限信息)
|
|
|
|
export function fetchGroupMsg(id) {
|
|
|
|
return {
|
|
|
|
type: FETCH_GROUP_MSG,
|
|
|
|
payload: axios.get('/api/group/get', {
|
|
|
|
params: { id }
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 21:29:01 +08:00
|
|
|
// 添加分组成员
|
2017-08-16 17:13:14 +08:00
|
|
|
export function addMember(param) {
|
|
|
|
return {
|
2017-08-16 20:31:59 +08:00
|
|
|
type: ADD_GROUP_MEMBER,
|
2017-08-16 17:13:14 +08:00
|
|
|
payload: axios.post('/api/group/add_member', param)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 21:29:01 +08:00
|
|
|
// 删除分组成员
|
2017-08-16 20:31:59 +08:00
|
|
|
export function delMember(param) {
|
|
|
|
return {
|
|
|
|
type: DEL_GROUP_MEMBER,
|
|
|
|
payload: axios.post('/api/group/del_member', param)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 21:29:01 +08:00
|
|
|
// 修改分组成员权限
|
|
|
|
export function changeMemberRole(param) {
|
|
|
|
return {
|
|
|
|
type: CHANGE_GROUP_MEMBER,
|
|
|
|
payload: axios.post('/api/group/change_member_role', param)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 17:13:14 +08:00
|
|
|
// 获取分组成员列表
|
|
|
|
export function fetchGroupMemberList(id) {
|
|
|
|
return {
|
|
|
|
type: FETCH_GROUP_MEMBER,
|
|
|
|
payload: axios.get('/api/group/get_member_list', {
|
|
|
|
params: { id }
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-07 19:34:34 +08:00
|
|
|
// Action Creators
|
|
|
|
export function fetchGroupList() {
|
|
|
|
return {
|
|
|
|
type: FETCH_GROUP_LIST,
|
2017-08-11 10:25:19 +08:00
|
|
|
payload: axios.get('/api/group/list')
|
2017-08-07 19:34:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setCurrGroup(group) {
|
|
|
|
return {
|
|
|
|
type: SET_CURR_GROUP,
|
|
|
|
payload: group
|
|
|
|
}
|
|
|
|
}
|