bug
jiangping
2023-11-07 64b432916af9c9218ab3f3eca614e26c542142ae
minipro_standard/uni_modules/uview-ui/components/u-navbar/u-navbar.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,186 @@
<template>
   <view class="u-navbar">
      <view
         class="u-navbar__placeholder"
         v-if="fixed && placeholder"
         :style="{
            height: $u.addUnit($u.getPx(height) + $u.sys().statusBarHeight,'px'),
         }"
      ></view>
      <view :class="[fixed && 'u-navbar--fixed']">
         <u-status-bar
            v-if="safeAreaInsetTop"
            :bgColor="bgColor"
         ></u-status-bar>
         <view
            class="u-navbar__content"
            :class="[border && 'u-border-bottom']"
            :style="{
               height: $u.addUnit(height),
               backgroundColor: bgColor,
            }"
         >
            <view
               class="u-navbar__content__left"
               hover-class="u-navbar__content__left--hover"
               hover-start-time="150"
               @tap="leftClick"
            >
               <slot name="left">
                  <u-icon
                     v-if="leftIcon"
                     :name="leftIcon"
                     :size="leftIconSize"
                     :color="leftIconColor"
                  ></u-icon>
                  <text
                     v-if="leftText"
                     :style="{
                        color: leftIconColor
                     }"
                     class="u-navbar__content__left__text"
                  >{{ leftText }}</text>
               </slot>
            </view>
            <slot name="center">
               <text
                  class="u-line-1 u-navbar__content__title"
                  :style="[{
                     width: $u.addUnit(titleWidth),
                  }, $u.addStyle(titleStyle)]"
               >{{ title }}</text>
            </slot>
            <view
               class="u-navbar__content__right"
               v-if="$slots.right || rightIcon || rightText"
               @tap="rightClick"
            >
               <slot name="right">
                  <u-icon
                     v-if="rightIcon"
                     :name="rightIcon"
                     size="20"
                  ></u-icon>
                  <text
                     v-if="rightText"
                     class="u-navbar__content__right__text"
                  >{{ rightText }}</text>
               </slot>
            </view>
         </view>
      </view>
   </view>
</template>
<script>
   import props from './props.js';
   /**
    * Navbar è‡ªå®šä¹‰å¯¼èˆªæ 
    * @description æ­¤ç»„件一般用于在特殊情况下,需要自定义导航栏的时候用到,一般建议使用uni-app带的导航栏。
    * @tutorial https://www.uviewui.com/components/navbar.html
    * @property {Boolean}         safeAreaInsetTop   æ˜¯å¦å¼€å¯é¡¶éƒ¨å®‰å…¨åŒºé€‚配  ï¼ˆé»˜è®¤ true ï¼‰
    * @property {Boolean}         placeholder         å›ºå®šåœ¨é¡¶éƒ¨æ—¶ï¼Œæ˜¯å¦ç”Ÿæˆä¸€ä¸ªç­‰é«˜å…ƒç´ ï¼Œä»¥é˜²æ­¢å¡Œé™· ï¼ˆé»˜è®¤ false ï¼‰
    * @property {Boolean}         fixed            å¯¼èˆªæ æ˜¯å¦å›ºå®šåœ¨é¡¶éƒ¨ ï¼ˆé»˜è®¤ false ï¼‰
    * @property {Boolean}         border            å¯¼èˆªæ åº•部是否显示下边框 ï¼ˆé»˜è®¤ false ï¼‰
    * @property {String}         leftIcon         å·¦è¾¹è¿”回图标的名称,只能为uView自带的图标 ï¼ˆé»˜è®¤ 'arrow-left' ï¼‰
    * @property {String}         leftText         å·¦è¾¹çš„æç¤ºæ–‡å­—
    * @property {String}         rightText         å³è¾¹çš„æç¤ºæ–‡å­—
    * @property {String}         rightIcon         å³è¾¹è¿”回图标的名称,只能为uView自带的图标
    * @property {String}         title            å¯¼èˆªæ æ ‡é¢˜ï¼Œå¦‚设置为空字符,将会隐藏标题占位区域
    * @property {String}         bgColor            å¯¼èˆªæ èƒŒæ™¯è®¾ç½® ï¼ˆé»˜è®¤ '#ffffff' ï¼‰
    * @property {String | Number}   titleWidth         å¯¼èˆªæ æ ‡é¢˜çš„æœ€å¤§å®½åº¦ï¼Œå†…容超出会以省略号隐藏 ï¼ˆé»˜è®¤ '400rpx' ï¼‰
    * @property {String | Number}   height            å¯¼èˆªæ é«˜åº¦(不包括状态栏高度在内,内部自动加上)(默认 '44px' ï¼‰
    * @property {String | Number}   leftIconSize      å·¦ä¾§è¿”回图标的大小(默认 20px ï¼‰
    * @property {String | Number}   leftIconColor      å·¦ä¾§è¿”回图标的颜色(默认 #303133 ï¼‰
    * @property {Boolean}           autoBack         ç‚¹å‡»å·¦ä¾§åŒºåŸŸ(返回图标),是否自动返回上一页(默认 false ï¼‰
    * @property {Object | String}   titleStyle         æ ‡é¢˜çš„æ ·å¼ï¼Œå¯¹è±¡æˆ–字符串
    * @event {Function} leftClick      ç‚¹å‡»å·¦ä¾§åŒºåŸŸ
    * @event {Function} rightClick      ç‚¹å‡»å³ä¾§åŒºåŸŸ
    * @example <u-navbar title="剑未配妥,出门已是江湖" left-text="返回" right-text="帮助" @click-left="onClickBack" @click-right="onClickRight"></u-navbar>
    */
   export default {
      name: 'u-navbar',
      mixins: [uni.$u.mpMixin, uni.$u.mixin, props],
      data() {
         return {
         }
      },
      methods: {
         // ç‚¹å‡»å·¦ä¾§åŒºåŸŸ
         leftClick() {
            // å¦‚果配置了autoBack,自动返回上一页
            this.$emit('leftClick')
            if(this.autoBack) {
               uni.navigateBack()
            }
         },
         // ç‚¹å‡»å³ä¾§åŒºåŸŸ
         rightClick() {
            this.$emit('rightClick')
         },
      }
   }
</script>
<style lang="scss" scoped>
   @import "../../libs/css/components.scss";
   .u-navbar {
      &--fixed {
         position: fixed;
         left: 0;
         right: 0;
         top: 0;
         z-index: 11;
      }
      &__content {
         @include flex(row);
         align-items: center;
         height: 44px;
         background-color: #9acafc;
         position: relative;
         justify-content: center;
         &__left,
         &__right {
            padding: 0 13px;
            position: absolute;
            top: 0;
            bottom: 0;
            @include flex(row);
            align-items: center;
         }
         &__left {
            left: 0;
            &--hover {
               opacity: 0.7;
            }
            &__text {
               font-size: 15px;
               margin-left: 3px;
            }
         }
         &__title {
            text-align: center;
            font-size: 16px;
            color: $u-main-color;
         }
         &__right {
            right: 0;
            &__text {
               font-size: 15px;
               margin-left: 3px;
            }
         }
      }
   }
</style>