|
|
@@ -1,6 +1,8 @@
|
|
|
-import { queryCurrentUser } from './services/user'
|
|
|
+import { queryCurrentUser, queryPermData } from './services/user'
|
|
|
import { history } from 'umi'
|
|
|
import RightContent from '@/components/RightContent'
|
|
|
+import { PERMISSION_NEED_PATH } from './utils/consts/customer'
|
|
|
+import { message } from 'antd'
|
|
|
|
|
|
const loginPath = '/user/login'
|
|
|
|
|
|
@@ -15,36 +17,53 @@ export async function getInitialState() {
|
|
|
}
|
|
|
return undefined
|
|
|
}
|
|
|
+
|
|
|
+ const fetchPermData = async () => {
|
|
|
+ try {
|
|
|
+ const res = await queryPermData()
|
|
|
+ return res.data
|
|
|
+ } catch (error) {
|
|
|
+ message.error('获取数据权限失败,请联系管理员')
|
|
|
+ }
|
|
|
+ return undefined
|
|
|
+ }
|
|
|
// 如果是登录页面,不执行
|
|
|
if (history.location.pathname !== loginPath) {
|
|
|
const currentUser = (await fetchUserInfo()) || {}
|
|
|
|
|
|
return {
|
|
|
fetchUserInfo,
|
|
|
+ fetchPermData,
|
|
|
...currentUser,
|
|
|
settings: {}
|
|
|
}
|
|
|
}
|
|
|
return {
|
|
|
fetchUserInfo,
|
|
|
+ fetchPermData,
|
|
|
settings: {}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export const layout = ({ initialState }) => {
|
|
|
+export const layout = ({ initialState, setInitialState }) => {
|
|
|
return {
|
|
|
rightContentRender: () => <RightContent />,
|
|
|
disableContentMargin: false,
|
|
|
waterMarkProps: {
|
|
|
content: initialState?.currentUser?.username
|
|
|
},
|
|
|
- // onPageChange: () => {
|
|
|
- // const { location } = history
|
|
|
- // // 如果没有登录,重定向到 login
|
|
|
- // if (initialState?.currentUser?.staffId && location.pathname !== loginPath) {
|
|
|
- // history.push(loginPath)
|
|
|
- // }
|
|
|
- // },
|
|
|
+ onPageChange: async () => {
|
|
|
+ const { location } = history
|
|
|
+ // 如果没有登录,重定向到 login
|
|
|
+ if (
|
|
|
+ initialState?.currentUser?.staffId &&
|
|
|
+ location.pathname !== loginPath &&
|
|
|
+ PERMISSION_NEED_PATH.includes(location.pathname)
|
|
|
+ ) {
|
|
|
+ const permData = await initialState.fetchPermData()
|
|
|
+ permData && setInitialState({ ...initialState, permData })
|
|
|
+ }
|
|
|
+ },
|
|
|
// menuHeaderRender: false,
|
|
|
...initialState?.settings
|
|
|
}
|