u-section.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <view class="u-section">
  3. <view class="u-section__title" :style="{
  4. fontWeight: bold ? 'bold' : 'normal',
  5. color: color,
  6. fontSize: fontSize + 'rpx',
  7. paddingLeft: showLine ? (fontSize * 0.7) + 'rpx' : 0
  8. }" :class="{
  9. 'u-section--line': showLine
  10. }">
  11. <view class="u-section__title__icon-wrap u-flex" :style="[lineStyle]" v-if="showLine">
  12. <u-icon top="0" name="column-line" :size="fontSize * 1.25" bold :color="lineColor ? lineColor : color"></u-icon>
  13. </view>
  14. <text class="u-flex u-section__title__text">{{title}}</text>
  15. </view>
  16. <view class="u-section__right-info" v-if="right || $slots.right" :style="{
  17. color: subColor
  18. }" @tap="rightClick">
  19. <slot name="right" v-if="$slots.right" />
  20. <block v-else>
  21. {{subTitle}}
  22. <view class="u-section__right-info__icon-arrow u-flex">
  23. <u-icon name="arrow-right" size="24" :color="subColor"></u-icon>
  24. </view>
  25. </block>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. /**
  31. * section 查看更多
  32. * @description 该组件一般用于分类信息有很多,但是限于篇幅只能列出一部分,让用户通过"查看更多"获得更多信息的场景,实际效果见演示。
  33. * @tutorial https://www.uviewui.com/components/section.html
  34. * @property {String} title 左边主标题
  35. * @property {String} sub-title 右边副标题(默认更多)
  36. * @property {Boolean} right 是否显示右边的内容(默认true)
  37. * @property {Boolean} showLine 是否显示左边的竖条(默认true)
  38. * @property {String Number} font-size 主标题的字体大小(默认28)
  39. * @property {Boolean} bold 主标题是否加粗(默认true)
  40. * @property {String} color 主标题颜色(默认#303133)
  41. * @event {Function} click 组件右侧的内容被点击时触发,用于跳转"更多"
  42. * @example <u-section title="今日热门" :right="false"></u-section>
  43. */
  44. export default {
  45. name: "u-section",
  46. props: {
  47. // 标题信息
  48. title: {
  49. type: String,
  50. default: ''
  51. },
  52. // 右边副标题内容
  53. subTitle: {
  54. type: String,
  55. default: '更多'
  56. },
  57. // 是否显示右边的内容
  58. right: {
  59. type: Boolean,
  60. default: true
  61. },
  62. fontSize: {
  63. type: [Number, String],
  64. default: 28
  65. },
  66. // 主标题是否加粗
  67. bold: {
  68. type: Boolean,
  69. default: true
  70. },
  71. // 主标题的颜色
  72. color: {
  73. type: String,
  74. default: '#303133'
  75. },
  76. // 右边副标题的颜色
  77. subColor: {
  78. type: String,
  79. default: '#909399'
  80. },
  81. // 是否显示左边的竖条
  82. showLine: {
  83. type: Boolean,
  84. default: true
  85. },
  86. // 左边竖线的颜色
  87. lineColor: {
  88. type: String,
  89. default: ''
  90. }
  91. },
  92. computed: {
  93. // 左边竖条的样式
  94. lineStyle() {
  95. // 由于安卓和iOS的,需要稍微调整绝对定位的top值,才能让左边的竖线和右边的文字垂直居中
  96. return {
  97. // 由于竖线为字体图标,具有比实际线宽更宽的宽度,所以也需要根据字体打下动态调整
  98. left: -(Number(this.fontSize) * 0.9) + 'rpx',
  99. top: -(Number(this.fontSize) * (this.$u.os() == 'ios' ? 0.14 : 0.15)) + 'rpx',
  100. }
  101. }
  102. },
  103. methods: {
  104. rightClick() {
  105. this.$emit('click');
  106. }
  107. }
  108. }
  109. </script>
  110. <style lang="scss" scoped>
  111. @import "../../libs/css/style.components.scss";
  112. .u-section {
  113. display: flex;
  114. justify-content: space-between;
  115. align-items: center;
  116. width: 100%;
  117. &__title {
  118. position: relative;
  119. font-size: 28rpx;
  120. padding-left: 20rpx;
  121. display: flex;
  122. align-items: center;
  123. &__icon-wrap {
  124. position: absolute;
  125. }
  126. &__text {
  127. line-height: 1;
  128. }
  129. }
  130. &__right-info {
  131. color: $u-tips-color;
  132. font-size: 26rpx;
  133. display: flex;
  134. align-items: center;
  135. &__icon-arrow {
  136. margin-left: 6rpx;
  137. }
  138. }
  139. }
  140. </style>