mirror of
https://github.com/zuiidea/antd-admin
synced 2026-11-01 23:43:55 +00:00
refactor user, menu, permission storage strategy then make full loader unnecessary
This commit is contained in:
@@ -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
@@ -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
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user