mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-21 05:19:42 +08:00
93 lines
2.2 KiB
JavaScript
Executable File
93 lines
2.2 KiB
JavaScript
Executable File
import axios from 'axios'
|
|
// Actions
|
|
const INIT_INTERFACE_DATA = 'yapi/interface/INIT_INTERFACE_DATA';
|
|
const FETCH_INTERFACE_DATA = 'yapi/interface/FETCH_INTERFACE_DATA';
|
|
const FETCH_INTERFACE_LIST = 'yapi/interface/FETCH_INTERFACE_LIST';
|
|
const DELETE_INTERFACE_DATA = 'yapi/interface/DELETE_INTERFACE_DATA';
|
|
const DELETE_INTERFACE_CAT_DATA = 'yapi/interface/DELETE_INTERFACE_CAT_DATA';
|
|
const UPDATE_INTERFACE_DATA = 'yapi/interface/UPDATE_INTERFACE_DATA';
|
|
// const SAVE_INTERFACE_PROJECT_ID = 'yapi/interface/SAVE_INTERFACE_PROJECT_ID';
|
|
// const GET_INTERFACE_GROUP_LIST = 'yapi/interface/GET_INTERFACE_GROUP_LIST';
|
|
|
|
// Reducer
|
|
const initialState = {
|
|
curdata: {},
|
|
list: []
|
|
}
|
|
|
|
export default (state = initialState, action) => {
|
|
switch (action.type) {
|
|
case INIT_INTERFACE_DATA:
|
|
return initialState
|
|
case UPDATE_INTERFACE_DATA:
|
|
return {
|
|
...state,
|
|
curdata: Object.assign({}, state.curdata, action.updata)
|
|
}
|
|
|
|
case FETCH_INTERFACE_DATA:
|
|
return {
|
|
...state,
|
|
curdata: action.payload.data
|
|
}
|
|
case FETCH_INTERFACE_LIST:
|
|
return {
|
|
...state,
|
|
list: action.payload.data
|
|
}
|
|
default:
|
|
return state
|
|
}
|
|
}
|
|
|
|
export function initInterface(){
|
|
return {
|
|
type: INIT_INTERFACE_DATA
|
|
}
|
|
|
|
}
|
|
|
|
export function updateInterfaceData(updata) {
|
|
|
|
return {
|
|
type: UPDATE_INTERFACE_DATA,
|
|
updata: updata,
|
|
payload: true
|
|
}
|
|
|
|
|
|
}
|
|
|
|
export async function deleteInterfaceData(id) {
|
|
let result = await axios.post('/api/interface/del', { id: id })
|
|
return {
|
|
type: DELETE_INTERFACE_DATA,
|
|
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
|
|
}
|
|
}
|
|
|
|
// Action Creators
|
|
export async function fetchInterfaceData(interfaceId) {
|
|
let result = await axios.get('/api/interface/get?id=' + interfaceId);
|
|
|
|
return {
|
|
type: FETCH_INTERFACE_DATA,
|
|
payload: result.data
|
|
}
|
|
}
|
|
|
|
export async function fetchInterfaceList(projectId) {
|
|
let result = await axios.get('/api/interface/list_menu?project_id=' + projectId);
|
|
return {
|
|
type: FETCH_INTERFACE_LIST,
|
|
payload: result.data
|
|
}
|
|
} |