yapi/client/reducer/modules/project.js

206 lines
4.5 KiB
JavaScript
Raw Normal View History

2017-08-07 19:34:34 +08:00
import axios from 'axios';
import variable from '../../constants/variable';
2017-07-18 10:56:03 +08:00
2017-08-07 19:34:34 +08:00
// Actions
const FETCH_PROJECT_LIST = 'yapi/project/FETCH_PROJECT_LIST';
2017-08-17 22:19:58 +08:00
const GET_PROJECT_MSG = 'yapi/project/GET_PROJECT_MSG';
2017-08-07 19:34:34 +08:00
const PROJECT_ADD = 'yapi/project/PROJECT_ADD';
const PROJECT_DEL = 'yapi/project/PROJECT_DEL';
2017-08-17 22:19:58 +08:00
// const CHANGE_TABLE_LOADING = 'yapi/project/CHANGE_TABLE_LOADING';
2017-08-07 19:34:34 +08:00
const PROJECT_UPDATE = 'yapi/project/PROJECT_UPDATE';
2017-08-23 15:25:35 +08:00
const PROJECT_UPSET = 'yapi/project/PROJECT_UPSET';
2017-08-15 12:08:59 +08:00
const GET_CURR_PROJECT = 'yapi/project/GET_CURR_PROJECT'
2017-08-18 17:08:37 +08:00
const GET_PEOJECT_MEMBER = 'yapi/project/GET_PEOJECT_MEMBER';
const ADD_PROJECT_MEMBER = 'yapi/project/ADD_PROJECT_MEMBER';
const DEL_PROJECT_MEMBER = 'yapi/project/DEL_PROJECT_MEMBER';
const CHANGE_PROJECT_MEMBER = 'yapi/project/CHANGE_PROJECT_MEMBER';
2017-08-07 19:34:34 +08:00
// Reducer
2017-07-18 10:56:03 +08:00
const initialState = {
2017-07-19 20:59:59 +08:00
isUpdateModalShow: false,
handleUpdateIndex: -1,
2017-07-18 22:08:01 +08:00
projectList: [],
2017-08-17 22:19:58 +08:00
projectMsg: {},
2017-07-20 17:08:29 +08:00
userInfo: {},
tableLoading: true,
total: 0,
currPage: 1,
2017-08-15 12:08:59 +08:00
currProject: {}
2017-07-18 10:56:03 +08:00
};
export default (state = initialState, action) => {
switch (action.type) {
2017-08-15 12:08:59 +08:00
case GET_CURR_PROJECT: {
2017-08-11 17:24:50 +08:00
return {
...state,
2017-08-15 12:08:59 +08:00
currProject: action.payload.data
2017-08-11 17:24:50 +08:00
}
}
2017-08-17 22:19:58 +08:00
// case CHANGE_UPDATE_MODAL: {
// return {
// ...state,
// isUpdateModalShow: action.payload.data,
// handleUpdateIndex: action.payload.index
// };
// }
// case CHANGE_TABLE_LOADING: {
// return {
// ...state,
// tableLoading: action.payload
// }
// }
case FETCH_PROJECT_LIST: {
return {
...state,
2017-07-18 21:11:32 +08:00
projectList: action.payload.data.data.list,
2017-07-20 17:08:29 +08:00
total: action.payload.data.data.total,
userInfo: action.payload.data.data.userinfo
};
}
2017-08-17 22:19:58 +08:00
case GET_PROJECT_MSG: {
return {
...state,
projectMsg: action.payload.data.data
};
}
2017-07-18 10:56:03 +08:00
case PROJECT_ADD: {
return state;
}
2017-07-18 22:08:01 +08:00
case PROJECT_DEL: {
return state;
}
2017-07-18 10:56:03 +08:00
default:
return state;
}
};
2017-08-07 19:34:34 +08:00
2017-08-17 22:19:58 +08:00
// 获取某分组下的项目列表
2017-08-07 19:34:34 +08:00
export function fetchProjectList(id, pageNum) {
return {
type: FETCH_PROJECT_LIST,
payload: axios.get('/api/project/list', {
2017-08-07 19:34:34 +08:00
params: {
group_id: id,
page: pageNum || 1,
limit: variable.PAGE_LIMIT
}
})
};
}
2017-08-17 22:19:58 +08:00
// 获取项目信息
export function getProjectMsg(id) {
2017-08-07 19:34:34 +08:00
return {
2017-08-17 22:19:58 +08:00
type: GET_PROJECT_MSG,
payload: axios.get('/api/project/get', {
params: { id }
})
2017-08-07 19:34:34 +08:00
};
}
2017-08-18 17:08:37 +08:00
// 添加项目成员
export function addMember(param) {
return {
type: ADD_PROJECT_MEMBER,
payload: axios.post('/api/project/add_member', param)
}
}
// 删除项目成员
export function delMember(param) {
return {
type: DEL_PROJECT_MEMBER,
payload: axios.post('/api/project/del_member', param)
}
}
// 修改项目成员权限
export function changeMemberRole(param) {
return {
type: CHANGE_PROJECT_MEMBER,
payload: axios.post('/api/project/change_member_role', param)
}
}
// 获取项目成员列表
export function getProjectMemberList(id) {
return {
type: GET_PEOJECT_MEMBER,
payload: axios.get('/api/project/get_member_list', {
params: { id }
})
}
}
2017-08-17 22:19:58 +08:00
// export function changeTableLoading(data) {
// return {
// type: CHANGE_TABLE_LOADING,
// payload: data
// };
// }
2017-08-07 19:34:34 +08:00
export function addProject(data) {
2017-08-29 11:08:31 +08:00
const { name, prd_host, basepath, desc, group_id, group_name, protocol, icon, color, project_type } = data;
2017-08-07 19:34:34 +08:00
const param = {
name,
prd_host,
protocol,
basepath,
desc,
group_id,
2017-08-23 15:25:35 +08:00
group_name,
icon,
2017-08-29 11:08:31 +08:00
color,
project_type
2017-08-07 19:34:34 +08:00
};
return {
type: PROJECT_ADD,
payload: axios.post('/api/project/add', param)
2017-08-07 19:34:34 +08:00
};
}
2017-08-23 15:25:35 +08:00
// 修改项目
2017-08-07 19:34:34 +08:00
export function updateProject(data) {
const { name, project_type, basepath, desc, _id, env } = data;
2017-08-07 19:34:34 +08:00
const param = {
name,
project_type,
2017-08-07 19:34:34 +08:00
basepath,
desc,
id: _id,
env
};
return {
type: PROJECT_UPDATE,
payload: axios.post('/api/project/up', param)
2017-08-07 19:34:34 +08:00
};
}
2017-08-23 15:25:35 +08:00
// 修改项目头像
export function upsetProject(param) {
return {
type: PROJECT_UPSET,
payload: axios.post('/api/project/upset', param)
};
}
// 删除项目
2017-08-07 19:34:34 +08:00
export function delProject(id) {
const param = { id };
return {
type: PROJECT_DEL,
payload: axios.post('/api/project/del', param)
2017-08-07 19:34:34 +08:00
};
}
2017-08-11 17:24:50 +08:00
export function getProject(id){
2017-08-15 12:08:59 +08:00
return async (dispatch) => {
2017-08-11 17:24:50 +08:00
let result = await axios.get('/api/project/get?id=' + id);
dispatch({
2017-08-15 12:08:59 +08:00
type: GET_CURR_PROJECT,
payload: result.data
2017-08-11 17:24:50 +08:00
})
}
2017-08-15 12:08:59 +08:00
}