Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
菜鸟程序猿_c
uni-app
提交
7fdd18a2
U
uni-app
项目概览
菜鸟程序猿_c
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7fdd18a2
编写于
9月 29, 2021
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: support dynamic tabbarItem hidden
上级
df9fc217
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
55 addition
and
22 deletion
+55
-22
src/platforms/app-plus/service/api/ui/tab-bar.js
src/platforms/app-plus/service/api/ui/tab-bar.js
+3
-2
src/platforms/app-plus/service/framework/tab-bar.js
src/platforms/app-plus/service/framework/tab-bar.js
+12
-2
src/platforms/h5/components/app/tabBar.vue
src/platforms/h5/components/app/tabBar.vue
+39
-17
src/platforms/h5/service/api/ui/tab-bar.js
src/platforms/h5/service/api/ui/tab-bar.js
+1
-1
未找到文件。
src/platforms/app-plus/service/api/ui/tab-bar.js
浏览文件 @
7fdd18a2
...
...
@@ -20,9 +20,10 @@ export function setTabBarItem ({
text
,
iconPath
,
selectedIconPath
,
pagePath
pagePath
,
visible
})
{
tabBar
.
setTabBarItem
(
index
,
text
,
iconPath
,
selectedIconPath
)
tabBar
.
setTabBarItem
(
index
,
text
,
iconPath
,
selectedIconPath
,
visible
)
const
route
=
pagePath
&&
__uniRoutes
.
find
(({
path
})
=>
path
===
pagePath
)
if
(
route
)
{
const
meta
=
route
.
meta
...
...
src/platforms/app-plus/service/framework/tab-bar.js
浏览文件 @
7fdd18a2
...
...
@@ -49,7 +49,7 @@ function setTabBarBadge (type, index, text) {
/**
* 动态设置 tabBar 某一项的内容
*/
function
setTabBarItem
(
index
,
text
,
iconPath
,
selectedIconPath
)
{
function
setTabBarItem
(
index
,
text
,
iconPath
,
selectedIconPath
,
visible
)
{
const
item
=
{
index
}
...
...
@@ -62,7 +62,17 @@ function setTabBarItem (index, text, iconPath, selectedIconPath) {
if
(
selectedIconPath
)
{
item
.
selectedIconPath
=
getRealPath
(
selectedIconPath
)
}
tabBar
&&
tabBar
.
setTabBarItem
(
item
)
if
(
visible
!==
undefined
)
{
item
.
visible
=
config
.
list
[
index
].
visible
=
visible
delete
item
.
index
const
tabbarItems
=
config
.
list
.
map
(
item
=>
({
visible
:
item
.
visible
}))
tabbarItems
[
index
]
=
item
tabBar
&&
tabBar
.
setTabBarItems
({
list
:
tabbarItems
})
}
else
{
tabBar
&&
tabBar
.
setTabBarItem
(
item
)
}
}
/**
* 动态设置 tabBar 的整体样式
...
...
src/platforms/h5/components/app/tabBar.vue
浏览文件 @
7fdd18a2
...
...
@@ -12,7 +12,7 @@
class="uni-tabbar-border"
/>
<div
v-for=
"(item,index) in
l
ist"
v-for=
"(item,index) in
visibleL
ist"
:key=
"item.isMidButton ? index : item.pagePath"
:style=
"item.isMidButton ?
{flex:'0 0 ' + item.width,position:'relative'} : {}"
class="uni-tabbar__item"
...
...
@@ -36,14 +36,14 @@
:style=
"
{height:height}"
>
<div
v-if=
"item.iconPath || item.isMidButton"
v-if=
"
getIconPath(item,index) ||
item.iconPath || item.isMidButton"
:class=
"
{'uni-tabbar__icon__diff':!item.text}"
class="uni-tabbar__icon"
:style="{width: iconWidth,height:iconWidth}"
>
<img
v-if=
"!item.isMidButton"
:src=
"_getRealPath(
selectedIndex===index?item.selectedIconPath:item.iconPath
)"
:src=
"_getRealPath(
getIconPath(item,index)
)"
>
<div
v-if=
"item.redDot"
...
...
@@ -287,7 +287,8 @@ export default {
},
data
()
{
return
{
selectedIndex
:
0
selectedIndex
:
0
,
visibleList
:
[]
}
},
computed
:
{
...
...
@@ -319,25 +320,45 @@ export default {
watch
:
{
$route
:
{
immediate
:
true
,
handler
(
to
)
{
if
(
to
.
meta
.
isTabBar
)
{
this
.
__path__
=
to
.
path
const
index
=
this
.
list
.
findIndex
(
item
=>
to
.
meta
.
pagePath
===
item
.
pagePath
)
if
(
index
>
-
1
)
{
this
.
selectedIndex
=
index
}
}
handler
()
{
// 只在此做一次 visibleList 的初始化
if
(
!
this
.
visibleList
.
length
)
this
.
_initVisibleList
()
this
.
setSelectedIndex
()
}
},
list
:
{
deep
:
true
,
handler
()
{
this
.
_initVisibleList
()
this
.
setSelectedIndex
()
}
}
},
created
()
{
this
.
_initMidButton
()
this
.
list
.
forEach
(
item
=>
{
if
(
item
.
visible
===
undefined
)
{
this
.
$set
(
item
,
'
visible
'
,
true
)
}
})
},
beforeCreate
()
{
this
.
__path__
=
this
.
$route
.
path
},
methods
:
{
_getRealPath
(
filePath
)
{
getIconPath
(
item
,
index
)
{
return
(
this
.
selectedIndex
===
index
?
item
.
selectedIconPath
||
item
.
iconPath
:
item
.
iconPath
)
||
''
},
setSelectedIndex
()
{
if
(
this
.
$route
.
meta
.
isTabBar
)
{
this
.
__path__
=
this
.
$route
.
path
const
index
=
this
.
visibleList
.
findIndex
(
item
=>
this
.
$route
.
meta
.
pagePath
===
item
.
pagePath
)
this
.
selectedIndex
=
index
}
},
_initVisibleList
()
{
this
.
visibleList
=
this
.
_initMidButton
(
this
.
list
.
filter
(
item
=>
item
.
visible
!==
false
))
},
_getRealPath
(
filePath
=
''
)
{
const
SCHEME_RE
=
/^
([
a-z-
]
+:
)?\/\/
/i
const
DATA_RE
=
/^data:.*,.*/
if
(
!
(
SCHEME_RE
.
test
(
filePath
)
||
DATA_RE
.
test
(
filePath
))
&&
filePath
.
indexOf
(
'
/
'
)
!==
0
)
{
...
...
@@ -375,8 +396,8 @@ export default {
UniServiceJSBridge
.
emit
(
'
onTabItemTap
'
,
detail
)
}
},
_initMidButton
()
{
const
listLength
=
this
.
list
.
length
_initMidButton
(
list
)
{
const
listLength
=
list
.
length
// 偶数则添加midButton
if
(
listLength
%
2
===
0
&&
isPlainObject
(
this
.
midButton
))
{
// 给midButton赋值默认值
...
...
@@ -388,8 +409,9 @@ export default {
for
(
const
key
in
DefaultMidButton
)
{
this
.
midButton
[
key
]
=
this
.
midButton
[
key
]
||
DefaultMidButton
[
key
]
}
this
.
list
.
splice
(
~~
(
listLength
/
2
),
0
,
Object
.
assign
({},
this
.
midButton
,
{
isMidButton
:
true
}))
list
.
splice
(
~~
(
listLength
/
2
),
0
,
Object
.
assign
({},
this
.
midButton
,
{
isMidButton
:
true
}))
}
return
list
},
_uniTabbarBdStyle
(
item
)
{
return
Object
.
assign
({},
{
...
...
src/platforms/h5/service/api/ui/tab-bar.js
浏览文件 @
7fdd18a2
...
...
@@ -2,7 +2,7 @@ import {
setProperties
}
from
'
uni-shared
'
const
setTabBarItemProps
=
[
'
text
'
,
'
iconPath
'
,
'
selectedIconPath
'
]
const
setTabBarItemProps
=
[
'
text
'
,
'
iconPath
'
,
'
selectedIconPath
'
,
'
visible
'
]
const
setTabBarStyleProps
=
[
'
color
'
,
'
selectedColor
'
,
'
backgroundColor
'
,
'
borderStyle
'
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录