mirror of
https://github.com/zuiidea/antd-admin.git
synced 2024-04-21 12:32:14 +00:00
Fix issue resulting User page showing wrong content when delete alll items in last page.
This commit is contained in:
+5
-27
@@ -4,7 +4,6 @@ import queryString from 'query-string'
|
||||
import { config } from 'utils'
|
||||
import { create, remove, update } from 'services/user'
|
||||
import * as usersService from 'services/users'
|
||||
import { routerRedux } from 'dva/router'
|
||||
import { pageModel } from './common'
|
||||
|
||||
const { query } = usersService
|
||||
@@ -37,11 +36,7 @@ export default modelExtend(pageModel, {
|
||||
|
||||
effects: {
|
||||
|
||||
* query ({ payload = {} }, { call, put, select }) {
|
||||
const { pagination } = yield select(_ => _.user)
|
||||
const { current, pageSize } = pagination
|
||||
payload.page = payload.page || current
|
||||
payload.pageSize = payload.pageSize || pageSize
|
||||
* query ({ payload = {} }, { call, put }) {
|
||||
const data = yield call(query, payload)
|
||||
if (data) {
|
||||
yield put({
|
||||
@@ -49,8 +44,8 @@ export default modelExtend(pageModel, {
|
||||
payload: {
|
||||
list: data.data,
|
||||
pagination: {
|
||||
current: Number(payload.page),
|
||||
pageSize: Number(payload.pageSize),
|
||||
current: Number(payload.page) || 1,
|
||||
pageSize: Number(payload.pageSize) || 10,
|
||||
total: data.total,
|
||||
},
|
||||
},
|
||||
@@ -60,33 +55,18 @@ export default modelExtend(pageModel, {
|
||||
|
||||
* delete ({ payload }, { call, put, select }) {
|
||||
const data = yield call(remove, { id: payload })
|
||||
const { selectedRowKeys, list, pagination } = yield select(_ => _.user)
|
||||
const { selectedRowKeys } = yield select(_ => _.user)
|
||||
if (data.success) {
|
||||
yield put({ type: 'updateState', payload: { selectedRowKeys: selectedRowKeys.filter(_ => _ !== payload) } })
|
||||
const page = (list.length === 1 && pagination.current > 1) ? pagination.current - 1 : pagination.current
|
||||
yield put({
|
||||
type: 'query',
|
||||
payload: {
|
||||
page,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
throw data
|
||||
}
|
||||
},
|
||||
|
||||
* multiDelete ({ payload }, { call, put, select }) {
|
||||
* multiDelete ({ payload }, { call, put }) {
|
||||
const data = yield call(usersService.remove, payload)
|
||||
const { list, pagination } = yield select(_ => _.user)
|
||||
if (data.success) {
|
||||
yield put({ type: 'updateState', payload: { selectedRowKeys: [] } })
|
||||
const page = (list.length === payload.ids.length && pagination.current > 1) ? pagination.current - 1 : pagination.current
|
||||
yield put({
|
||||
type: 'query',
|
||||
payload: {
|
||||
page,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
throw data
|
||||
}
|
||||
@@ -96,7 +76,6 @@ export default modelExtend(pageModel, {
|
||||
const data = yield call(create, payload)
|
||||
if (data.success) {
|
||||
yield put({ type: 'hideModal' })
|
||||
yield put({ type: 'query' })
|
||||
} else {
|
||||
throw data
|
||||
}
|
||||
@@ -108,7 +87,6 @@ export default modelExtend(pageModel, {
|
||||
const data = yield call(update, newUser)
|
||||
if (data.success) {
|
||||
yield put({ type: 'hideModal' })
|
||||
yield put({ type: 'query' })
|
||||
} else {
|
||||
throw data
|
||||
}
|
||||
|
||||
+30
-28
@@ -18,7 +18,16 @@ const User = ({
|
||||
const {
|
||||
list, pagination, currentItem, modalVisible, modalType, isMotion, selectedRowKeys,
|
||||
} = user
|
||||
const { pageSize } = pagination
|
||||
|
||||
const handleRefresh = (newQuery) => {
|
||||
dispatch(routerRedux.push({
|
||||
pathname,
|
||||
search: queryString.stringify({
|
||||
...query,
|
||||
...newQuery,
|
||||
}),
|
||||
}))
|
||||
}
|
||||
|
||||
const modalProps = {
|
||||
item: modalType === 'create' ? {} : currentItem,
|
||||
@@ -47,20 +56,21 @@ const User = ({
|
||||
location,
|
||||
isMotion,
|
||||
onChange (page) {
|
||||
dispatch(routerRedux.push({
|
||||
pathname,
|
||||
search: queryString.stringify({
|
||||
...query,
|
||||
page: page.current,
|
||||
pageSize: page.pageSize,
|
||||
}),
|
||||
}))
|
||||
handleRefresh({
|
||||
page: page.current,
|
||||
pageSize: page.pageSize,
|
||||
})
|
||||
},
|
||||
onDeleteItem (id) {
|
||||
dispatch({
|
||||
type: 'user/delete',
|
||||
payload: id,
|
||||
})
|
||||
.then(() => {
|
||||
handleRefresh({
|
||||
page: (list.length === 1 && pagination.current > 1) ? pagination.current - 1 : pagination.current,
|
||||
})
|
||||
})
|
||||
},
|
||||
onEditItem (item) {
|
||||
dispatch({
|
||||
@@ -70,6 +80,7 @@ const User = ({
|
||||
currentItem: item,
|
||||
},
|
||||
})
|
||||
.then(() => handleRefresh)
|
||||
},
|
||||
rowSelection: {
|
||||
selectedRowKeys,
|
||||
@@ -90,25 +101,10 @@ const User = ({
|
||||
...query,
|
||||
},
|
||||
onFilterChange (value) {
|
||||
dispatch(routerRedux.push({
|
||||
pathname: location.pathname,
|
||||
search: queryString.stringify({
|
||||
...value,
|
||||
page: 1,
|
||||
pageSize,
|
||||
}),
|
||||
}))
|
||||
},
|
||||
onSearch (fieldsValue) {
|
||||
fieldsValue.keyword.length ? dispatch(routerRedux.push({
|
||||
pathname: '/user',
|
||||
query: {
|
||||
field: fieldsValue.field,
|
||||
keyword: fieldsValue.keyword,
|
||||
},
|
||||
})) : dispatch(routerRedux.push({
|
||||
pathname: '/user',
|
||||
}))
|
||||
handleRefresh({
|
||||
...value,
|
||||
page: 1,
|
||||
})
|
||||
},
|
||||
onAdd () {
|
||||
dispatch({
|
||||
@@ -117,6 +113,7 @@ const User = ({
|
||||
modalType: 'create',
|
||||
},
|
||||
})
|
||||
.then(() => handleRefresh)
|
||||
},
|
||||
switchIsMotion () {
|
||||
dispatch({ type: 'user/switchIsMotion' })
|
||||
@@ -130,6 +127,11 @@ const User = ({
|
||||
ids: selectedRowKeys,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
handleRefresh({
|
||||
page: (list.length === selectedRowKeys.length && pagination.current > 1) ? pagination.current - 1 : pagination.current,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user