gaoluyang
5 天以前 92230c9a97dc9ce9df3313d11d26999c04bb6b26
src/uni_modules/uni-title/components/uni-title/uni-title.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,171 @@
<template>
   <view class="uni-title__box" :style="{'align-items':textAlign}">
      <text class="uni-title__base" :class="['uni-'+type]" :style="{'color':color}">{{title}}</text>
   </view>
</template>
<script>
   /**
    * Title æ ‡é¢˜
    * @description æ ‡é¢˜ï¼Œé€šå¸¸ç”¨äºŽè®°å½•页面标题,使用当前组件,uni-app å¦‚果开启统计,将会自动统计页面标题
    * @tutorial https://ext.dcloud.net.cn/plugin?id=1066
    * @property {String} type = [h1|h2|h3|h4|h5] æ ‡é¢˜ç±»åž‹
    *    @value h1 ä¸€çº§æ ‡é¢˜
    *    @value h2 äºŒçº§æ ‡é¢˜
    *    @value h3 ä¸‰çº§æ ‡é¢˜
    *    @value h4 å››çº§æ ‡é¢˜
    *    @value h5 äº”级标题
    * @property {String} title æ ‡é¢˜å†…容
    * @property {String} align = [left|center|right] å¯¹é½æ–¹å¼
    *    @value left åšå¯¹é½
    *    @value center å±…中对齐
    *    @value right å³å¯¹é½
    * @property {String} color å­—体颜色
    * @property {Boolean} stat = [true|false] æ˜¯å¦å¼€å¯ç»Ÿè®¡åŠŸèƒ½å‘¢ï¼Œå¦‚ä¸å¡«å†™type值,默认为开启,填写 type å±žæ€§ï¼Œé»˜è®¤ä¸ºå…³é—­
    */
   export default {
      name:"UniTitle",
      props: {
         type: {
            type: String,
            default: ''
         },
         title: {
            type: String,
            default: ''
         },
         align: {
            type: String,
            default: 'left'
         },
         color: {
            type: String,
            default: '#333333'
         },
         stat: {
            type: [Boolean, String],
            default: ''
         }
      },
      data() {
         return {
         };
      },
      computed: {
         textAlign() {
            let align = 'center';
            switch (this.align) {
               case 'left':
                  align = 'flex-start'
                  break;
               case 'center':
                  align = 'center'
                  break;
               case 'right':
                  align = 'flex-end'
                  break;
            }
            return align
         }
      },
      watch: {
         title(newVal) {
            if (this.isOpenStat()) {
               // ä¸ŠæŠ¥æ•°æ®
               if (uni.report) {
                  uni.report('title', this.title)
               }
            }
         }
      },
      mounted() {
         if (this.isOpenStat()) {
            // ä¸ŠæŠ¥æ•°æ®
            if (uni.report) {
               uni.report('title', this.title)
            }
         }
      },
      methods: {
         isOpenStat() {
            if (this.stat === '') {
               this.isStat = false
            }
            let stat_type = (typeof(this.stat) === 'boolean' && this.stat) || (typeof(this.stat) === 'string' && this.stat !==
               '')
            if (this.type === "") {
               this.isStat = true
               if (this.stat.toString() === 'false') {
                  this.isStat = false
               }
            }
            if (this.type !== '') {
               this.isStat = true
               if (stat_type) {
                  this.isStat = true
               } else {
                  this.isStat = false
               }
            }
            return this.isStat
         }
      }
   }
</script>
<style>
   /* .uni-title {
   } */
   .uni-title__box {
      /* #ifndef APP-NVUE */
      display: flex;
      /* #endif */
      flex-direction: column;
      align-items: flex-start;
      justify-content: center;
      padding: 8px 0;
      flex: 1;
   }
   .uni-title__base {
      font-size: 15px;
      color: #333;
      font-weight: 500;
   }
   .uni-h1 {
      font-size: 20px;
      color: #333;
      font-weight: bold;
   }
   .uni-h2 {
      font-size: 18px;
      color: #333;
      font-weight: bold;
   }
   .uni-h3 {
      font-size: 16px;
      color: #333;
      font-weight: bold;
      /* font-weight: 400; */
   }
   .uni-h4 {
      font-size: 14px;
      color: #333;
      font-weight: bold;
      /* font-weight: 300; */
   }
   .uni-h5 {
      font-size: 12px;
      color: #333;
      font-weight: bold;
      /* font-weight: 200; */
   }
</style>