提交 b3e514c2 编写于 作者: d-u-a's avatar d-u-a

feat: H5 tabbar iconfont

上级 b7feb489
...@@ -36,13 +36,23 @@ ...@@ -36,13 +36,23 @@
:style="{height:height}" :style="{height:height}"
> >
<div <div
v-if="getIconPath(item,index) || item.iconPath || item.isMidButton" v-if="getIconPath(item,index) || item.iconfont || item.iconPath || item.isMidButton"
: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
v-if="item.iconfont"
:style="{
color:selectedIndex === index ? selectedColor : color,
fontSize: item.iconfont.fontSize || fontSize
}"
class="uni-tabbar__iconfont"
>
{{ selectedIndex === index ? item.iconfont.selectedText : item.iconfont.text }}
</div>
<img <img
v-if="!item.isMidButton" v-else-if="!item.isMidButton"
:src="_getRealPath(getIconPath(item,index))" :src="_getRealPath(getIconPath(item,index))"
> >
<div <div
...@@ -166,6 +176,10 @@ ...@@ -166,6 +176,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 {
font-family: 'UniTabbarIconFont';
} }
uni-tabbar .uni-tabbar__label { uni-tabbar .uni-tabbar__label {
...@@ -219,10 +233,12 @@ ...@@ -219,10 +233,12 @@
<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'
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'
export default { export default {
name: 'TabBar', name: 'TabBar',
props: { props: {
...@@ -247,6 +263,10 @@ export default { ...@@ -247,6 +263,10 @@ export default {
borderStyle: { borderStyle: {
type: String, type: String,
default: 'black' default: 'black'
},
iconfontSrc: {
type: String,
default: ''
}, },
list: { list: {
type: Array, type: Array,
...@@ -339,6 +359,12 @@ export default { ...@@ -339,6 +359,12 @@ export default {
if (item.visible === undefined) { if (item.visible === undefined) {
this.$set(item, 'visible', true) this.$set(item, 'visible', true)
} }
})
loadFontFace({
options: {
family: UNI_TABBAR_ICON_FONT,
source: `url("${this.iconfontSrc}")`
}
}) })
}, },
beforeCreate () { beforeCreate () {
......
...@@ -2,7 +2,7 @@ import { ...@@ -2,7 +2,7 @@ import {
setProperties setProperties
} from 'uni-shared' } from 'uni-shared'
const setTabBarItemProps = ['text', 'iconPath', 'selectedIconPath', 'visible'] const setTabBarItemProps = ['text', 'iconPath', 'iconfont', 'selectedIconPath', 'visible']
const setTabBarStyleProps = ['color', 'selectedColor', 'backgroundColor', 'borderStyle'] const setTabBarStyleProps = ['color', 'selectedColor', 'backgroundColor', 'borderStyle']
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册