u-section.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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" v-if="arrow">
  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 {Boolean} arrow 是否显示右边箭头(默认true)
  39. * @property {String Number} font-size 主标题的字体大小(默认28)
  40. * @property {Boolean} bold 主标题是否加粗(默认true)
  41. * @property {String} color 主标题颜色(默认#303133)
  42. * @event {Function} click 组件右侧的内容被点击时触发,用于跳转"更多"
  43. * @example <u-section title="今日热门" :right="false"></u-section>
  44. */
  45. export default {
  46. emits: ["click"],
  47. name: "u-section",
  48. props: {
  49. // 标题信息
  50. title: {
  51. type: String,
  52. default: ''
  53. },
  54. // 右边副标题内容
  55. subTitle: {
  56. type: String,
  57. default: '更多'
  58. },
  59. // 是否显示右边的内容
  60. right: {
  61. type: Boolean,
  62. default: true
  63. },
  64. fontSize: {
  65. type: [Number, String],
  66. default: 28
  67. },
  68. // 主标题是否加粗
  69. bold: {
  70. type: Boolean,
  71. default: true
  72. },
  73. // 主标题的颜色
  74. color: {
  75. type: String,
  76. default: '#303133'
  77. },
  78. // 右边副标题的颜色
  79. subColor: {
  80. type: String,
  81. default: '#909399'
  82. },
  83. // 是否显示左边的竖条
  84. showLine: {
  85. type: Boolean,
  86. default: true
  87. },
  88. // 左边竖线的颜色
  89. lineColor: {
  90. type: String,
  91. default: ''
  92. },
  93. // 是否显示右边箭头
  94. arrow: {
  95. type: Boolean,
  96. default: true
  97. },
  98. },
  99. computed: {
  100. // 左边竖条的样式
  101. lineStyle() {
  102. // 由于安卓和iOS的,需要稍微调整绝对定位的top值,才能让左边的竖线和右边的文字垂直居中
  103. return {
  104. // 由于竖线为字体图标,具有比实际线宽更宽的宽度,所以也需要根据字体打下动态调整
  105. left: -(Number(this.fontSize) * 0.9) + 'rpx',
  106. top: -(Number(this.fontSize) * (this.$u.os() == 'ios' ? 0.14 : 0.15)) + 'rpx',
  107. }
  108. }
  109. },
  110. methods: {
  111. rightClick() {
  112. this.$emit('click');
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang="scss" scoped>
  118. @import "../../libs/css/style.components.scss";
  119. .u-section {
  120. @include vue-flex;
  121. justify-content: space-between;
  122. align-items: center;
  123. width: 100%;
  124. &__title {
  125. position: relative;
  126. font-size: 28rpx;
  127. padding-left: 20rpx;
  128. @include vue-flex;
  129. align-items: center;
  130. &__icon-wrap {
  131. position: absolute;
  132. }
  133. &__text {
  134. line-height: 1;
  135. }
  136. }
  137. &__right-info {
  138. color: $u-tips-color;
  139. font-size: 26rpx;
  140. @include vue-flex;
  141. align-items: center;
  142. &__icon-arrow {
  143. margin-left: 6rpx;
  144. }
  145. }
  146. }
  147. </style>