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
P
pro-blocks
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
pro-blocks
Commits
2fb922d8
Commit
2fb922d8
authored
Dec 29, 2017
by
afc163
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
take dispatch outside the component, close #528
parent
c1366eb2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
82 deletions
+68
-82
src/components/GlobalHeader/index.js
src/components/GlobalHeader/index.js
+14
-41
src/components/SiderMenu/index.js
src/components/SiderMenu/index.js
+15
-36
src/layouts/BasicLayout.js
src/layouts/BasicLayout.js
+39
-5
No files found.
src/components/GlobalHeader/index.js
View file @
2fb922d8
import
React
,
{
PureComponent
}
from
'
react
'
;
import
React
,
{
PureComponent
}
from
'
react
'
;
import
{
Layout
,
Menu
,
Icon
,
Spin
,
Tag
,
Dropdown
,
Avatar
,
message
,
Divider
}
from
'
antd
'
;
import
{
Layout
,
Menu
,
Icon
,
Spin
,
Tag
,
Dropdown
,
Avatar
,
Divider
}
from
'
antd
'
;
import
moment
from
'
moment
'
;
import
moment
from
'
moment
'
;
import
groupBy
from
'
lodash/groupBy
'
;
import
groupBy
from
'
lodash/groupBy
'
;
import
Debounce
from
'
lodash-decorators/debounce
'
;
import
Debounce
from
'
lodash-decorators/debounce
'
;
import
{
Link
}
from
'
dva/router
'
;
import
{
Link
}
from
'
dva/router
'
;
import
NoticeIcon
from
'
../../components/NoticeIcon
'
;
import
NoticeIcon
from
'
../../components/NoticeIcon
'
;
import
HeaderSearch
from
'
../../components/HeaderSearch
'
;
import
HeaderSearch
from
'
../../components/HeaderSearch
'
;
import
logo
from
'
../../assets/logo.svg
'
;
import
styles
from
'
./index.less
'
;
import
styles
from
'
./index.less
'
;
const
{
Header
}
=
Layout
;
const
{
Header
}
=
Layout
;
export
default
class
GlobalHeader
extends
PureComponent
{
export
default
class
GlobalHeader
extends
PureComponent
{
componentDidMount
()
{
this
.
props
.
dispatch
({
type
:
'
user/fetchCurrent
'
,
});
}
componentWillUnmount
()
{
componentWillUnmount
()
{
this
.
triggerResizeEvent
.
cancel
();
this
.
triggerResizeEvent
.
cancel
();
}
}
...
@@ -47,33 +41,9 @@ export default class GlobalHeader extends PureComponent {
...
@@ -47,33 +41,9 @@ export default class GlobalHeader extends PureComponent {
});
});
return
groupBy
(
newNotices
,
'
type
'
);
return
groupBy
(
newNotices
,
'
type
'
);
}
}
handleNoticeClear
=
(
type
)
=>
{
message
.
success
(
`清空了
${
type
}
`
);
this
.
props
.
dispatch
({
type
:
'
global/clearNotices
'
,
payload
:
type
,
});
}
handleNoticeVisibleChange
=
(
visible
)
=>
{
if
(
visible
)
{
this
.
props
.
dispatch
({
type
:
'
global/fetchNotices
'
,
});
}
}
handleMenuClick
=
({
key
})
=>
{
if
(
key
===
'
logout
'
)
{
this
.
props
.
dispatch
({
type
:
'
login/logout
'
,
});
}
}
toggle
=
()
=>
{
toggle
=
()
=>
{
const
{
collapsed
}
=
this
.
props
;
const
{
collapsed
,
onCollapse
}
=
this
.
props
;
this
.
props
.
dispatch
({
onCollapse
(
!
collapsed
);
type
:
'
global/changeLayoutCollapsed
'
,
payload
:
!
collapsed
,
});
this
.
triggerResizeEvent
();
this
.
triggerResizeEvent
();
}
}
@
Debounce
(
600
)
@
Debounce
(
600
)
...
@@ -84,10 +54,11 @@ export default class GlobalHeader extends PureComponent {
...
@@ -84,10 +54,11 @@ export default class GlobalHeader extends PureComponent {
}
}
render
()
{
render
()
{
const
{
const
{
currentUser
,
collapsed
,
fetchingNotices
,
isMobile
,
currentUser
,
collapsed
,
fetchingNotices
,
isMobile
,
logo
,
onNoticeVisibleChange
,
onMenuClick
,
onNoticeClear
,
}
=
this
.
props
;
}
=
this
.
props
;
const
menu
=
(
const
menu
=
(
<
Menu
className
=
{
styles
.
menu
}
selectedKeys
=
{[]}
onClick
=
{
this
.
handle
MenuClick
}
>
<
Menu
className
=
{
styles
.
menu
}
selectedKeys
=
{[]}
onClick
=
{
on
MenuClick
}
>
<
Menu
.
Item
disabled
><
Icon
type
=
"
user
"
/>
个人中心
<
/Menu.Item
>
<
Menu
.
Item
disabled
><
Icon
type
=
"
user
"
/>
个人中心
<
/Menu.Item
>
<
Menu
.
Item
disabled
><
Icon
type
=
"
setting
"
/>
设置
<
/Menu.Item
>
<
Menu
.
Item
disabled
><
Icon
type
=
"
setting
"
/>
设置
<
/Menu.Item
>
<
Menu
.
Divider
/>
<
Menu
.
Divider
/>
...
@@ -98,10 +69,12 @@ export default class GlobalHeader extends PureComponent {
...
@@ -98,10 +69,12 @@ export default class GlobalHeader extends PureComponent {
return
(
return
(
<
Header
className
=
{
styles
.
header
}
>
<
Header
className
=
{
styles
.
header
}
>
{
isMobile
&&
(
{
isMobile
&&
(
[(
[
(
<
Link
to
=
"
/
"
className
=
{
styles
.
logo
}
key
=
"
logo
"
>
<
Link
to
=
"
/
"
className
=
{
styles
.
logo
}
key
=
"
logo
"
>
<
img
src
=
{
logo
}
alt
=
"
logo
"
width
=
"
32
"
/>
<
img
src
=
{
logo
}
alt
=
"
logo
"
width
=
"
32
"
/>
<
/Link>
)
,
<
/Link
>
),
<
Divider
type
=
"
vertical
"
key
=
"
line
"
/>
,
<
Divider
type
=
"
vertical
"
key
=
"
line
"
/>
,
]
]
)}
)}
...
@@ -128,8 +101,8 @@ export default class GlobalHeader extends PureComponent {
...
@@ -128,8 +101,8 @@ export default class GlobalHeader extends PureComponent {
onItemClick
=
{(
item
,
tabProps
)
=>
{
onItemClick
=
{(
item
,
tabProps
)
=>
{
console
.
log
(
item
,
tabProps
);
// eslint-disable-line
console
.
log
(
item
,
tabProps
);
// eslint-disable-line
}}
}}
onClear
=
{
this
.
handle
NoticeClear
}
onClear
=
{
on
NoticeClear
}
onPopupVisibleChange
=
{
this
.
handle
NoticeVisibleChange
}
onPopupVisibleChange
=
{
on
NoticeVisibleChange
}
loading
=
{
fetchingNotices
}
loading
=
{
fetchingNotices
}
popupAlign
=
{{
offset
:
[
20
,
-
16
]
}}
popupAlign
=
{{
offset
:
[
20
,
-
16
]
}}
>
>
...
...
src/components/SiderMenu/index.js
View file @
2fb922d8
import
'
rc-drawer-menu/assets/index.css
'
;
import
'
rc-drawer-menu/assets/index.css
'
;
import
React
,
{
PureComponent
}
from
'
react
'
;
import
React
from
'
react
'
;
import
DrawerMenu
from
'
rc-drawer-menu
'
;
import
DrawerMenu
from
'
rc-drawer-menu
'
;
import
SiderMenu
from
'
./SiderMenu
'
;
import
SiderMenu
from
'
./SiderMenu
'
;
export
default
class
Index
extends
PureComponent
{
export
default
props
=>
(
onCollapse
=
(
collapsed
)
=>
{
props
.
isMobile
?
(
this
.
props
.
dispatch
({
type
:
'
global/changeLayoutCollapsed
'
,
payload
:
collapsed
,
});
}
render
()
{
const
{
collapsed
,
isMobile
}
=
this
.
props
;
return
isMobile
?
(
<
DrawerMenu
<
DrawerMenu
parent
=
{
null
}
parent
=
{
null
}
level
=
{
null
}
level
=
{
null
}
iconChild
=
{
null
}
iconChild
=
{
null
}
open
=
{
!
collapsed
}
open
=
{
!
props
.
collapsed
}
onMaskClick
=
{()
=>
{
thi
s
.
onCollapse
(
true
);
}}
onMaskClick
=
{()
=>
{
prop
s
.
onCollapse
(
true
);
}}
width
=
"
256px
"
width
=
"
256px
"
>
>
<
SiderMenu
<
SiderMenu
{...
props
}
collapsed
=
{
props
.
isMobile
?
false
:
props
.
collapsed
}
/
>
{...
this
.
props
}
isMobile
=
{
isMobile
}
onCollapse
=
{
this
.
onCollapse
}
collapsed
=
{
isMobile
?
false
:
collapsed
}
/
>
<
/DrawerMenu
>
<
/DrawerMenu
>
)
:
(
)
:
<
SiderMenu
{...
props
}
/
>
<
SiderMenu
);
{...
this
.
props
}
isMobile
=
{
isMobile
}
onCollapse
=
{
this
.
onCollapse
}
/
>
);
}
}
src/layouts/BasicLayout.js
View file @
2fb922d8
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
PropTypes
from
'
prop-types
'
;
import
PropTypes
from
'
prop-types
'
;
import
{
Layout
,
Icon
}
from
'
antd
'
;
import
{
Layout
,
Icon
,
message
}
from
'
antd
'
;
import
DocumentTitle
from
'
react-document-title
'
;
import
DocumentTitle
from
'
react-document-title
'
;
import
{
connect
}
from
'
dva
'
;
import
{
connect
}
from
'
dva
'
;
import
{
Route
,
Redirect
,
Switch
}
from
'
dva/router
'
;
import
{
Route
,
Redirect
,
Switch
}
from
'
dva/router
'
;
...
@@ -13,7 +13,7 @@ import SiderMenu from '../components/SiderMenu';
...
@@ -13,7 +13,7 @@ import SiderMenu from '../components/SiderMenu';
import
NotFound
from
'
../routes/Exception/404
'
;
import
NotFound
from
'
../routes/Exception/404
'
;
import
{
getRoutes
}
from
'
../utils/utils
'
;
import
{
getRoutes
}
from
'
../utils/utils
'
;
import
{
getMenuData
}
from
'
../common/menu
'
;
import
{
getMenuData
}
from
'
../common/menu
'
;
import
logo
from
'
../assets/logo.svg
'
;
/**
/**
* 根据菜单取得重定向地址.
* 根据菜单取得重定向地址.
...
@@ -82,6 +82,9 @@ class BasicLayout extends React.PureComponent {
...
@@ -82,6 +82,9 @@ class BasicLayout extends React.PureComponent {
isMobile
:
mobile
,
isMobile
:
mobile
,
});
});
});
});
this
.
props
.
dispatch
({
type
:
'
user/fetchCurrent
'
,
});
}
}
getPageTitle
()
{
getPageTitle
()
{
const
{
routerData
,
location
}
=
this
.
props
;
const
{
routerData
,
location
}
=
this
.
props
;
...
@@ -92,26 +95,57 @@ class BasicLayout extends React.PureComponent {
...
@@ -92,26 +95,57 @@ class BasicLayout extends React.PureComponent {
}
}
return
title
;
return
title
;
}
}
handleMenuCollapse
=
(
collapsed
)
=>
{
this
.
props
.
dispatch
({
type
:
'
global/changeLayoutCollapsed
'
,
payload
:
collapsed
,
});
}
handleNoticeClear
=
(
type
)
=>
{
message
.
success
(
`清空了
${
type
}
`
);
this
.
props
.
dispatch
({
type
:
'
global/clearNotices
'
,
payload
:
type
,
});
}
handleMenuClick
=
({
key
})
=>
{
if
(
key
===
'
logout
'
)
{
this
.
props
.
dispatch
({
type
:
'
login/logout
'
,
});
}
}
handleNoticeVisibleChange
=
(
visible
)
=>
{
if
(
visible
)
{
this
.
props
.
dispatch
({
type
:
'
global/fetchNotices
'
,
});
}
}
render
()
{
render
()
{
const
{
const
{
currentUser
,
collapsed
,
fetchingNotices
,
notices
,
routerData
,
match
,
location
,
dispatch
,
currentUser
,
collapsed
,
fetchingNotices
,
notices
,
routerData
,
match
,
location
,
}
=
this
.
props
;
}
=
this
.
props
;
const
layout
=
(
const
layout
=
(
<
Layout
>
<
Layout
>
<
SiderMenu
<
SiderMenu
collapsed
=
{
collapsed
}
collapsed
=
{
collapsed
}
location
=
{
location
}
location
=
{
location
}
dispatch
=
{
dispatch
}
isMobile
=
{
this
.
state
.
isMobile
}
isMobile
=
{
this
.
state
.
isMobile
}
onCollapse
=
{
this
.
handleMenuCollapse
}
/
>
/
>
<
Layout
>
<
Layout
>
<
GlobalHeader
<
GlobalHeader
logo
=
{
logo
}
currentUser
=
{
currentUser
}
currentUser
=
{
currentUser
}
fetchingNotices
=
{
fetchingNotices
}
fetchingNotices
=
{
fetchingNotices
}
notices
=
{
notices
}
notices
=
{
notices
}
collapsed
=
{
collapsed
}
collapsed
=
{
collapsed
}
dispatch
=
{
dispatch
}
isMobile
=
{
this
.
state
.
isMobile
}
isMobile
=
{
this
.
state
.
isMobile
}
onNoticeClear
=
{
this
.
handleNoticeClear
}
onCollapse
=
{
this
.
handleMenuCollapse
}
onMenuClick
=
{
this
.
handleMenuClick
}
onNoticeVisibleChange
=
{
this
.
handleNoticeVisibleChange
}
/
>
/
>
<
Content
style
=
{{
margin
:
'
24px 24px 0
'
,
height
:
'
100%
'
}}
>
<
Content
style
=
{{
margin
:
'
24px 24px 0
'
,
height
:
'
100%
'
}}
>
<
div
style
=
{{
minHeight
:
'
calc(100vh - 260px)
'
}}
>
<
div
style
=
{{
minHeight
:
'
calc(100vh - 260px)
'
}}
>
...
...
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