React模拟后台项目(八) 附加 user仓库文件配置

15 篇文章 1 订阅

一、用户页面仓库 src/pages/user/store/index.js

import reducer from './reducer';
import * as actionCreators from './actionCreators';
import * as constants from './actionTypes';
    
export {reducer, actionCreators, constants} 

二、用户页面仓库 src/pages/user/store/actionTypes.js

export const GET_USERS = 'users/GET_USERS'

三、用户页面仓库 src/pages/user/store/actionCreators.js

// 常量
import * as constants from './actionTypes'

// UI组件
import { message } from 'antd';

// 接口
import {
    getUsersApi,
    deleteUsersApi,
    postUsersApi,  //用户添加接口
    putUsersApi,
} from '../../../api/index'


// 用户信息列表
export const getUsersData = params => dispatch => {
    getUsersApi(params).then(res => {
        console.log(res)
        if(res.meta.status === 200){
            dispatch({
                type: constants.GET_USERS,
                data: res.data                
            })
        }
    })
}

// 用户信息删除 
export const deleteUsersData = (id, callback) => dispatch => {
    deleteUsersApi(id).then( res => {
        if(res.meta.status === 200){
            message.success('删除成功')
            callback()
        }else{
            message.error(res.meta.msg);
        }
    })
};

// 用户信息添加
export const postUsersData = (params, callback) => dispatch => {
    postUsersApi(params).then(res => {
        console.log(res)
        if(res.meta.status === 201){
            message.success('添加成功')
            callback()
        }else{
            message.error(res.meta.msg);
        }
    })
}

// 用户信息编辑
export const putUsersData = (id, params, callback) => dispatch => {
    console.log(putUsersApi)
    putUsersApi(id, params).then(res => {
        console.log(res)
        if(res.meta.status === 200)
        {
            message.success('修改成功')
            callback()
        }else
        {
            message.error(res.meta.msg);
        }
    })
}

四、用户页面仓库 src/pages/user/store/reducer.js

import {fromJS} from 'immutable'
import * as constants from './actionTypes'

const defaultState = fromJS({
    // 表单列表数据
    data: []
})

export default (state = defaultState, action) => {
    
    switch(action.type)
    {
        case constants.GET_USERS:           
            return state.set ('data', fromJS(action.data))
        default:
            return state
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值