uni-section.vue 2.9 KB

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