Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
sage-front-framework
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
郁骅焌
sage-front-framework
Commits
9483c90b
提交
9483c90b
authored
5月 11, 2020
作者:
郁骅焌
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tabbar修改
上级
8d5f01e8
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
204 行增加
和
20 行删除
+204
-20
config.js
config/config.js
+2
-18
index.jsx
src/components/TabBar/index.jsx
+165
-0
style.less
src/components/TabBar/style.less
+14
-0
global.less
src/global.less
+8
-0
BasicLayout.jsx
src/layouts/BasicLayout.jsx
+15
-2
没有找到文件。
config/config.js
浏览文件 @
9483c90b
...
@@ -47,31 +47,15 @@ export default defineConfig({
...
@@ -47,31 +47,15 @@ export default defineConfig({
routes
:
[
routes
:
[
{
{
path
:
'/'
,
path
:
'/'
,
redirect
:
'/
welc
ome'
,
redirect
:
'/
h
ome'
,
},
},
{
{
path
:
'/
welc
ome'
,
path
:
'/
h
ome'
,
name
:
'welcome'
,
name
:
'welcome'
,
icon
:
'smile'
,
icon
:
'smile'
,
component
:
'./Welcome'
,
component
:
'./Welcome'
,
},
},
{
{
path
:
'/admin'
,
name
:
'admin'
,
icon
:
'crown'
,
component
:
'./Admin'
,
authority
:
[
'admin'
],
routes
:
[
{
path
:
'/admin/sub-page'
,
name
:
'sub-page'
,
icon
:
'smile'
,
component
:
'./Welcome'
,
authority
:
[
'admin'
],
},
],
},
{
name
:
'list.table-list'
,
name
:
'list.table-list'
,
icon
:
'table'
,
icon
:
'table'
,
path
:
'/list'
,
path
:
'/list'
,
...
...
src/components/TabBar/index.jsx
0 → 100644
浏览文件 @
9483c90b
import
React
,
{
useState
,
useEffect
,
useImperativeHandle
}
from
'react'
import
{
Tabs
}
from
'antd'
import
{
useLocation
,
history
}
from
"umi"
import
'./style.less'
const
{
TabPane
}
=
Tabs
;
const
TabBar
=
(
props
,
ref
)
=>
{
const
location
=
useLocation
()
const
{
pathname
}
=
location
const
{
currentUser
:
{
menuTree
}
}
=
props
const
[
panes
,
setPanes
]
=
useState
([
{
title
:
'首页'
,
key
:
'/home'
,
closable
:
false
},
// { title: '测试标签1', key: '2' },
// { title: '测试标签2', key: '3' },
// { title: 'Crud', key: '/demo/crud' },
// { title: '测试标签3', key: '4' },
// { title: '测试标签4', key: '5' },
// { title: '测试标签5', key: '6' },
// { title: '测试标签6', key: '7' },
// { title: '测试标签7', key: '8' },
// { title: '测试标签8', key: '9' },
// { title: '测试标签9', key: '10' },
// { title: '测试标签10', key: '11' },
// { title: '测试标签11', key: '12' },
// { title: '测试标签12', key: '13' }
])
const
[
activeKey
,
setActiveKey
]
=
useState
(
''
)
const
[
allPath
,
setAllPath
]
=
useState
([])
const
checkPaneExist
=
(
path
)
=>
{
let
isExist
=
false
for
(
let
i
=
0
;
i
<
panes
.
length
;
i
++
)
{
if
(
panes
[
i
].
key
===
path
)
{
isExist
=
true
break
}
}
if
(
!
isExist
)
{
const
p
=
allPath
.
find
((
item
)
=>
{
return
item
.
path
===
path
})
if
(
p
)
{
const
newPanes
=
panes
.
slice
()
newPanes
.
push
({
title
:
p
.
name
,
key
:
path
})
setPanes
(
newPanes
)
}
}
}
// 初始化
useEffect
(()
=>
{
const
list
=
[]
const
loopPath
=
(
arr
)
=>
{
arr
.
forEach
(
item
=>
{
list
.
push
(
item
);
if
(
item
.
hasSun
)
{
const
clist
=
item
.
children
.
slice
()
loopPath
(
clist
)
}
})
}
loopPath
(
menuTree
)
setAllPath
(
list
)
let
isExist
=
false
for
(
let
i
=
0
;
i
<
panes
.
length
;
i
++
)
{
if
(
panes
[
i
].
key
===
pathname
)
{
isExist
=
true
break
}
}
if
(
!
isExist
)
{
const
p
=
list
.
find
((
item
)
=>
{
return
item
.
path
===
pathname
})
if
(
p
)
{
const
newPanes
=
panes
.
slice
()
newPanes
.
push
({
title
:
p
.
name
,
key
:
pathname
})
setPanes
(
newPanes
)
}
}
setActiveKey
(
pathname
)
},
[])
const
onChange
=
(
activekey
,
fromMenu
)
=>
{
if
(
activekey
!==
activeKey
)
{
setTimeout
(()
=>
{
setActiveKey
(
activekey
)
},
200
)
if
(
!
fromMenu
)
{
history
.
push
(
activekey
)
}
else
{
checkPaneExist
(
activekey
)
}
}
}
const
remove
=
targetKey
=>
{
let
lastActiveKey
=
'/home'
let
lastIndex
;
panes
.
forEach
((
pane
,
i
)
=>
{
if
(
pane
.
key
===
targetKey
)
{
lastIndex
=
i
-
1
;
}
});
const
lastPanes
=
panes
.
filter
(
pane
=>
pane
.
key
!==
targetKey
);
if
(
lastPanes
.
length
&&
activeKey
===
targetKey
)
{
if
(
lastIndex
>=
0
)
{
lastActiveKey
=
lastPanes
[
lastIndex
].
key
;
}
else
{
lastActiveKey
=
lastPanes
[
0
].
key
;
}
}
else
{
lastActiveKey
=
lastPanes
[
lastPanes
.
length
-
1
].
key
;
}
setTimeout
(()
=>
{
setActiveKey
(
lastActiveKey
)
},
200
)
setPanes
(
lastPanes
)
history
.
push
(
lastActiveKey
)
};
const
onEdit
=
(
targetKey
,
action
)
=>
{
if
(
action
===
'remove'
)
{
remove
(
targetKey
);
}
};
useImperativeHandle
(
ref
,
()
=>
({
onChange
}))
return
(
<
div
className=
"sage-tabbar"
>
<
Tabs
onChange=
{
onChange
}
activeKey=
{
activeKey
}
type=
"editable-card"
hideAdd
tabBarGutter=
{
4
}
onEdit=
{
onEdit
}
>
{
panes
.
map
(
pane
=>
(
<
TabPane
tab=
{
pane
.
title
}
key=
{
pane
.
key
}
closable=
{
pane
.
closable
}
/>
))
}
</
Tabs
>
</
div
>
)
}
export
default
React
.
forwardRef
(
TabBar
)
src/components/TabBar/style.less
0 → 100644
浏览文件 @
9483c90b
.sage-tabbar {
margin: -24px -24px -4px;
height: 40px;
background: #fff;
.ant-tabs.ant-tabs-card .ant-tabs-card-bar .ant-tabs-tab {
border-bottom: 1px solid #f0f0f0;
}
.ant-tabs.ant-tabs-card .ant-tabs-card-bar .ant-tabs-tab-active {
// border-bottom: 0px;
}
.ant-tabs.ant-tabs-card .ant-tabs-card-bar .ant-tabs-ink-bar {
// visibility: visible;
}
}
src/global.less
浏览文件 @
9483c90b
...
@@ -38,6 +38,14 @@ ol {
...
@@ -38,6 +38,14 @@ ol {
margin: 12px 12px 0 !important;
margin: 12px 12px 0 !important;
}
}
.ant-pro-page-header-wrap-page-header-warp {
display: none !important;
}
.ant-pro-basicLayout-content .ant-pro-page-header-wrap {
margin-top: 0px !important;
}
// 公共样式
// 公共样式
.sage-hidden {
.sage-hidden {
display: none !important;
display: none !important;
...
...
src/layouts/BasicLayout.jsx
浏览文件 @
9483c90b
...
@@ -4,12 +4,13 @@
...
@@ -4,12 +4,13 @@
* https://github.com/ant-design/ant-design-pro-layout
* https://github.com/ant-design/ant-design-pro-layout
*/
*/
import
ProLayout
,
{
DefaultFooter
}
from
'@ant-design/pro-layout'
;
import
ProLayout
,
{
DefaultFooter
}
from
'@ant-design/pro-layout'
;
import
React
,
{
useEffect
}
from
'react'
;
import
React
,
{
useEffect
,
useRef
}
from
'react'
;
import
{
Link
,
useIntl
,
connect
}
from
'umi'
;
import
{
Link
,
useIntl
,
connect
}
from
'umi'
;
import
{
GithubOutlined
}
from
'@ant-design/icons'
;
import
{
GithubOutlined
}
from
'@ant-design/icons'
;
import
{
Result
,
Button
}
from
'antd'
;
import
{
Result
,
Button
}
from
'antd'
;
import
Authorized
from
'@/utils/Authorized'
;
import
Authorized
from
'@/utils/Authorized'
;
import
RightContent
from
'@/components/GlobalHeader/RightContent'
;
import
RightContent
from
'@/components/GlobalHeader/RightContent'
;
import
TabBar
from
'@/components/TabBar'
;
import
{
getAuthorityFromRouter
}
from
'@/utils/utils'
;
import
{
getAuthorityFromRouter
}
from
'@/utils/utils'
;
import
logo
from
'../assets/logo.svg'
;
import
logo
from
'../assets/logo.svg'
;
...
@@ -69,11 +70,14 @@ const BasicLayout = props => {
...
@@ -69,11 +70,14 @@ const BasicLayout = props => {
location
=
{
location
=
{
pathname
:
'/'
,
pathname
:
'/'
,
},
},
currentUser
}
=
props
;
}
=
props
;
/**
/**
* constructor
* constructor
*/
*/
const
tabBarRef
=
useRef
()
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
dispatch
)
{
if
(
dispatch
)
{
dispatch
({
dispatch
({
...
@@ -94,6 +98,12 @@ const BasicLayout = props => {
...
@@ -94,6 +98,12 @@ const BasicLayout = props => {
}
}
};
// get children authority
};
// get children authority
const
handlePageChange
=
({
pathname
})
=>
{
if
(
tabBarRef
.
current
)
{
tabBarRef
.
current
.
onChange
(
pathname
,
true
)
}
}
const
authorized
=
getAuthorityFromRouter
(
props
.
route
.
routes
,
location
.
pathname
||
'/'
)
||
{
const
authorized
=
getAuthorityFromRouter
(
props
.
route
.
routes
,
location
.
pathname
||
'/'
)
||
{
authority
:
undefined
,
authority
:
undefined
,
};
};
...
@@ -109,6 +119,7 @@ const BasicLayout = props => {
...
@@ -109,6 +119,7 @@ const BasicLayout = props => {
</
Link
>
</
Link
>
)
}
)
}
onCollapse=
{
handleMenuCollapse
}
onCollapse=
{
handleMenuCollapse
}
onPageChange=
{
handlePageChange
}
menuItemRender=
{
(
menuItemProps
,
defaultDom
)
=>
{
menuItemRender=
{
(
menuItemProps
,
defaultDom
)
=>
{
if
(
menuItemProps
.
isUrl
||
menuItemProps
.
children
||
!
menuItemProps
.
path
)
{
if
(
menuItemProps
.
isUrl
||
menuItemProps
.
children
||
!
menuItemProps
.
path
)
{
return
defaultDom
;
return
defaultDom
;
...
@@ -139,6 +150,7 @@ const BasicLayout = props => {
...
@@ -139,6 +150,7 @@ const BasicLayout = props => {
{
...
props
}
{
...
props
}
{
...
settings
}
{
...
settings
}
>
>
<
TabBar
ref=
{
tabBarRef
}
currentUser=
{
currentUser
}
/>
<
Authorized
authority=
{
authorized
.
authority
}
noMatch=
{
noMatch
}
>
<
Authorized
authority=
{
authorized
.
authority
}
noMatch=
{
noMatch
}
>
{
children
}
{
children
}
</
Authorized
>
</
Authorized
>
...
@@ -146,7 +158,8 @@ const BasicLayout = props => {
...
@@ -146,7 +158,8 @@ const BasicLayout = props => {
);
);
};
};
export
default
connect
(({
global
,
settings
})
=>
({
export
default
connect
(({
user
,
global
,
settings
})
=>
({
currentUser
:
user
.
currentUser
,
collapsed
:
global
.
collapsed
,
collapsed
:
global
.
collapsed
,
settings
,
settings
,
}))(
BasicLayout
);
}))(
BasicLayout
);
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论