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
aa7e9bd4
Commit
aa7e9bd4
authored
Apr 03, 2019
by
陈帅
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change to upcales
parent
1c8dabcf
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
152 additions
and
10 deletions
+152
-10
src/components/PageHeaderWrapper/Breadcrumb.tsx
src/components/PageHeaderWrapper/Breadcrumb.tsx
+135
-0
src/components/PageHeaderWrapper/breadcrumb.tsx
src/components/PageHeaderWrapper/breadcrumb.tsx
+1
-1
src/components/PageHeaderWrapper/index.tsx
src/components/PageHeaderWrapper/index.tsx
+16
-9
No files found.
src/components/PageHeaderWrapper/Breadcrumb.tsx
0 → 100644
View file @
aa7e9bd4
import
React
from
'
react
'
;
import
pathToRegexp
from
'
path-to-regexp
'
;
import
Link
from
'
umi/link
'
;
import
{
FormattedMessage
}
from
'
umi-plugin-react/locale
'
;
import
{
urlToList
}
from
'
../_utils/pathTools
'
;
import
{
PageHeaderWrapperProps
}
from
'
.
'
;
import
{
MenuDataItem
}
from
'
../SiderMenu
'
;
import
{
BreadcrumbProps
as
AntdBreadcrumbProps
}
from
'
antd/lib/breadcrumb
'
;
type
BreadcrumbProps
=
PageHeaderWrapperProps
;
// 渲染Breadcrumb 子节点
// Render the Breadcrumb child node
const
itemRender
:
AntdBreadcrumbProps
[
'
itemRender
'
]
=
(
route
,
params
,
routes
,
paths
)
=>
{
const
last
=
routes
.
indexOf
(
route
)
===
routes
.
length
-
1
;
return
last
||
!
route
.
component
?
(
<
span
>
{
route
.
breadcrumbName
}
</
span
>
)
:
(
<
Link
to
=
{
paths
.
join
(
'
/
'
)
}
>
{
route
.
breadcrumbName
}
</
Link
>
);
};
const
renderItemLocal
=
(
item
:
MenuDataItem
):
React
.
ReactNode
=>
{
if
(
item
.
locale
)
{
return
<
FormattedMessage
id
=
{
item
.
locale
}
defaultMessage
=
{
item
.
name
}
/>;
}
return
item
.
name
;
};
export
const
getBreadcrumb
=
(
breadcrumbNameMap
:
PageHeaderWrapperProps
[
'
breadcrumbNameMap
'
],
url
:
string
,
):
MenuDataItem
=>
{
if
(
!
breadcrumbNameMap
)
{
return
{
path
:
''
,
};
}
let
breadcrumb
=
breadcrumbNameMap
[
url
];
if
(
!
breadcrumb
)
{
Object
.
keys
(
breadcrumbNameMap
).
forEach
(
item
=>
{
if
(
pathToRegexp
(
item
).
test
(
url
))
{
breadcrumb
=
breadcrumbNameMap
[
item
];
}
});
}
return
breadcrumb
||
{
path
:
''
};
};
export
const
getBreadcrumbProps
=
(
props
:
BreadcrumbProps
):
PageHeaderWrapperProps
=>
{
const
{
location
,
breadcrumbNameMap
}
=
props
;
return
{
location
,
breadcrumbNameMap
,
};
};
// Generated according to props
const
conversionFromProps
=
(
props
:
BreadcrumbProps
):
AntdBreadcrumbProps
[
'
routes
'
]
=>
{
const
{
breadcrumbList
=
[]
}
=
props
;
return
breadcrumbList
.
map
(
item
=>
{
const
{
title
,
href
}
=
item
;
return
{
path
:
href
,
breadcrumbName
:
title
,
};
})
.
filter
(
item
=>
item
.
path
);
};
const
conversionFromLocation
=
(
routerLocation
:
PageHeaderWrapperProps
[
'
location
'
],
breadcrumbNameMap
:
PageHeaderWrapperProps
[
'
breadcrumbNameMap
'
],
props
:
BreadcrumbProps
,
):
AntdBreadcrumbProps
[
'
routes
'
]
=>
{
if
(
!
routerLocation
)
{
return
[];
}
const
{
home
}
=
props
;
// Convert the url to an array
const
pathSnippets
=
urlToList
(
routerLocation
.
pathname
);
// Loop data mosaic routing
const
extraBreadcrumbItems
:
AntdBreadcrumbProps
[
'
routes
'
]
=
pathSnippets
.
map
(
url
=>
{
const
currentBreadcrumb
=
getBreadcrumb
(
breadcrumbNameMap
,
url
);
if
(
currentBreadcrumb
.
inherited
)
{
return
{
path
:
''
,
breadcrumbName
:
''
};
}
const
name
=
renderItemLocal
(
currentBreadcrumb
);
const
{
hideInBreadcrumb
}
=
currentBreadcrumb
;
return
name
&&
!
hideInBreadcrumb
?
{
path
:
url
,
breadcrumbName
:
name
,
}
:
{
path
:
''
,
breadcrumbName
:
''
};
})
.
filter
(
item
=>
item
&&
item
.
path
);
// Add home breadcrumbs to your head if defined
if
(
home
)
{
extraBreadcrumbItems
.
unshift
({
path
:
'
/
'
,
breadcrumbName
:
home
,
});
}
return
extraBreadcrumbItems
;
};
/**
* 将参数转化为面包屑
* Convert parameters into breadcrumbs
*/
export
const
conversionBreadcrumbList
=
(
props
:
BreadcrumbProps
):
AntdBreadcrumbProps
=>
{
const
{
breadcrumbList
}
=
props
;
const
{
location
,
breadcrumbNameMap
}
=
getBreadcrumbProps
(
props
);
if
(
breadcrumbList
&&
breadcrumbList
.
length
)
{
return
{
routes
:
conversionFromProps
(
props
),
itemRender
,
};
}
// 根据 location 生成 面包屑
// Generate breadcrumbs based on location
if
(
location
&&
location
.
pathname
)
{
return
{
routes
:
conversionFromLocation
(
location
,
breadcrumbNameMap
,
props
),
itemRender
,
};
}
return
{
routes
:
[],
};
};
src/components/PageHeaderWrapper/breadcrumb.tsx
View file @
aa7e9bd4
...
@@ -3,7 +3,7 @@ import pathToRegexp from 'path-to-regexp';
...
@@ -3,7 +3,7 @@ import pathToRegexp from 'path-to-regexp';
import
Link
from
'
umi/link
'
;
import
Link
from
'
umi/link
'
;
import
{
FormattedMessage
}
from
'
umi-plugin-react/locale
'
;
import
{
FormattedMessage
}
from
'
umi-plugin-react/locale
'
;
import
{
urlToList
}
from
'
../_utils/pathTools
'
;
import
{
urlToList
}
from
'
../_utils/pathTools
'
;
import
{
PageHeaderWrapperProps
}
from
'
.
/
'
;
import
{
PageHeaderWrapperProps
}
from
'
.
'
;
import
{
MenuDataItem
}
from
'
../SiderMenu
'
;
import
{
MenuDataItem
}
from
'
../SiderMenu
'
;
import
{
BreadcrumbProps
as
AntdBreadcrumbProps
}
from
'
antd/lib/breadcrumb
'
;
import
{
BreadcrumbProps
as
AntdBreadcrumbProps
}
from
'
antd/lib/breadcrumb
'
;
...
...
src/components/PageHeaderWrapper/index.tsx
View file @
aa7e9bd4
...
@@ -7,7 +7,7 @@ import GridContent from './GridContent';
...
@@ -7,7 +7,7 @@ import GridContent from './GridContent';
import
ConnectState
from
'
@/models/connect
'
;
import
ConnectState
from
'
@/models/connect
'
;
import
{
ContentWidth
}
from
'
config/defaultSettings
'
;
import
{
ContentWidth
}
from
'
config/defaultSettings
'
;
import
styles
from
'
./index.less
'
;
import
styles
from
'
./index.less
'
;
import
{
conversionBreadcrumbList
}
from
'
./
b
readcrumb
'
;
import
{
conversionBreadcrumbList
}
from
'
./
B
readcrumb
'
;
import
{
MenuDataItem
}
from
'
../SiderMenu
'
;
import
{
MenuDataItem
}
from
'
../SiderMenu
'
;
import
*
as
H
from
'
history
'
;
import
*
as
H
from
'
history
'
;
...
@@ -81,7 +81,18 @@ class PageHeaderWrapper extends React.Component<PageHeaderWrapperProps> {
...
@@ -81,7 +81,18 @@ class PageHeaderWrapper extends React.Component<PageHeaderWrapperProps> {
extraContent
,
extraContent
,
...
restProps
...
restProps
}
=
this
.
mergePropsAndChildren
();
}
=
this
.
mergePropsAndChildren
();
if
(
!
title
&&
!
content
)
{
let
pageTitle
=
title
;
const
breadcrumb
=
conversionBreadcrumbList
({
...
restProps
,
home
:
<
FormattedMessage
id
=
"menu.home"
defaultMessage
=
"Home"
/>,
});
if
(
!
title
&&
breadcrumb
.
routes
)
{
const
router
=
breadcrumb
.
routes
[
breadcrumb
.
routes
.
length
-
1
];
if
(
router
)
{
pageTitle
=
router
.
breadcrumbName
;
}
}
if
(
!
pageTitle
&&
!
content
)
{
return
;
return
;
}
}
return
(
return
(
...
@@ -93,14 +104,11 @@ class PageHeaderWrapper extends React.Component<PageHeaderWrapperProps> {
...
@@ -93,14 +104,11 @@ class PageHeaderWrapper extends React.Component<PageHeaderWrapperProps> {
marginBottom
:
0
,
marginBottom
:
0
,
}
}
}
}
>
>
{
t
itle
}
{
pageT
itle
}
</
Title
>
</
Title
>
}
}
{
...
restProps
}
{
...
restProps
}
breadcrumb
=
{
conversionBreadcrumbList
({
breadcrumb
=
{
breadcrumb
}
...
restProps
,
home
:
<
FormattedMessage
id
=
"menu.home"
defaultMessage
=
"Home"
/>,
})
}
className
=
{
styles
.
pageHeader
}
className
=
{
styles
.
pageHeader
}
footer
=
{
renderFooter
(
restProps
)
}
footer
=
{
renderFooter
(
restProps
)
}
>
>
...
@@ -117,10 +125,9 @@ class PageHeaderWrapper extends React.Component<PageHeaderWrapperProps> {
...
@@ -117,10 +125,9 @@ class PageHeaderWrapper extends React.Component<PageHeaderWrapperProps> {
);
);
};
};
render
()
{
render
()
{
const
{
children
,
top
}
=
this
.
mergePropsAndChildren
();
const
{
children
}
=
this
.
mergePropsAndChildren
();
return
(
return
(
<
div
style
=
{
{
margin
:
'
-24px -24px 0
'
}
}
className
=
{
classNames
(
classNames
,
styles
.
main
)
}
>
<
div
style
=
{
{
margin
:
'
-24px -24px 0
'
}
}
className
=
{
classNames
(
classNames
,
styles
.
main
)
}
>
{
top
}
{
this
.
renderPageHeader
()
}
{
this
.
renderPageHeader
()
}
{
children
?
(
{
children
?
(
<
div
className
=
{
styles
[
'
children-content
'
]
}
>
<
div
className
=
{
styles
[
'
children-content
'
]
}
>
...
...
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