SupSearch:'/api/Order/supSearch.json',
SupState:'/api/Order/supState.json',
import { watchGetAccountSaga } from './account' import {supSearch} from './supSearch' export default function* rootSaga() { yield [ // 更多 watchGetAccountSaga(), supSearch(), ] }
componentWillMount(){ this.props.initialDispatch() },
import { SUPSEARCHACTION, supSearchSucceed,supSearchFailed} from '../actions/sup' export function* supSearch() { while (true) { yield take(SUPSEARCHACTION) yield fork(fetchSupSearchApi) } }
function* fetchSupSearchApi(){ try { yield put( beginTask() ) const response = yield call(fetch, FL.PATH.API.SupSearch) const res = yield response.json() if (!res) { return false } else { yield put( supSearchSucceed(res) ) (成功) } } catch (e) { yield put( supSearchFailed(e) ) (失敗) } finally { yield put( endTask() ) } }
if (__DEBUG__) { let data = Mock.mock({ 'Status': '200', 'Position': '001', 'ErrorCode': '001', 'Data|1-10': [{ 'productNumber': /[A-Z][A-Z]\d{3}[a-z]\d{3}/, 'productName': '@ctitle(3, 5)', 'supplierName': '@ctitle(3)', 'productStockStatus|1-100': 1, 'faceValue|1-1000': 1, 'productPrice|1-100': 1, 'type|1-4': 1, 'averageChargeTime':'@natural(0,200)'+'min', 'complaintRate':'@natural(0,100)'+'%', 'successRate': '@natural(0,100)'+'%', 'today|1-100': 1, 'week|1-1000':1 , 'month|1-10000': 1, 'purchaseApplyStatus': '@boolean()' }] }); fetchMock.mock(FL.PATH.API.SupSearch, data); // fetchMock.mock(FL.PATH.API.ACCOUNT, 404); }
export const SUPSEARCHACTION = 'SUPSEARCHACTION' export const SUPSEARCH_SUCCEED = 'SUPSEARCH_SUCCEED' export const SUPSEARCH_FAILED = 'SUPSEARCH_FAILED'
export function supSearchAction(){ return { type:SUPSEARCHACTION } } export function supSearchSucceed(items){ return { type:SUPSEARCH_SUCCEED, items } } export function supSearchFailed(error) { return { type: SUPSEARCH_FAILED, error, } }
import supSearch from './supSearch' import supState from './supState' const rootReducer = combineReducers({ routing: routerReducer, supSearch, supState, }) export default rootReducer
import {SUPSEARCHACTION,SUPSEARCH_SUCCEED,SUPSEARCH_FAILED} from '../actions/sup' export default function supSearch (state = {}, action) { switch (action.type) { case SUPSEARCHACTION: return { ...state, isfetching:true, } case SUPSEARCH_SUCCEED: return { ...state, isfetch:false, items: action.items, } case SUPSEARCH_FAILED: return { ...state, isfetching: false, error: action.error, }; default: return state } }
import { connect} from 'react-redux' import SupSearch from '../components/SupSearch/js/SupSearch' import {supSearchAction} from '../actions/sup' import {createSelector } from 'reselect' const defaultValue = []; const stateItemSelector = (state) =>state.supSearch.items || defaultValue const stateSelector = createSelector ( [stateItemSelector], (stateItem) => { return stateItem } ) const mapStateToProps = (state) =>{ return { items:stateSelector(state), } } const mapDispatchToProps = (dispatch) =>{ return { initialDispatch(){ dispatch(supSearchAction()) }, } } export default connect( mapStateToProps, mapDispatchToProps )(SupSearch)
componentWillMount(){ this.props.initialDispatch() },