AI销管
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

155 linhas
3.9 KiB

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