123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import {fromJS} from 'immutable';
- import * as constants from './constants';
- import {getrand} from '../../../lib/public'
- const defaultState = fromJS({
- featureList: [],
- blogList: [],
- articlePage: 1,
- thumbList: [
- {img: 'https://cos.nosum.cn/nosum/blog/1/nosum-blog-1%20(44).jpg'},
- {img: 'https://cos.nosum.cn/nosum/blog/1/nosum-blog-1%20(42).jpg'},
- {img: 'https://cos.nosum.cn/nosum/blog/1/nosum-blog-1%20(41).jpg'},
- {img: 'https://cos.nosum.cn/nosum/blog/1/nosum-blog-1%20(3).jpg'},
- {img: 'https://cos.nosum.cn/nosum/blog/1/nosum-blog-1%20(28).jpg'},
- {img: 'https://cos.nosum.cn/nosum/blog/1/nosum-blog-1%20(43).jpg'},
- {img: 'https://cos.nosum.cn/nosum/blog/1/nosum-blog-1%20(47).jpg'},
- {img: 'https://cos.nosum.cn/nosum/blog/1/nosum-blog-1%20(48).jpg'},
- {img: 'https://cos.nosum.cn/nosum/blog/1/nosum-blog-1%20(49).jpg'},
- {img: 'https://cos.nosum.cn/nosum/blog/1/nosum-blog-1%20(55).jpg'},
- {img: 'https://cos.nosum.cn/nosum/blog/1/nosum-blog-1%20(56).jpg'},
- {img: 'https://cos.nosum.cn/nosum/blog/1/nosum-blog-1%20(57).jpg'}
- ],
- finished: false,
- loading: true,
- isList: false,
- socialList:[]
- });
- const setFeature = (state, action) => {
- return state.merge({
- featureList: action.data
- })
- };
- const list = (thumbList, data) => {
- const list = data.toJS();
- const Img = thumbList.toJS();
- let arr = [];
- for (let i = 0; i < list.length; i++) {
- arr.push({
- id: list[i].id,
- title: list[i].title,
- thumbnail: list[i].thumbnail || Img[getrand(0, Img.length - 1)].img,
- comments: list[i].comments,
- status: list[i].status,
- summary: list[i].summary,
- views: list[i].views,
- createTime: list[i].createTime,
- syncStatus: list[i].syncStatus,
- author: list[i].author,
- categoryName: list[i].categoryName
- })
- }
- return arr
- };
- const setBlogList = (state, action) => {
- const arr = list(state.get('thumbList'), action.data);
- return action.override ? state.merge({
- blogList: action.override ? fromJS(arr) : state.get('blogList').concat(fromJS(arr)),
- articlePage: action.nextPage,
- finished: false,
- loading: false,
- isList: true
- }) : state.merge({
- blogList: action.override ? fromJS(arr) : state.get('blogList').concat(fromJS(arr)),
- articlePage: action.nextPage,
- loading: false,
- isList: true
- })
- };
- export default (state = defaultState, action) => {
- switch (action.type) {
- case constants.GET_FEATURE:
- return setFeature(state, action);
- case constants.GET_BLOGLIST:
- return setBlogList(state, action);
- case constants.SET_FINISHED:
- return state.set('finished', true);
- case constants.LOADING_TRUE:
- return state.set('loading', true);
- case constants.GET_SOCIAL_LIST:
- return state.merge({
- socialList: action.data
- });
- default:
- return state;
- }
- }
|