yapi/client/reducer/modules/interface.js

110 lines
2.6 KiB
JavaScript
Raw Normal View History

2017-08-11 18:57:58 +08:00
import axios from 'axios'
2017-08-07 19:34:34 +08:00
// Actions
2017-08-19 19:06:09 +08:00
const INIT_INTERFACE_DATA = 'yapi/interface/INIT_INTERFACE_DATA';
2017-08-07 19:34:34 +08:00
const FETCH_INTERFACE_DATA = 'yapi/interface/FETCH_INTERFACE_DATA';
2017-08-11 18:57:58 +08:00
const FETCH_INTERFACE_LIST = 'yapi/interface/FETCH_INTERFACE_LIST';
const DELETE_INTERFACE_DATA = 'yapi/interface/DELETE_INTERFACE_DATA';
2017-08-19 19:06:09 +08:00
const DELETE_INTERFACE_CAT_DATA = 'yapi/interface/DELETE_INTERFACE_CAT_DATA';
2017-08-14 23:01:20 +08:00
const UPDATE_INTERFACE_DATA = 'yapi/interface/UPDATE_INTERFACE_DATA';
2017-09-27 21:29:22 +08:00
const CHANGE_EDIT_STATUS = 'yapi/interface/CHANGE_EDIT_STATUS';
2017-08-11 18:57:58 +08:00
// const SAVE_INTERFACE_PROJECT_ID = 'yapi/interface/SAVE_INTERFACE_PROJECT_ID';
// const GET_INTERFACE_GROUP_LIST = 'yapi/interface/GET_INTERFACE_GROUP_LIST';
2017-08-07 15:40:21 +08:00
2017-08-07 19:34:34 +08:00
// Reducer
2017-08-07 15:40:21 +08:00
const initialState = {
2017-08-11 18:57:58 +08:00
curdata: {},
2017-09-27 21:29:22 +08:00
list: [],
editStatus: false // 记录编辑页面是否有编辑
2017-08-07 15:40:21 +08:00
}
export default (state = initialState, action) => {
switch (action.type) {
2017-08-19 19:06:09 +08:00
case INIT_INTERFACE_DATA:
return initialState
2017-08-14 23:01:20 +08:00
case UPDATE_INTERFACE_DATA:
return {
...state,
2017-08-17 16:40:58 +08:00
curdata: Object.assign({}, state.curdata, action.updata)
2017-08-14 23:01:20 +08:00
}
2017-08-07 15:40:21 +08:00
case FETCH_INTERFACE_DATA:
return {
...state,
2017-08-11 18:57:58 +08:00
curdata: action.payload.data
2017-08-07 15:40:21 +08:00
}
2017-08-11 18:57:58 +08:00
case FETCH_INTERFACE_LIST:
2017-08-07 15:40:21 +08:00
return {
...state,
2017-08-18 17:49:37 +08:00
list: action.payload.data
}
2017-09-27 21:29:22 +08:00
case CHANGE_EDIT_STATUS: {
return {
...state,
editStatus: action.status
};
}
2017-08-07 15:40:21 +08:00
default:
return state
}
}
2017-08-07 19:34:34 +08:00
2017-09-27 21:29:22 +08:00
// 记录编辑页面是否有编辑
export function changeEditStatus(status) {
return {
type: CHANGE_EDIT_STATUS,
status
}
}
2017-08-19 19:06:09 +08:00
export function initInterface(){
return {
type: INIT_INTERFACE_DATA
}
}
2017-08-14 23:01:20 +08:00
export function updateInterfaceData(updata) {
return {
type: UPDATE_INTERFACE_DATA,
updata: updata,
payload: true
}
}
export async function deleteInterfaceData(id) {
2017-08-19 19:06:09 +08:00
let result = await axios.post('/api/interface/del', { id: id })
return {
type: DELETE_INTERFACE_DATA,
2017-08-19 19:06:09 +08:00
payload: result
}
}
export async function deleteInterfaceCatData(id) {
let result = await axios.post('/api/interface/del_cat', { catid: id })
return {
type: DELETE_INTERFACE_CAT_DATA,
payload: result
}
}
2017-08-07 19:34:34 +08:00
// Action Creators
export async function fetchInterfaceData(interfaceId) {
let result = await axios.get('/api/interface/get?id=' + interfaceId);
2017-09-27 21:29:22 +08:00
return {
type: FETCH_INTERFACE_DATA,
payload: result.data
2017-08-07 19:34:34 +08:00
}
}
export async function fetchInterfaceList(projectId) {
2017-08-18 20:35:31 +08:00
let result = await axios.get('/api/interface/list_menu?project_id=' + projectId);
return {
type: FETCH_INTERFACE_LIST,
payload: result.data
2017-08-07 19:34:34 +08:00
}
2017-09-27 21:29:22 +08:00
}