mirror of
https://github.com/zuiidea/antd-admin
synced 2026-10-29 20:44:05 +00:00
user
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
|
||||
export default {
|
||||
|
||||
namespace: 'example',
|
||||
|
||||
state: {},
|
||||
|
||||
subscriptions: {
|
||||
setup({ dispatch, history }) {
|
||||
},
|
||||
},
|
||||
|
||||
effects: {
|
||||
*fetchRemote({ payload }, { call, put }) {
|
||||
},
|
||||
},
|
||||
|
||||
reducers: {
|
||||
fetch(state, action) {
|
||||
return { ...state, ...action.payload };
|
||||
},
|
||||
},
|
||||
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
import {create, remove, update, query} from '../services/users'
|
||||
import {parse} from 'qs'
|
||||
|
||||
export default {
|
||||
|
||||
namespace : 'users',
|
||||
|
||||
state : {
|
||||
list: [],
|
||||
loading: false,
|
||||
total: null,
|
||||
current: 1,
|
||||
currentItem: {},
|
||||
modalVisible: false,
|
||||
modalType: 'create'
|
||||
},
|
||||
|
||||
subscriptions : {
|
||||
setup({dispatch, history}) {
|
||||
history.listen(location => {
|
||||
if (location.pathname === '/users') {
|
||||
dispatch({type: 'query', payload: location.query})
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
effects : {
|
||||
*query({
|
||||
payload
|
||||
}, {call, put}) {
|
||||
yield put({type: 'showLoading'})
|
||||
const {data} = yield call(query, parse(payload))
|
||||
if (data) {
|
||||
yield put({
|
||||
type: 'querySuccess',
|
||||
payload: {
|
||||
list: data.data,
|
||||
total: data.page.total,
|
||||
current: data.page.current
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
* 'delete' ({
|
||||
payload
|
||||
}, {call, put}) {
|
||||
yield put({type: 'showLoading'})
|
||||
const {data} = yield call(remove, {id: payload})if (data && data.success) {
|
||||
yield put({type: 'deleteSuccess', payload})
|
||||
}
|
||||
},
|
||||
*create({
|
||||
payload
|
||||
}, {call, put}) {
|
||||
yield put({type: 'hideModal'})
|
||||
yield put({type: 'showLoading'})
|
||||
const {data} = yield call(create, payload)
|
||||
if (data && data.success) {
|
||||
yield put({type: 'createSuccess', payload})
|
||||
}
|
||||
},
|
||||
*update({
|
||||
payload
|
||||
}, {select, call, put}) {
|
||||
yield put({type: 'hideModal'})
|
||||
yield put({type: 'showLoading'})
|
||||
const id = yield select(({users}) => users.currentItem.id)
|
||||
const newUser = {
|
||||
...payload,
|
||||
id
|
||||
}
|
||||
const {data} = yield call(update, newUser)
|
||||
if (data && data.success) {
|
||||
yield put({type: 'updateSuccess', payload: newUser})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
reducers : {
|
||||
showLoading(state) {
|
||||
return {
|
||||
...state,
|
||||
loading: true
|
||||
}
|
||||
},
|
||||
createSuccess(state, action) {
|
||||
const newUser = action.payload
|
||||
return {
|
||||
...state,
|
||||
list: [
|
||||
newUser, ...state.list
|
||||
],
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
deleteSuccess(state, action) {
|
||||
const id = action.payload
|
||||
const newList = state.list.filter(user => user.id !== id)
|
||||
return {
|
||||
...state,
|
||||
list: newList,
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
updateSuccess(state, action) {
|
||||
const updateUser = action.payload
|
||||
const newList = state.list.map(user => {
|
||||
if (user.id === updateUser.id) {
|
||||
return {
|
||||
...user,
|
||||
...updateUser
|
||||
}
|
||||
}
|
||||
return user
|
||||
})
|
||||
return {
|
||||
...state,
|
||||
list: newList,
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
querySuccess(state, action) {
|
||||
return {
|
||||
...state,
|
||||
...action.payload,
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
showModal(state, action) {
|
||||
return {
|
||||
...state,
|
||||
...action.payload,
|
||||
modalVisible: true
|
||||
}
|
||||
},
|
||||
hideModal(state) {
|
||||
return {
|
||||
...state,
|
||||
modalVisible: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user