tn-list-view.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <view
  3. class="tn-list-view-class tn-list-view"
  4. :class="[
  5. backgroundColorClass,
  6. viewClass
  7. ]"
  8. :style="[viewStyle]"
  9. >
  10. <view
  11. v-if="showTitle"
  12. class="tn-list-view__title"
  13. :class="[
  14. fontColorClass
  15. ]"
  16. :style="[titleStyle]"
  17. @tap="handleClickTitle"
  18. >{{ title }}</view>
  19. <view
  20. v-else
  21. :class="[{'tn-list-view__title--card': card}]"
  22. @tap="handleClickTitle"
  23. >
  24. <slot name="title"></slot>
  25. </view>
  26. <view
  27. class="tn-list-view__content tn-border-solid-top tn-border-solid-bottom"
  28. :class="[contentClass]"
  29. >
  30. <slot></slot>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import componentsColorMixin from '../../libs/mixin/components_color.js'
  36. export default {
  37. mixins: [ componentsColorMixin ],
  38. name: 'tn-list-view',
  39. props: {
  40. // 标题
  41. title: {
  42. type: String,
  43. default: ''
  44. },
  45. // 去掉边框 上边框 top, 下边框 bottom, 所有边框 all
  46. unlined: {
  47. type: String,
  48. default: 'all'
  49. },
  50. // 上外边距
  51. marginTop: {
  52. type: String,
  53. default: ''
  54. },
  55. // 内容是否显示为卡片模式
  56. card: {
  57. type: Boolean,
  58. default: false
  59. },
  60. // 是否自定义标题
  61. customTitle: {
  62. type: Boolean,
  63. default: false
  64. }
  65. },
  66. computed: {
  67. showTitle() {
  68. return !this.customTitle && this.title
  69. },
  70. viewClass() {
  71. let clazz = ''
  72. if (this.card) {
  73. clazz += ' tn-list-view--card'
  74. }
  75. return clazz
  76. },
  77. viewStyle() {
  78. let style = {}
  79. if (this.backgroundColorStyle) {
  80. style.backgroundColor = this.backgroundColorStyle
  81. }
  82. if (this.marginTop) {
  83. style.marginTop = this.marginTop
  84. }
  85. return style
  86. },
  87. titleStyle() {
  88. let style = {}
  89. if (this.fontColorStyle) {
  90. style.color = this.fontColorStyle
  91. }
  92. if (this.fontSize) {
  93. style.fontSize = this.fontSize + this.fontUnit
  94. }
  95. return style
  96. },
  97. contentClass() {
  98. let clazz = ''
  99. if (this.card) {
  100. clazz += ' tn-list-view__content--card'
  101. }
  102. switch(this.unlined) {
  103. case 'top':
  104. clazz += ' tn-none-border-top'
  105. break
  106. case 'bottom':
  107. clazz += ' tn-none-border-bottom'
  108. break
  109. case 'all':
  110. clazz += ' tn-none-border'
  111. break
  112. }
  113. return clazz
  114. }
  115. },
  116. data () {
  117. return {
  118. kindShowFlag: this.showKind
  119. }
  120. },
  121. methods: {
  122. // 处理标题点击事件
  123. handleClickTitle() {
  124. if (!this.kindList) return
  125. this.kindShowFlag = !this.kindShowFlag
  126. this.$emit("clickTitle", {})
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .tn-list-view {
  133. background-color: #FFFFFF;
  134. &__title {
  135. width: 100%;
  136. padding: 30rpx;
  137. font-size: 30rpx;
  138. line-height: 30rpx;
  139. box-sizing: border-box;
  140. &--card {
  141. // margin: 0rpx 30rpx;
  142. }
  143. }
  144. &__content {
  145. width: 100%;
  146. position: relative;
  147. border-radius: 0;
  148. &--card {
  149. // width: auto;
  150. // overflow: hidden;
  151. // margin-right: 30rpx;
  152. // margin-left: 30rpx;
  153. // border-radius: 20rpx
  154. }
  155. }
  156. &--card {
  157. // padding-bottom: 30rpx;
  158. border-radius: 20rpx;
  159. overflow: hidden;
  160. }
  161. }
  162. </style>