yapi/client/reducer/modules/news.js

94 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-08-07 19:34:34 +08:00
// Actions
const FETCH_NEWS_DATA = 'yapi/news/FETCH_NEWS_DATA';
2017-08-14 15:17:05 +08:00
const FETCH_MORE_NEWS = 'yapi/news/FETCH_MORE_NEWS'
2017-08-07 19:34:34 +08:00
// Reducer
2017-07-17 12:15:21 +08:00
const initialState = {
2017-08-09 16:08:37 +08:00
newsData: {
list: [],
total: 0
},
curpage: 1
2017-07-17 12:15:21 +08:00
}
export default (state = initialState, action) => {
switch (action.type) {
case FETCH_NEWS_DATA: {
2017-08-14 15:17:05 +08:00
const list = action.payload.data.data.list;
state.newsData.list = list;
state.curpage = 1;
state.newsData.list.sort(function(a,b){
return b.add_time - a.add_time;
})
return {
...state,
newsData: {
total:action.payload.data.data.total,
list: state.newsData.list
}
};
}
case FETCH_MORE_NEWS: {
2017-08-09 16:08:37 +08:00
const list = action.payload.data.data.list;
state.newsData.list.push(...list);
2017-08-09 18:00:45 +08:00
state.newsData.list.sort(function(a,b){
return b.add_time - a.add_time;
})
2017-08-09 16:08:37 +08:00
if(list && list.length){
state.curpage++;
}
2017-07-17 12:15:21 +08:00
return {
...state,
2017-08-09 16:08:37 +08:00
newsData: {
total:action.payload.data.data.total,
list: state.newsData.list
}
2017-08-14 15:17:05 +08:00
}
2017-07-17 12:15:21 +08:00
}
default:
return state;
}
}
2017-08-07 19:34:34 +08:00
// Action Creators
import axios from 'axios';
import variable from '../../constants/variable';
2017-08-11 17:49:47 +08:00
export function fetchNewsData (typeid,type,page,limit) {
2017-08-07 19:34:34 +08:00
const param = {
2017-08-09 18:00:45 +08:00
typeid: typeid,
2017-08-11 17:49:47 +08:00
type: type,
2017-08-07 19:34:34 +08:00
page: page,
2017-08-09 16:08:37 +08:00
limit: limit?limit:variable.PAGE_LIMIT
2017-08-07 19:34:34 +08:00
}
return {
type: FETCH_NEWS_DATA,
payload: axios.get('/api/log/list',{
2017-08-07 19:34:34 +08:00
params: param
})
};
}
2017-08-14 15:17:05 +08:00
export function fetchMoreNews (typeid,type,page,limit) {
const param = {
typeid: typeid,
type: type,
page: page,
limit: limit?limit:variable.PAGE_LIMIT
}
return {
type: FETCH_MORE_NEWS,
payload: axios.get('/api/log/list',{
params: param
})
};
}
2017-08-07 19:34:34 +08:00
2017-08-09 18:00:45 +08:00
export function getMockUrl(project_id){
const params = {id: project_id};
return {
type:"",
payload: axios.get('/api/project/get', {params: params})
2017-08-09 18:00:45 +08:00
}
2017-08-07 19:34:34 +08:00
}
2017-08-09 18:00:45 +08:00