refactor user, menu, permission storage strategy then make full loader unnecessary

This commit is contained in:
lovemegowin
2019-06-21 15:26:06 +08:00
parent 713a86b9d6
commit a29d761483
3 changed files with 15 additions and 41 deletions
+5 -8
View File
@@ -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
+6 -28
View File
@@ -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
+4 -5
View File
@@ -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,
}