uni-section.vue 3.6 KB

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