yapi/client/actions/project.js

91 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-07-14 18:02:01 +08:00
import {
FETCH_PROJECT_LIST,
2017-07-18 22:08:01 +08:00
PROJECT_ADD,
2017-07-19 20:59:59 +08:00
PROJECT_DEL,
CHANGE_UPDATE_MODAL,
PROJECT_UPDATE,
CHANGE_TABLE_LOADING
2017-07-14 18:02:01 +08:00
} from '../constants/action-types.js';
import axios from 'axios';
import variable from '../constants/variable';
2017-07-14 18:02:01 +08:00
const fetchProjectList = (id, pageNum) => {
return {
type: FETCH_PROJECT_LIST,
payload: axios.get('/project/list', {
params: {
group_id: id,
page: pageNum || 1,
limit: variable.PAGE_LIMIT
}
})
2017-07-18 22:08:01 +08:00
};
};
2017-07-19 20:59:59 +08:00
const changeUpdateModal = (data, index) => {
return {
type: CHANGE_UPDATE_MODAL,
2017-07-19 20:59:59 +08:00
payload: { data, index }
};
};
const changeTableLoading = (data) => {
return {
type: CHANGE_TABLE_LOADING,
payload: data
};
};
2017-07-14 18:02:01 +08:00
const addProject = (data) => {
2017-07-20 17:53:28 +08:00
const { name, prd_host, basepath, desc, group_id, protocol } = data;
2017-07-14 18:02:01 +08:00
const param = {
name,
prd_host,
2017-07-20 17:53:28 +08:00
protocol,
2017-07-14 18:02:01 +08:00
basepath,
2017-07-18 14:58:57 +08:00
desc,
group_id
2017-07-18 22:08:01 +08:00
};
2017-07-14 18:02:01 +08:00
return {
type: PROJECT_ADD,
// payload 可以返回 Promise异步请求使用 axios 即可
2017-07-18 10:56:03 +08:00
payload: axios.post('/project/add', param)
2017-07-18 22:08:01 +08:00
};
};
2017-07-19 20:59:59 +08:00
const updateProject = (data) => {
const { name, prd_host, basepath, desc, _id, protocol, env } = data;
2017-07-19 20:59:59 +08:00
const param = {
name,
prd_host,
2017-07-20 17:53:28 +08:00
protocol,
2017-07-19 20:59:59 +08:00
basepath,
desc,
id: _id,
env
2017-07-19 20:59:59 +08:00
};
return {
type: PROJECT_UPDATE,
// payload 可以返回 Promise异步请求使用 axios 即可
payload: axios.post('/project/up', param)
};
};
2017-07-18 22:08:01 +08:00
const delProject = (id) => {
const param = { id };
return {
type: PROJECT_DEL,
// payload 可以返回 Promise异步请求使用 axios 即可
payload: axios.post('/project/del', param)
};
};
2017-07-14 18:02:01 +08:00
export default {
fetchProjectList,
2017-07-18 22:08:01 +08:00
addProject,
2017-07-19 20:59:59 +08:00
delProject,
changeUpdateModal,
updateProject,
changeTableLoading
2017-07-18 22:08:01 +08:00
};