yapi/client/reducer/modules/interfaceCol.js

78 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-08-14 17:32:17 +08:00
import axios from 'axios'
// Actions
const FETCH_INTERFACE_COL_LIST = 'yapi/interfaceCol/FETCH_INTERFACE_COL_LIST';
const FETCH_INTERFACE_CASE_LIST = 'yapi/interfaceCol/FETCH_INTERFACE_CASE_LIST';
2017-08-17 20:24:07 +08:00
const SET_COL_DATA = 'yapi/interfaceCol/SET_COL_DATA';
2017-08-14 17:32:17 +08:00
// Reducer
const initialState = {
interfaceColList: [{
_id: 0,
name: '',
uid: 0,
project_id: 0,
desc: '',
add_time: 0,
up_time: 0,
2017-08-17 20:24:07 +08:00
caseList: [
2017-08-14 17:32:17 +08:00
{}
]
}],
isShowCol: true,
2017-08-17 20:24:07 +08:00
currColId: 0,
currCaseId: 0
2017-08-14 17:32:17 +08:00
}
export default (state = initialState, action) => {
switch (action.type) {
case FETCH_INTERFACE_COL_LIST:
return {
...state,
interfaceColList: action.payload.data.data
}
case FETCH_INTERFACE_CASE_LIST: {
2017-08-17 20:24:07 +08:00
const caseList = state.interfaceColList.map(col => {
if (col._id === state.currColId) {
return col.caseList = action.payload.data.data;
2017-08-14 17:32:17 +08:00
}
return col;
})
return {
...state,
2017-08-17 20:24:07 +08:00
caseList
}
}
case SET_COL_DATA: {
return {
...state,
...action.payload.data
2017-08-14 17:32:17 +08:00
}
}
default:
return state
}
}
// Action Creators
export function fetchInterfaceColList (projectId) {
return {
type: FETCH_INTERFACE_COL_LIST,
payload: axios.get('/api/col/list?project_id=' + projectId)
}
}
export function fetchInterfaceCaseList(colId){
return {
type: FETCH_INTERFACE_CASE_LIST,
payload: axios.get('/api/col/case_list?col_id=' + colId)
}
}
2017-08-17 20:24:07 +08:00
export function setColData(data){
return {
type: SET_COL_DATA,
payload: data
}
}