¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <view class="u-tabbar"> |
| | | <view |
| | | class="u-tabbar__content" |
| | | ref="u-tabbar__content" |
| | | @touchmove.stop.prevent="noop" |
| | | :class="[border && 'u-border-top', fixed && 'u-tabbar--fixed']" |
| | | :style="[tabbarStyle]" |
| | | > |
| | | <view class="u-tabbar__content__item-wrapper"> |
| | | <slot /> |
| | | </view> |
| | | <u-safe-bottom v-if="safeAreaInsetBottom"></u-safe-bottom> |
| | | </view> |
| | | <view |
| | | class="u-tabbar__placeholder" |
| | | v-if="placeholder" |
| | | :style="{ |
| | | height: placeholderHeight + 'px', |
| | | }" |
| | | ></view> |
| | | </view> |
| | | </template> |
| | | |
| | | <script> |
| | | import props from './props.js'; |
| | | // #ifdef APP-NVUE |
| | | const dom = uni.requireNativePlugin('dom') |
| | | // #endif |
| | | /** |
| | | * Tabbar åºé¨å¯¼èªæ |
| | | * @description æ¤ç»ä»¶æä¾äºèªå®ä¹tabbarçè½åã |
| | | * @tutorial https://www.uviewui.com/components/tabbar.html |
| | | * @property {String | Number} value å½åå¹é
项çname |
| | | * @property {Boolean} safeAreaInsetBottom æ¯å¦ä¸ºiPhoneXçåºåºé¨å®å
¨è·ç¦»ï¼é»è®¤ true ï¼ |
| | | * @property {Boolean} border æ¯å¦æ¾ç¤ºä¸æ¹è¾¹æ¡ï¼é»è®¤ true ï¼ |
| | | * @property {String | Number} zIndex å
ç´ å±çº§z-indexï¼é»è®¤ 1 ï¼ |
| | | * @property {String} activeColor é䏿 ç¾çé¢è²ï¼é»è®¤ '#1989fa' ï¼ |
| | | * @property {String} inactiveColor æªé䏿 ç¾çé¢è²ï¼é»è®¤ '#7d7e80' ï¼ |
| | | * @property {Boolean} fixed æ¯å¦åºå®å¨åºé¨ï¼é»è®¤ true ï¼ |
| | | * @property {Boolean} placeholder fixedå®ä½åºå®å¨åºé¨æ¶ï¼æ¯å¦çæä¸ä¸ªçé«å
ç´ é²æ¢å¡é·ï¼é»è®¤ true ï¼ |
| | | * @property {Object} customStyle å®ä¹éè¦ç¨å°çå¤é¨æ ·å¼ |
| | | * |
| | | * @example <u-tabbar :value="value2" :placeholder="false" @change="name => value2 = name" :fixed="false" :safeAreaInsetBottom="false"><u-tabbar-item text="é¦é¡µ" icon="home" dot ></u-tabbar-item></u-tabbar> |
| | | */ |
| | | export default { |
| | | name: 'u-tabbar', |
| | | mixins: [uni.$u.mpMixin, uni.$u.mixin,props], |
| | | data() { |
| | | return { |
| | | placeholderHeight: 0 |
| | | } |
| | | }, |
| | | computed: { |
| | | tabbarStyle() { |
| | | const style = { |
| | | zIndex: this.zIndex |
| | | } |
| | | // åå¹¶æ¥èªç¶ç»ä»¶çcustomStyleæ ·å¼ |
| | | return uni.$u.deepMerge(style, uni.$u.addStyle(this.customStyle)) |
| | | }, |
| | | // çå¬å¤ä¸ªåæ°çååï¼éè¿å¨computedæ§è¡å¯¹åºçæä½ |
| | | updateChild() { |
| | | return [this.value, this.activeColor, this.inactiveColor] |
| | | }, |
| | | updatePlaceholder() { |
| | | return [this.fixed, this.placeholder] |
| | | } |
| | | }, |
| | | watch: { |
| | | updateChild() { |
| | | // 妿updateChildrenä¸çå
ç´ åçäºååï¼åæ§è¡åå
ç´ åå§åæä½ |
| | | this.updateChildren() |
| | | }, |
| | | updatePlaceholder() { |
| | | // 妿fixedï¼placeholderçåæ°åçååï¼éæ°è®¡ç®å ä½å
ç´ çé«åº¦ |
| | | this.setPlaceholderHeight() |
| | | } |
| | | }, |
| | | created() { |
| | | this.children = [] |
| | | }, |
| | | mounted() { |
| | | this.setPlaceholderHeight() |
| | | }, |
| | | methods: { |
| | | updateChildren() { |
| | | // 妿åå¨åå
ç´ ï¼åæ§è¡åå
ç´ çupdateFromParentè¿è¡æ´æ°æ°æ® |
| | | this.children.length && this.children.map(child => child.updateFromParent()) |
| | | }, |
| | | // 设置ç¨äºé²æ¢å¡é·å
ç´ çé«åº¦ |
| | | async setPlaceholderHeight() { |
| | | if (!this.fixed || !this.placeholder) return |
| | | // å»¶æ¶ä¸å®æ¶é´ |
| | | await uni.$u.sleep(20) |
| | | // #ifndef APP-NVUE |
| | | this.$uGetRect('.u-tabbar__content').then(({height = 50}) => { |
| | | // ä¿®å¤IOS safearea bottom æªå¡«å
é«åº¦ |
| | | this.placeholderHeight = height |
| | | }) |
| | | // #endif |
| | | |
| | | // #ifdef APP-NVUE |
| | | dom.getComponentRect(this.$refs['u-tabbar__content'], (res) => { |
| | | const { |
| | | size |
| | | } = res |
| | | this.placeholderHeight = size.height |
| | | }) |
| | | // #endif |
| | | } |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <style lang="scss" scoped> |
| | | @import "../../libs/css/components.scss"; |
| | | |
| | | .u-tabbar { |
| | | @include flex(column); |
| | | flex: 1; |
| | | justify-content: center; |
| | | |
| | | &__content { |
| | | @include flex(column); |
| | | background-color: #fff; |
| | | |
| | | &__item-wrapper { |
| | | height: 50px; |
| | | @include flex(row); |
| | | } |
| | | } |
| | | |
| | | &--fixed { |
| | | position: fixed; |
| | | bottom: 0; |
| | | left: 0; |
| | | right: 0; |
| | | } |
| | | } |
| | | </style> |