From d6250f16b02ea32457ec622a8e8da25c90a42dab Mon Sep 17 00:00:00 2001 From: lovemegowin Date: Fri, 21 Jun 2019 14:12:15 +0800 Subject: [PATCH 1/4] fullScreen loader is not always necessary refactor default spinning to false --- src/components/Loader/Loader.js | 2 +- src/models/app.js | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/components/Loader/Loader.js b/src/components/Loader/Loader.js index 29abe44..5a5a021 100644 --- a/src/components/Loader/Loader.js +++ b/src/components/Loader/Loader.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types' import classNames from 'classnames' import styles from './Loader.less' -const Loader = ({ spinning = true, fullScreen }) => { +const Loader = ({ spinning = false, fullScreen }) => { return (
Date: Fri, 21 Jun 2019 15:23:19 +0800 Subject: [PATCH 2/4] add null point assert --- src/components/Layout/Bread.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/Layout/Bread.js b/src/components/Layout/Bread.js index db202f5..268890c 100644 --- a/src/components/Layout/Bread.js +++ b/src/components/Layout/Bread.js @@ -12,7 +12,7 @@ import styles from './Bread.less' class Bread extends PureComponent { generateBreadcrumbs = paths => { return paths.map((item, key) => { - const content = ( + const content = item && ( {item.icon ? ( @@ -22,13 +22,15 @@ class Bread extends PureComponent { ) return ( - - {paths.length - 1 !== key ? ( - {content} - ) : ( - content - )} - + item && ( + + {paths.length - 1 !== key ? ( + {content} + ) : ( + content + )} + + ) ) }) } From a29d761483fb03faf1d73ab8c9a7993d5c3174d0 Mon Sep 17 00:00:00 2001 From: lovemegowin Date: Fri, 21 Jun 2019 15:26:06 +0800 Subject: [PATCH 3/4] refactor user, menu, permission storage strategy then make full loader unnecessary --- src/layouts/PrimaryLayout.js | 13 +++++-------- src/models/app.js | 34 ++++++---------------------------- src/pages/dashboard/index.js | 9 ++++----- 3 files changed, 15 insertions(+), 41 deletions(-) diff --git a/src/layouts/PrimaryLayout.js b/src/layouts/PrimaryLayout.js index 8a5df9b..978598f 100644 --- a/src/layouts/PrimaryLayout.js +++ b/src/layouts/PrimaryLayout.js @@ -11,6 +11,7 @@ import { enquireScreen, unenquireScreen } from 'enquire-js' import { config, pathMatchRegexp, langFromPath } from 'utils' import Error from '../pages/404' import styles from './PrimaryLayout.less' +import store from 'store' const { Content } = Layout const { Header, Bread, Sider } = MyLayout @@ -46,14 +47,10 @@ class PrimaryLayout extends PureComponent { render() { const { app, location, dispatch, children } = this.props - const { - user, - theme, - routeList, - collapsed, - permissions, - notifications, - } = app + const { theme, collapsed, notifications } = app + const user = store.get('user') || {} + const permissions = store.get('permissions') || {} + const routeList = store.get('routeList') || [] const { isMobile } = this.state const { onCollapseChange } = this diff --git a/src/models/app.js b/src/models/app.js index ad0837a..85b82d2 100644 --- a/src/models/app.js +++ b/src/models/app.js @@ -14,10 +14,6 @@ const { queryRouteList, logoutUser, queryUserInfo } = api export default { namespace: 'app', state: { - user: {}, - permissions: { - visit: [], - }, routeList: [ { id: '1', @@ -94,14 +90,9 @@ export default { return cases.every(_ => _) }) } - yield put({ - type: 'updateState', - payload: { - user, - permissions, - routeList, - }, - }) + store.set('routeList', routeList) + store.set('permissions', permissions) + store.set('user', user) if (pathMatchRegexp(['/', '/login'], window.location.pathname)) { router.push({ pathname: '/dashboard', @@ -120,22 +111,9 @@ export default { *signOut({ payload }, { call, put }) { const data = yield call(logoutUser) if (data.success) { - yield put({ - type: 'updateState', - payload: { - user: {}, - permissions: { visit: [] }, - menu: [ - { - id: '1', - icon: 'laptop', - name: 'Dashboard', - zhName: '仪表盘', - router: '/dashboard', - }, - ], - }, - }) + store.set('routeList', []) + store.set('permissions', { visit: [] }) + store.set('user', {}) yield put({ type: 'query' }) } else { throw data diff --git a/src/pages/dashboard/index.js b/src/pages/dashboard/index.js index 72a76c9..a010f29 100644 --- a/src/pages/dashboard/index.js +++ b/src/pages/dashboard/index.js @@ -17,6 +17,7 @@ import { User, } from './components' import styles from './index.less' +import store from 'store' const bodyStyle = { bodyStyle: { @@ -26,14 +27,14 @@ const bodyStyle = { } @connect(({ app, dashboard, loading }) => ({ - avatar: app.user.avatar, - username: app.user.username, dashboard, loading, })) class Dashboard extends PureComponent { render() { - const { avatar, username, dashboard, loading } = this.props + const userDetail = store.get('user') + const { avatar, username } = userDetail + const { dashboard, loading } = this.props const { weather, sales, @@ -154,8 +155,6 @@ class Dashboard extends PureComponent { } Dashboard.propTypes = { - avatar: PropTypes.string, - username: PropTypes.string, dashboard: PropTypes.object, loading: PropTypes.object, } From df82ee42fdd87d84f8f17461e959ebb5904f6494 Mon Sep 17 00:00:00 2001 From: lovemegowin Date: Mon, 24 Jun 2019 15:20:25 +0800 Subject: [PATCH 4/4] fix #985 , close #985 --- src/pages/user/components/Filter.js | 5 --- src/pages/user/index.js | 51 ++++++++++++++++------------- src/pages/user/model.js | 14 -------- src/utils/request.js | 7 ++-- 4 files changed, 31 insertions(+), 46 deletions(-) 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,