uni-section.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="uni-section">
  3. <view class="uni-section-header" @click="onClick">
  4. <view class="uni-section-header__decoration" v-if="type" :class="type" />
  5. <slot v-else name="decoration"></slot>
  6. <view class="uni-section-header__content">
  7. <text :style="{'font-size':titleFontSize,'color':titleColor}" class="uni-section__content-title" :class="{'distraction':!subTitle}">{{ title }}</text>
  8. <text v-if="subTitle" :style="{'font-size':subTitleFontSize,'color':subTitleColor}" class="uni-section-header__content-sub">{{ subTitle }}</text>
  9. </view>
  10. <view class="uni-section-header__slot-right">
  11. <slot name="right"></slot>
  12. </view>
  13. </view>
  14. <view class="uni-section-content" :style="{padding: _padding}">
  15. <slot />
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. /**
  21. * Section 标题栏
  22. * @description 标题栏
  23. * @property {String} type = [line|circle|square] 标题装饰类型
  24. * @value line 竖线
  25. * @value circle 圆形
  26. * @value square 正方形
  27. * @property {String} title 主标题
  28. * @property {String} titleFontSize 主标题字体大小
  29. * @property {String} titleColor 主标题字体颜色
  30. * @property {String} subTitle 副标题
  31. * @property {String} subTitleFontSize 副标题字体大小
  32. * @property {String} subTitleColor 副标题字体颜色
  33. * @property {String} padding 默认插槽 padding
  34. */
  35. export default {
  36. name: 'UniSection',
  37. emits: ['click'],
  38. props: {
  39. type: {
  40. type: String,
  41. default: ''
  42. },
  43. title: {
  44. type: String,
  45. required: true,
  46. default: ''
  47. },
  48. titleFontSize: {
  49. type: String,
  50. default: '14px'
  51. },
  52. titleColor: {
  53. type: String,
  54. default: '#333'
  55. },
  56. subTitle: {
  57. type: String,
  58. default: ''
  59. },
  60. subTitleFontSize: {
  61. type: String,
  62. default: '12px'
  63. },
  64. subTitleColor: {
  65. type: String,
  66. default: '#999'
  67. },
  68. padding: {
  69. type: [Boolean, String],
  70. default: false
  71. }
  72. },
  73. computed: {
  74. _padding() {
  75. if (typeof this.padding === 'string') {
  76. return this.padding
  77. }
  78. return this.padding ? '10px' : ''
  79. }
  80. },
  81. watch: {
  82. title(newVal) {
  83. if (uni.report && newVal !== '') {
  84. uni.report('title', newVal)
  85. }
  86. }
  87. },
  88. methods: {
  89. onClick() {
  90. this.$emit('click')
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss">
  96. $uni-primary: #2979ff !default;
  97. .uni-section {
  98. background-color: #fff;
  99. margin: 15rpx 0;
  100. border-radius: 10rpx;
  101. .uni-section-header {
  102. position: relative;
  103. /* #ifndef APP-NVUE */
  104. display: flex;
  105. /* #endif */
  106. flex-direction: row;
  107. align-items: center;
  108. padding: 12px 10px;
  109. font-weight: normal;
  110. &__decoration {
  111. margin-right: 6px;
  112. background-color: $uni-primary;
  113. &.line {
  114. width: 4px;
  115. height: 12px;
  116. border-radius: 10px;
  117. }
  118. &.circle {
  119. width: 8px;
  120. height: 8px;
  121. border-top-right-radius: 50px;
  122. border-top-left-radius: 50px;
  123. border-bottom-left-radius: 50px;
  124. border-bottom-right-radius: 50px;
  125. }
  126. &.square {
  127. width: 8px;
  128. height: 8px;
  129. }
  130. }
  131. &__content {
  132. /* #ifndef APP-NVUE */
  133. display: flex;
  134. /* #endif */
  135. flex-direction: column;
  136. flex: 1;
  137. color: #333;
  138. .distraction {
  139. flex-direction: row;
  140. align-items: center;
  141. }
  142. &-sub {
  143. margin-top: 2px;
  144. }
  145. }
  146. &__slot-right {
  147. font-size: 14px;
  148. }
  149. }
  150. .uni-section-content {
  151. font-size: 14px;
  152. }
  153. }
  154. </style>