提交 7ef5d2cd 编写于 作者: D DCloud_LXH

feat(h5): tabBar set midButton

上级 ad024491
...@@ -40,16 +40,16 @@ ...@@ -40,16 +40,16 @@
:class="{'uni-tabbar__icon__diff':!item.text}" :class="{'uni-tabbar__icon__diff':!item.text}"
class="uni-tabbar__icon" class="uni-tabbar__icon"
:style="{width: iconWidth,height:iconWidth}" :style="{width: iconWidth,height:iconWidth}"
> >
<div <div
v-if="item.iconfont" v-if="item.iconfont"
:style="{ :style="{
color:selectedIndex === index ? item.iconfont.selectedColor : item.iconfont.color, color:selectedIndex === index ? item.iconfont.selectedColor : item.iconfont.color,
fontSize: item.iconfont.fontSize || iconWidth fontSize: item.iconfont.fontSize || iconWidth
}" }"
class="uni-tabbar__iconfont" class="uni-tabbar__iconfont"
> >
{{ selectedIndex === index ? item.iconfont.selectedText : item.iconfont.text }} {{ selectedIndex === index ? item.iconfont.selectedText : item.iconfont.text }}
</div> </div>
<img <img
v-else-if="!item.isMidButton" v-else-if="!item.isMidButton"
...@@ -169,10 +169,10 @@ ...@@ -169,10 +169,10 @@
uni-tabbar .uni-tabbar__icon img { uni-tabbar .uni-tabbar__icon img {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
uni-tabbar .uni-tabbar__iconfont { uni-tabbar .uni-tabbar__iconfont {
font-family: 'UniTabbarIconFont'; font-family: 'UniTabbarIconFont';
} }
uni-tabbar .uni-tabbar__label { uni-tabbar .uni-tabbar__label {
...@@ -226,11 +226,11 @@ ...@@ -226,11 +226,11 @@
<script> <script>
import getRealPath from 'uni-platform/helpers/get-real-path' import getRealPath from 'uni-platform/helpers/get-real-path'
import { isPlainObject } from 'uni-shared' import { isPlainObject } from 'uni-shared'
import { publish } from 'uni-platform/service/bridge' import { publish } from 'uni-platform/service/bridge'
import { loadFontFace } from 'uni-core/view/bridge/subscribe/font' import { loadFontFace } from 'uni-core/view/bridge/subscribe/font'
function cssSupports (css) { function cssSupports (css) {
return window.CSS && CSS.supports && (CSS.supports(css) || CSS.supports.apply(CSS, css.split(':'))) return window.CSS && CSS.supports && (CSS.supports(css) || CSS.supports.apply(CSS, css.split(':')))
} }
const UNI_TABBAR_ICON_FONT = 'UniTabbarIconFont' const UNI_TABBAR_ICON_FONT = 'UniTabbarIconFont'
export default { export default {
name: 'TabBar', name: 'TabBar',
...@@ -256,10 +256,10 @@ export default { ...@@ -256,10 +256,10 @@ export default {
borderStyle: { borderStyle: {
type: String, type: String,
default: 'black' default: 'black'
}, },
iconfontSrc: { iconfontSrc: {
type: String, type: String,
default: '' default: ''
}, },
list: { list: {
type: Array, type: Array,
...@@ -301,7 +301,8 @@ export default { ...@@ -301,7 +301,8 @@ export default {
data () { data () {
return { return {
selectedIndex: 0, selectedIndex: 0,
visibleList: [] visibleList: [],
internalMidButton: {}
} }
}, },
computed: { computed: {
...@@ -345,6 +346,9 @@ export default { ...@@ -345,6 +346,9 @@ export default {
this._initVisibleList() this._initVisibleList()
this.setSelectedIndex() this.setSelectedIndex()
} }
},
midButton (config) {
this._initVisibleList()
} }
}, },
created () { created () {
...@@ -352,15 +356,15 @@ export default { ...@@ -352,15 +356,15 @@ export default {
if (item.visible === undefined) { if (item.visible === undefined) {
this.$set(item, 'visible', true) this.$set(item, 'visible', true)
} }
}) })
if (this.iconfontSrc) { if (this.iconfontSrc) {
loadFontFace({ loadFontFace({
options: { options: {
family: UNI_TABBAR_ICON_FONT, family: UNI_TABBAR_ICON_FONT,
source: `url("${this.iconfontSrc}")` source: `url("${this.iconfontSrc}")`
} }
}) })
} }
}, },
beforeCreate () { beforeCreate () {
...@@ -422,16 +426,16 @@ export default { ...@@ -422,16 +426,16 @@ export default {
const listLength = list.length const listLength = list.length
// 偶数则添加midButton // 偶数则添加midButton
if (listLength % 2 === 0 && isPlainObject(this.midButton)) { if (listLength % 2 === 0 && isPlainObject(this.midButton)) {
// 给midButton赋值默认值 this.internalMidButton = Object.assign(
const DefaultMidButton = { {
width: '50px', width: '50px',
height: '50px', height: '50px',
iconWidth: '24px' iconWidth: '24px'
} },
for (const key in DefaultMidButton) { this.internalMidButton,
this.midButton[key] = this.midButton[key] || DefaultMidButton[key] this.midButton
} )
list.splice(~~(listLength / 2), 0, Object.assign({}, this.midButton, { isMidButton: true })) list.splice(~~(listLength / 2), 0, Object.assign({}, this.internalMidButton, { isMidButton: true }))
} }
return list return list
}, },
......
...@@ -4,7 +4,7 @@ import { ...@@ -4,7 +4,7 @@ import {
const setTabBarItemProps = ['text', 'iconPath', 'iconfont', 'selectedIconPath', 'visible'] const setTabBarItemProps = ['text', 'iconPath', 'iconfont', 'selectedIconPath', 'visible']
const setTabBarStyleProps = ['color', 'selectedColor', 'backgroundColor', 'borderStyle'] const setTabBarStyleProps = ['color', 'selectedColor', 'backgroundColor', 'borderStyle', 'midButton']
const setTabBarBadgeProps = ['badge', 'redDot'] const setTabBarBadgeProps = ['badge', 'redDot']
...@@ -45,10 +45,10 @@ function setTabBar (type, args = {}) { ...@@ -45,10 +45,10 @@ function setTabBar (type, args = {}) {
case 'hideTabBar': case 'hideTabBar':
app.$children[0].hideTabBar = true app.$children[0].hideTabBar = true
break break
case 'setTabBarItem': { case 'setTabBarItem': {
if (args.iconfont) { if (args.iconfont) {
setProperties(tabBar.list[index].iconfont, setTabBarIconfontStyles, args.iconfont) setProperties(tabBar.list[index].iconfont, setTabBarIconfontStyles, args.iconfont)
args.iconfont = tabBar.list[index].iconfont args.iconfont = tabBar.list[index].iconfont
} }
setProperties(tabBar.list[index], setTabBarItemProps, args) setProperties(tabBar.list[index], setTabBarItemProps, args)
const pagePath = args.pagePath const pagePath = args.pagePath
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册