uni-section.vue 3.5 KB

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