tn-list-cell.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view
  3. class="tn-list-cell-class tn-list-cell"
  4. :class="[
  5. backgroundColorClass,
  6. fontColorClass,
  7. cellClass
  8. ]"
  9. :hover-class="hover ? 'tn-hover' : ''"
  10. :hover-stay-time="150"
  11. :style="[cellStyle]"
  12. @tap="handleClick"
  13. >
  14. <slot></slot>
  15. </view>
  16. </template>
  17. <script>
  18. import componentsColorMixin from '../../libs/mixin/components_color.js'
  19. export default {
  20. mixins: [ componentsColorMixin ],
  21. name: 'tn-list-cell',
  22. props: {
  23. // 列表序号
  24. index: {
  25. type: [Number, String],
  26. default: '0'
  27. },
  28. // 内边距
  29. padding: {
  30. type: String,
  31. default: ''
  32. },
  33. // 是否有箭头
  34. arrow: {
  35. type: Boolean,
  36. default: false
  37. },
  38. //箭头是否有偏移距离
  39. arrowRight: {
  40. type: Boolean,
  41. default: true
  42. },
  43. // 是否有点击效果
  44. hover: {
  45. type: Boolean,
  46. default: false
  47. },
  48. // 隐藏线条
  49. unlined: {
  50. type: Boolean,
  51. default: false
  52. },
  53. //线条是否有左偏移距离
  54. lineLeft: {
  55. type: Boolean,
  56. default: true
  57. },
  58. //线条是否有右偏移距离
  59. lineRight: {
  60. type: Boolean,
  61. default: true
  62. },
  63. //是否加圆角
  64. radius: {
  65. type: Boolean,
  66. default: false
  67. }
  68. },
  69. computed: {
  70. cellClass() {
  71. let clazz = ''
  72. if (this.arrow) {
  73. clazz += ' tn-list-cell--arrow'
  74. if (!this.arrowRight) {
  75. clazz += ' tn-list-cell--arrow--none-right'
  76. }
  77. }
  78. if (this.unlined) {
  79. clazz += ' tn-list-cell--unlined'
  80. } else {
  81. if (this.lineLeft) {
  82. clazz += ' tn-list-cell--line-left'
  83. }
  84. if (this.lineRight) {
  85. clazz += ' tn-list-cell--line-right'
  86. }
  87. }
  88. if (this.radius) {
  89. clazz += ' tn-list-cell--radius'
  90. }
  91. return clazz
  92. },
  93. cellStyle() {
  94. let style = {}
  95. if (this.backgroundColorStyle) {
  96. style.backgroundColor = this.backgroundColorStyle
  97. }
  98. if (this.fontColorStyle) {
  99. style.color = this.fontColorStyle
  100. }
  101. if (this.fontSize) {
  102. style.fontSize = this.fontSize + this.fontUnit
  103. }
  104. if (this.padding) {
  105. style.padding = this.padding
  106. }
  107. return style
  108. },
  109. },
  110. data() {
  111. return {
  112. }
  113. },
  114. methods: {
  115. // 处理点击事件
  116. handleClick() {
  117. this.$emit("click", {
  118. index: Number(this.index)
  119. })
  120. this.$emit("tap", {
  121. index: Number(this.index)
  122. })
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. .tn-list-cell {
  129. position: relative;
  130. width: 100%;
  131. box-sizing: border-box;
  132. background-color: #FFFFFF;
  133. color: $tn-font-color;
  134. font-size: 28rpx;
  135. padding: 26rpx 30rpx;
  136. &--radius {
  137. border-radius: 12rpx;
  138. overflow: hidden;
  139. }
  140. &--arrow {
  141. &::before {
  142. content: " ";
  143. position: absolute;
  144. top: 50%;
  145. right: 30rpx;
  146. width: 20rpx;
  147. height: 20rpx;
  148. margin-top: -12rpx;
  149. border-width: 4rpx 4rpx 0 0;
  150. border-color: $tn-font-holder-color;
  151. border-style: solid;
  152. transform: matrix(0.5, 0.5, -0.5, 0.5, 0, 0);
  153. }
  154. &--none-right {
  155. &::before {
  156. right: 0 !important;
  157. }
  158. }
  159. }
  160. &::after {
  161. content: " ";
  162. position: absolute;
  163. bottom: 0;
  164. right: 0;
  165. left: 0;
  166. pointer-events: none;
  167. border-bottom: 1px solid $tn-border-solid-color;
  168. transform: scaleY(0.5) translateZ(0);
  169. transform-origin: 0 100%;
  170. }
  171. &--line-left {
  172. &::after {
  173. left: 30rpx !important;
  174. }
  175. }
  176. &--line-right {
  177. &::after {
  178. right: 30rpx !important;
  179. }
  180. }
  181. &--unlined {
  182. &::after {
  183. border-bottom: 0 !important;
  184. }
  185. }
  186. }
  187. </style>