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
123401a9
Commit
123401a9
authored
Jun 18, 2018
by
陈帅
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize the Breadcrumb
parent
93cc3870
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
26 deletions
+42
-26
src/components/PageHeader/index.js
src/components/PageHeader/index.js
+22
-14
src/components/PageHeader/index.md
src/components/PageHeader/index.md
+1
-0
src/pages/layouts/BasicLayout.js
src/pages/layouts/BasicLayout.js
+13
-12
src/pages/layouts/PageHeaderLayout.js
src/pages/layouts/PageHeaderLayout.js
+6
-0
No files found.
src/components/PageHeader/index.js
View file @
123401a9
...
...
@@ -60,21 +60,25 @@ export default class PageHeader extends PureComponent {
// Generated according to props
conversionFromProps
=
()
=>
{
const
{
breadcrumbList
,
breadcrumbSeparator
,
linkElement
=
'
a
'
}
=
this
.
props
;
return
(
<
Breadcrumb
className
=
{
styles
.
breadcrumb
}
separator
=
{
breadcrumbSeparator
}
>
{
breadcrumbList
.
map
(
item
=>
(
<
Breadcrumb
.
Item
key
=
{
item
.
title
}
>
{
item
.
href
?
createElement
(
linkElement
,
{
[
linkElement
===
'
a
'
?
'
href
'
:
'
to
'
]:
item
.
href
,
},
item
.
title
)
:
item
.
title
}
<
/Breadcrumb.Item
>
))}
{
breadcrumbList
.
map
(
item
=>
{
const
title
=
this
.
props
.
itemRender
?
this
.
props
.
itemRender
(
item
)
:
item
.
title
;
return
(
<
Breadcrumb
.
Item
key
=
{
item
.
title
}
>
{
item
.
href
?
createElement
(
linkElement
,
{
[
linkElement
===
'
a
'
?
'
href
'
:
'
to
'
]:
item
.
href
,
},
title
)
:
title
}
<
/Breadcrumb.Item
>
);
})}
<
/Breadcrumb
>
);
};
...
...
@@ -85,14 +89,18 @@ export default class PageHeader extends PureComponent {
const
pathSnippets
=
urlToList
(
routerLocation
.
pathname
);
// Loop data mosaic routing
const
extraBreadcrumbItems
=
pathSnippets
.
map
((
url
,
index
)
=>
{
console
.
log
(
url
);
const
currentBreadcrumb
=
getBreadcrumb
(
breadcrumbNameMap
,
url
);
const
isLinkable
=
index
!==
pathSnippets
.
length
-
1
&&
currentBreadcrumb
.
component
;
const
name
=
this
.
props
.
itemRender
?
this
.
props
.
itemRender
(
currentBreadcrumb
)
:
currentBreadcrumb
.
name
;
return
currentBreadcrumb
.
name
&&
!
currentBreadcrumb
.
hideInBreadcrumb
?
(
<
Breadcrumb
.
Item
key
=
{
url
}
>
{
createElement
(
isLinkable
?
linkElement
:
'
span
'
,
{
[
linkElement
===
'
a
'
?
'
href
'
:
'
to
'
]:
url
},
currentBreadcrumb
.
name
name
)}
<
/Breadcrumb.Item
>
)
:
null
;
...
...
src/components/PageHeader/index.md
View file @
123401a9
...
...
@@ -28,6 +28,7 @@ order: 11
| tabActiveKey | 当前高亮的 tab 项 | string | - |
| tabDefaultActiveKey | 默认高亮的 tab 项 | string | 第一项 |
| onTabChange | 切换面板的回调 | (key) => void | - |
| itemRender | 自定义节点方法 | (menuItem) => ReactNode | - |
| linkElement | 定义链接的元素,默认为
`a`
,可传入 react-router 的 Link | string
\|
ReactElement | - |
> 面包屑的配置方式有三种,一是直接配置 `breadcrumbList`,二是结合 `react-router@2` `react-router@3`,配置 `routes` 及 `params` 实现,类似 [面包屑 Demo](https://ant.design/components/breadcrumb-cn/#components-breadcrumb-demo-router),三是结合 `react-router@4`,配置 `location` `breadcrumbNameMap`,优先级依次递减,脚手架中使用最后一种。 对于后两种用法,你也可以将 `routes` `params` 及 `location` `breadcrumbNameMap` 放到 context 中,组件会自动获取。
src/pages/layouts/BasicLayout.js
View file @
123401a9
...
...
@@ -26,18 +26,18 @@ const { AuthorizedRoute, check } = Authorized;
* @param {Object} menuData 菜单配置
* @param {Object} routerData 路由配置
*/
const
getBreadcrumbNameMap
=
(
me
nuData
,
routerData
)
=>
{
const
r
esult
=
{};
const
childResult
=
{};
for
(
const
i
of
menuData
)
{
if
(
!
routerData
[
i
.
path
])
{
result
[
i
.
path
]
=
i
;
}
if
(
i
.
children
)
{
Object
.
assign
(
childResult
,
getBreadcrumbNameMap
(
i
.
children
,
routerData
)
);
}
}
return
Object
.
assign
({},
routerData
,
result
,
childResult
)
;
const
getBreadcrumbNameMap
=
(
me
un
,
router
)
=>
{
const
r
outerMap
=
{};
const
mergeMeunAndRouter
=
meunData
=>
{
meunData
.
forEach
(
meunItem
=>
{
routerMap
[
meunItem
.
path
]
=
Object
.
assign
(
meunItem
,
router
);
if
(
meunItem
.
children
)
{
mergeMeunAndRouter
(
meunItem
.
children
);
}
}
);
};
mergeMeunAndRouter
(
meun
);
return
routerMap
;
};
const
query
=
{
...
...
@@ -68,6 +68,7 @@ const query = {
class
BasicLayout
extends
React
.
PureComponent
{
getContext
()
{
const
{
location
,
routerData
,
menuData
}
=
this
.
props
;
console
.
log
(
getBreadcrumbNameMap
(
menuData
,
routerData
));
return
{
location
,
breadcrumbNameMap
:
getBreadcrumbNameMap
(
menuData
,
routerData
),
...
...
src/pages/layouts/PageHeaderLayout.js
View file @
123401a9
...
...
@@ -18,6 +18,12 @@ const PageHeaderLayout = ({ children, wrapperClassName, top, ...restProps }) =>
key
=
"
pageheader
"
{...
restProps
}
linkElement
=
{
Link
}
itemRender
=
{
item
=>
{
if
(
item
.
locale
)
{
return
<
FormattedMessage
id
=
{
item
.
locale
}
defaultMessage
=
{
item
.
name
}
/>
;
}
return
item
.
name
;
}}
/
>
);
}}
...
...
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