diff --git a/src/pages/user/components/Filter.js b/src/pages/user/components/Filter.js index 1931677..49fc04d 100644 --- a/src/pages/user/components/Filter.js +++ b/src/pages/user/components/Filter.js @@ -26,11 +26,6 @@ const TwoColProps = { @withI18n() @Form.create() class Filter extends Component { - componentDidUpdate(prevProps, prevState) { - if (Object.keys(prevProps.filter).length === 0) { - this.handleReset() - } - } handleFields = fields => { const { createTime } = fields if (createTime.length) { diff --git a/src/pages/user/index.js b/src/pages/user/index.js index 66f4a77..238ced8 100644 --- a/src/pages/user/index.js +++ b/src/pages/user/index.js @@ -13,9 +13,30 @@ import Modal from './components/Modal' @withI18n() @connect(({ user, loading }) => ({ user, loading })) class User extends PureComponent { + componentDidMount() { + this.handleRefresh({ page: 1, pageSize: 10 }) + } + + handleRefresh = newQuery => { + const { location, dispatch } = this.props + const { query, pathname } = location + const payload = { + ...query, + ...newQuery, + } + dispatch({ + type: 'user/query', + payload, + }) + router.push({ + pathname, + search: stringify(payload, { arrayFormat: 'repeat' }), + }) + } + render() { const { location, dispatch, user, loading, i18n } = this.props - const { query, pathname } = location + const { query } = location const { list, pagination, @@ -25,19 +46,6 @@ class User extends PureComponent { selectedRowKeys, } = user - const handleRefresh = newQuery => { - router.push({ - pathname, - search: stringify( - { - ...query, - ...newQuery, - }, - { arrayFormat: 'repeat' } - ), - }) - } - const modalProps = { item: modalType === 'create' ? {} : currentItem, visible: modalVisible, @@ -52,7 +60,7 @@ class User extends PureComponent { type: `user/${modalType}`, payload: data, }).then(() => { - handleRefresh() + this.handleRefresh() }) }, onCancel() { @@ -66,8 +74,8 @@ class User extends PureComponent { dataSource: list, loading: loading.effects['user/query'], pagination, - onChange(page) { - handleRefresh({ + onChange: page => { + this.handleRefresh({ page: page.current, pageSize: page.pageSize, }) @@ -77,7 +85,7 @@ class User extends PureComponent { type: 'user/delete', payload: id, }).then(() => { - handleRefresh({ + this.handleRefresh({ page: list.length === 1 && pagination.current > 1 ? pagination.current - 1 @@ -111,10 +119,9 @@ class User extends PureComponent { filter: { ...query, }, - onFilterChange(value) { - handleRefresh({ + onFilterChange: value => { + this.handleRefresh({ ...value, - page: 1, }) }, onAdd() { @@ -134,7 +141,7 @@ class User extends PureComponent { ids: selectedRowKeys, }, }).then(() => { - handleRefresh({ + this.handleRefresh({ page: list.length === selectedRowKeys.length && pagination.current > 1 ? pagination.current - 1 diff --git a/src/pages/user/model.js b/src/pages/user/model.js index 7c27989..d774c8b 100644 --- a/src/pages/user/model.js +++ b/src/pages/user/model.js @@ -22,20 +22,6 @@ export default modelExtend(pageModel, { selectedRowKeys: [], }, - subscriptions: { - setup({ dispatch, history }) { - history.listen(location => { - if (pathMatchRegexp('/user', location.pathname)) { - const payload = location.query || { page: 1, pageSize: 10 } - dispatch({ - type: 'query', - payload, - }) - } - }) - }, - }, - effects: { *query({ payload = {} }, { call, put }) { const data = yield call(queryUserList, payload) diff --git a/src/utils/request.js b/src/utils/request.js index f3f070c..cc28a3f 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -33,11 +33,8 @@ export default function request(options) { message.error(e.message) } - options.url = - method.toLocaleLowerCase() === 'get' - ? `${url}${isEmpty(cloneData) ? '' : '?'}${qs.stringify(cloneData)}` - : url - + options.url = url + options.params = cloneData options.cancelToken = new CancelToken(cancel => { window.cancelRequest.set(Symbol(Date.now()), { pathname: window.location.pathname,