uni-section.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. .uni-section-header {
  100. position: relative;
  101. /* #ifndef APP-NVUE */
  102. display: flex;
  103. /* #endif */
  104. flex-direction: row;
  105. align-items: center;
  106. padding: 12px 10px;
  107. font-weight: normal;
  108. &__decoration{
  109. margin-right: 6px;
  110. background-color: $uni-primary;
  111. &.line {
  112. width: 4px;
  113. height: 12px;
  114. border-radius: 10px;
  115. }
  116. &.circle {
  117. width: 8px;
  118. height: 8px;
  119. border-top-right-radius: 50px;
  120. border-top-left-radius: 50px;
  121. border-bottom-left-radius: 50px;
  122. border-bottom-right-radius: 50px;
  123. }
  124. &.square {
  125. width: 8px;
  126. height: 8px;
  127. }
  128. }
  129. &__content {
  130. /* #ifndef APP-NVUE */
  131. display: flex;
  132. /* #endif */
  133. flex-direction: column;
  134. flex: 1;
  135. color: #333;
  136. .distraction {
  137. flex-direction: row;
  138. align-items: center;
  139. }
  140. &-sub {
  141. margin-top: 2px;
  142. }
  143. }
  144. &__slot-right{
  145. font-size: 14px;
  146. }
  147. }
  148. .uni-section-content{
  149. font-size: 14px;
  150. }
  151. }
  152. </style>