Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
c2fe4009
Commit
c2fe4009
authored
Aug 29, 2018
by
afc163
Committed by
偏右
Aug 30, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove LoadingPage
parent
c93b0169
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
125 deletions
+63
-125
config/router.config.js
config/router.config.js
+1
-1
src/layouts/BasicLayout.js
src/layouts/BasicLayout.js
+62
-15
src/layouts/LoadingPage.js
src/layouts/LoadingPage.js
+0
-109
No files found.
config/router.config.js
View file @
c2fe4009
...
@@ -13,7 +13,7 @@ module.exports = [
...
@@ -13,7 +13,7 @@ module.exports = [
// app
// app
{
{
path
:
'
/
'
,
path
:
'
/
'
,
component
:
'
../layouts/
LoadingPage
'
,
component
:
'
../layouts/
BasicLayout
'
,
routes
:
[
routes
:
[
// dashboard
// dashboard
{
path
:
'
/
'
,
redirect
:
'
/dashboard/analysis
'
},
{
path
:
'
/
'
,
redirect
:
'
/dashboard/analysis
'
},
...
...
src/layouts/BasicLayout.js
View file @
c2fe4009
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
{
Layout
}
from
'
antd
'
;
import
{
Layout
}
from
'
antd
'
;
import
DocumentTitle
from
'
react-document-title
'
;
import
DocumentTitle
from
'
react-document-title
'
;
import
deep
Equal
from
'
lodash/isEqual
'
;
import
is
Equal
from
'
lodash/isEqual
'
;
import
memoizeOne
from
'
memoize-one
'
;
import
memoizeOne
from
'
memoize-one
'
;
import
{
connect
}
from
'
dva
'
;
import
{
connect
}
from
'
dva
'
;
import
{
ContainerQuery
}
from
'
react-container-query
'
;
import
{
ContainerQuery
}
from
'
react-container-query
'
;
import
classNames
from
'
classnames
'
;
import
classNames
from
'
classnames
'
;
import
pathToRegexp
from
'
path-to-regexp
'
;
import
pathToRegexp
from
'
path-to-regexp
'
;
import
{
enquireScreen
,
unenquireScreen
}
from
'
enquire-js
'
;
import
{
formatMessage
}
from
'
umi/locale
'
;
import
{
formatMessage
}
from
'
umi/locale
'
;
import
SiderMenu
from
'
@/components/SiderMenu
'
;
import
SiderMenu
from
'
@/components/SiderMenu
'
;
import
Authorized
from
'
@/utils/Authorized
'
;
import
Authorized
from
'
@/utils/Authorized
'
;
...
@@ -15,28 +16,59 @@ import logo from '../assets/logo.svg';
...
@@ -15,28 +16,59 @@ import logo from '../assets/logo.svg';
import
Footer
from
'
./Footer
'
;
import
Footer
from
'
./Footer
'
;
import
Header
from
'
./Header
'
;
import
Header
from
'
./Header
'
;
import
Context
from
'
./MenuContext
'
;
import
Context
from
'
./MenuContext
'
;
// TODO: should use this.props.routes
import
routerConfig
from
'
../../config/router.config
'
;
const
{
Content
}
=
Layout
;
const
{
Content
}
=
Layout
;
const
{
check
}
=
Authorized
;
const
{
check
}
=
Authorized
;
// Conversion router to menu.
function
formatter
(
data
,
parentPath
=
''
,
parentAuthority
,
parentName
)
{
return
data
.
map
(
item
=>
{
let
locale
=
'
menu
'
;
if
(
parentName
&&
item
.
name
)
{
locale
=
`
${
parentName
}
.
${
item
.
name
}
`
;
}
else
if
(
item
.
name
)
{
locale
=
`menu.
${
item
.
name
}
`
;
}
else
if
(
parentName
)
{
locale
=
parentName
;
}
const
result
=
{
...
item
,
locale
,
authority
:
item
.
authority
||
parentAuthority
,
};
if
(
item
.
routes
)
{
const
children
=
formatter
(
item
.
routes
,
`
${
parentPath
}${
item
.
path
}
/`
,
item
.
authority
,
locale
);
// Reduce memory usage
result
.
children
=
children
;
}
delete
result
.
routes
;
return
result
;
});
}
// get menu map data
const
menuData
=
formatter
(
routerConfig
[
1
].
routes
);
/**
/**
* 获取面包屑映射
* 获取面包屑映射
* @param {Object} menuData 菜单配置
* @param {Object} menuData 菜单配置
*/
*/
const
getBreadcrumbNameMap
=
memoizeOne
(
me
un
=>
{
const
getBreadcrumbNameMap
=
memoizeOne
(
me
nu
=>
{
const
routerMap
=
{};
const
routerMap
=
{};
const
mergeMe
unAndRouter
=
meunData
=>
{
const
mergeMe
nuAndRouter
=
()
=>
{
me
unData
.
forEach
(
meun
Item
=>
{
me
nuData
.
forEach
(
menu
Item
=>
{
if
(
me
un
Item
.
children
)
{
if
(
me
nu
Item
.
children
)
{
mergeMe
unAndRouter
(
meun
Item
.
children
);
mergeMe
nuAndRouter
(
menu
Item
.
children
);
}
}
// Reduce memory usage
// Reduce memory usage
routerMap
[
me
unItem
.
path
]
=
meun
Item
;
routerMap
[
me
nuItem
.
path
]
=
menu
Item
;
});
});
};
};
mergeMe
unAndRouter
(
meun
);
mergeMe
nuAndRouter
(
menu
);
return
routerMap
;
return
routerMap
;
},
deep
Equal
);
},
is
Equal
);
const
query
=
{
const
query
=
{
'
screen-xs
'
:
{
'
screen-xs
'
:
{
...
@@ -66,31 +98,47 @@ const query = {
...
@@ -66,31 +98,47 @@ const query = {
class
BasicLayout
extends
React
.
PureComponent
{
class
BasicLayout
extends
React
.
PureComponent
{
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
);
super
(
props
);
const
{
menuData
}
=
this
.
props
;
this
.
getPageTitle
=
memoizeOne
(
this
.
getPageTitle
);
this
.
getPageTitle
=
memoizeOne
(
this
.
getPageTitle
);
// Because there are many places to be. So put it here
// Because there are many places to be. So put it here
this
.
breadcrumbNameMap
=
getBreadcrumbNameMap
(
menuData
);
this
.
breadcrumbNameMap
=
getBreadcrumbNameMap
();
console
.
log
(
this
.
breadcrumbNameMap
);
}
}
state
=
{
state
=
{
rendering
:
true
,
rendering
:
true
,
isMobile
:
false
,
};
};
componentDidMount
()
{
componentDidMount
()
{
const
{
dispatch
}
=
this
.
props
;
dispatch
({
type
:
'
user/fetchCurrent
'
,
});
dispatch
({
type
:
'
setting/getSetting
'
,
});
this
.
renderRef
=
requestAnimationFrame
(()
=>
{
this
.
renderRef
=
requestAnimationFrame
(()
=>
{
this
.
setState
({
this
.
setState
({
rendering
:
false
,
rendering
:
false
,
});
});
});
});
this
.
enquireHandler
=
enquireScreen
(
mobile
=>
{
const
{
isMobile
}
=
this
.
state
;
if
(
isMobile
!==
mobile
)
{
this
.
setState
({
isMobile
:
mobile
,
});
}
});
}
}
componentDidUpdate
()
{
componentDidUpdate
()
{
const
{
menuData
}
=
this
.
props
;
this
.
breadcrumbNameMap
=
getBreadcrumbNameMap
();
this
.
breadcrumbNameMap
=
getBreadcrumbNameMap
(
menuData
);
}
}
componentWillUnmount
()
{
componentWillUnmount
()
{
cancelAnimationFrame
(
this
.
renderRef
);
cancelAnimationFrame
(
this
.
renderRef
);
unenquireScreen
(
this
.
enquireHandler
);
}
}
getContext
()
{
getContext
()
{
...
@@ -168,13 +216,12 @@ class BasicLayout extends React.PureComponent {
...
@@ -168,13 +216,12 @@ class BasicLayout extends React.PureComponent {
render
()
{
render
()
{
const
{
const
{
isMobile
,
silderTheme
,
silderTheme
,
layout
:
PropsLayout
,
layout
:
PropsLayout
,
children
,
children
,
location
:
{
pathname
},
location
:
{
pathname
},
}
=
this
.
props
;
}
=
this
.
props
;
const
{
rendering
}
=
this
.
state
;
const
{
rendering
,
isMobile
}
=
this
.
state
;
const
isTop
=
PropsLayout
===
'
topmenu
'
;
const
isTop
=
PropsLayout
===
'
topmenu
'
;
const
layout
=
(
const
layout
=
(
<
Layout
>
<
Layout
>
...
...
src/layouts/LoadingPage.js
deleted
100644 → 0
View file @
c93b0169
import
React
,
{
PureComponent
}
from
'
react
'
;
import
{
Spin
}
from
'
antd
'
;
import
{
connect
}
from
'
dva
'
;
import
{
enquireScreen
,
unenquireScreen
}
from
'
enquire-js
'
;
import
BasicLayout
from
'
./BasicLayout
'
;
// TODO: should use this.props.routes
import
routerConfig
from
'
../../config/router.config
'
;
// Conversion router to menu.
function
formatter
(
data
,
parentPath
=
''
,
parentAuthority
,
parentName
)
{
return
data
.
map
(
item
=>
{
let
locale
=
'
menu
'
;
if
(
parentName
&&
item
.
name
)
{
locale
=
`
${
parentName
}
.
${
item
.
name
}
`
;
}
else
if
(
item
.
name
)
{
locale
=
`menu.
${
item
.
name
}
`
;
}
else
if
(
parentName
)
{
locale
=
parentName
;
}
const
result
=
{
...
item
,
locale
,
authority
:
item
.
authority
||
parentAuthority
,
};
if
(
item
.
routes
)
{
const
children
=
formatter
(
item
.
routes
,
`
${
parentPath
}${
item
.
path
}
/`
,
item
.
authority
,
locale
);
// Reduce memory usage
result
.
children
=
children
;
}
delete
result
.
routes
;
return
result
;
});
}
// get meun map data
const
MenuData
=
formatter
(
routerConfig
[
1
].
routes
);
class
LoadingPage
extends
PureComponent
{
state
=
{
loading
:
true
,
isMobile
:
false
,
};
componentDidMount
()
{
const
{
dispatch
}
=
this
.
props
;
this
.
enquireHandler
=
enquireScreen
(
mobile
=>
{
const
{
isMobile
}
=
this
.
state
;
if
(
isMobile
!==
mobile
)
{
this
.
setState
({
isMobile
:
mobile
,
});
}
});
dispatch
({
type
:
'
user/fetchCurrent
'
,
});
this
.
hideLoading
();
this
.
initSetting
();
}
componentWillUnmount
()
{
unenquireScreen
(
this
.
enquireHandler
);
}
hideLoading
()
{
this
.
setState
({
loading
:
false
,
});
}
/**
* get setting from url params
*/
initSetting
()
{
const
{
dispatch
}
=
this
.
props
;
dispatch
({
type
:
'
setting/getSetting
'
,
});
}
render
()
{
const
{
loading
,
isMobile
}
=
this
.
state
;
if
(
loading
)
{
return
(
<
div
style
=
{{
width
:
'
100%
'
,
height
:
'
100%
'
,
margin
:
'
auto
'
,
paddingTop
:
50
,
textAlign
:
'
center
'
,
}}
>
<
Spin
size
=
"
large
"
/>
<
/div
>
);
}
return
(
<
BasicLayout
isMobile
=
{
isMobile
}
menuData
=
{
MenuData
}
routerData
=
{
routerConfig
}
redirectData
=
{[]}
{...
this
.
props
}
/
>
);
}
}
export
default
connect
()(
LoadingPage
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment