uni-list-item.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view
  3. :class="disabled ? 'uni-list-item--disabled' : ''"
  4. :hover-class="disabled || showSwitch ? '' : 'uni-list-item--hover'"
  5. class="uni-list-item"
  6. @click="onClick">
  7. <view class="uni-list-item__container">
  8. <view
  9. v-if="thumb"
  10. class="uni-list-item__icon"><image
  11. :src="thumb"
  12. class="uni-list-item__icon-img" /></view>
  13. <view
  14. v-else-if="showExtraIcon"
  15. class="uni-list-item__icon">
  16. <uni-icons
  17. :color="extraIcon.color"
  18. :size="extraIcon.size"
  19. :type="extraIcon.type"
  20. class="uni-icon-wrapper" />
  21. </view>
  22. <view class="uni-list-item__content">
  23. <view class="uni-list-item__content-title">{{ title }}</view>
  24. <view
  25. v-if="note"
  26. class="uni-list-item__content-note">{{ note }}</view>
  27. </view>
  28. <view
  29. v-if="showBadge || showArrow || showSwitch"
  30. class="uni-list-item__extra">
  31. <uni-badge
  32. v-if="showBadge"
  33. :type="badgeType"
  34. :text="badgeText" />
  35. <switch
  36. v-if="showSwitch"
  37. :disabled="disabled"
  38. :checked="switchChecked"
  39. @change="onSwitchChange" />
  40. <uni-icons
  41. v-if="showArrow"
  42. :size="20"
  43. class="uni-icon-wrapper"
  44. color="#bbb"
  45. type="arrowright" />
  46. </view>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import uniIcons from '../uni-icons/uni-icons.vue'
  52. import uniBadge from '../uni-badge/uni-badge.vue'
  53. export default {
  54. name: 'UniListItem',
  55. components: {
  56. uniIcons,
  57. uniBadge
  58. },
  59. props: {
  60. title: {
  61. type: String,
  62. default: ''
  63. }, // 列表标题
  64. note: {
  65. type: String,
  66. default: ''
  67. }, // 列表描述
  68. disabled: {
  69. // 是否禁用
  70. type: [Boolean, String],
  71. default: false
  72. },
  73. showArrow: {
  74. // 是否显示箭头
  75. type: [Boolean, String],
  76. default: true
  77. },
  78. showBadge: {
  79. // 是否显示数字角标
  80. type: [Boolean, String],
  81. default: false
  82. },
  83. showSwitch: {
  84. // 是否显示Switch
  85. type: [Boolean, String],
  86. default: false
  87. },
  88. switchChecked: {
  89. // Switch是否被选中
  90. type: [Boolean, String],
  91. default: false
  92. },
  93. badgeText: {
  94. // badge内容
  95. type: String,
  96. default: ''
  97. },
  98. badgeType: {
  99. // badge类型
  100. type: String,
  101. default: 'success'
  102. },
  103. thumb: {
  104. // 缩略图
  105. type: String,
  106. default: ''
  107. },
  108. showExtraIcon: {
  109. // 是否显示扩展图标
  110. type: [Boolean, String],
  111. default: false
  112. },
  113. extraIcon: {
  114. type: Object,
  115. default () {
  116. return {
  117. type: 'contact',
  118. color: '#000000',
  119. size: 20
  120. }
  121. }
  122. }
  123. },
  124. data () {
  125. return {}
  126. },
  127. methods: {
  128. onClick () {
  129. this.$emit('click')
  130. },
  131. onSwitchChange (e) {
  132. this.$emit('switchChange', e.detail)
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss">
  138. @mixin list-hover {
  139. background-color: $uni-bg-color-hover;
  140. }
  141. @mixin list-disabled {
  142. opacity: 0.3;
  143. }
  144. $list-item-pd: $uni-spacing-col-lg $uni-spacing-row-lg;
  145. .uni-list-item {
  146. font-size: $uni-font-size-lg;
  147. position: relative;
  148. display: flex;
  149. flex-direction: column;
  150. justify-content: space-between;
  151. align-items: center;
  152. // height:130rpx ;
  153. &--disabled {
  154. @include list-disabled;
  155. }
  156. // &--hover {
  157. // @include list-hover;
  158. // }
  159. &__container {
  160. padding: $list-item-pd;
  161. width: 100%;
  162. box-sizing: border-box;
  163. flex: 1;
  164. position: relative;
  165. display: flex;
  166. flex-direction: row;
  167. justify-content: space-between;
  168. align-items: center;
  169. &:after {
  170. position: absolute;
  171. z-index: 3;
  172. right: 0;
  173. bottom: 0;
  174. left: 30rpx;
  175. height: 1px;
  176. content: '';
  177. -webkit-transform: scaleY(0.5);
  178. transform: scaleY(0.5);
  179. background-color: #464755;
  180. }
  181. }
  182. &__content {
  183. flex: 1;
  184. overflow: hidden;
  185. display: flex;
  186. flex-direction: column;
  187. color: #FFFFFF;
  188. &-title {
  189. font-size:30rpx;
  190. text-overflow: ellipsis;
  191. white-space: nowrap;
  192. color: inherit;
  193. line-height: 1.5;
  194. overflow: hidden;
  195. }
  196. &-note {
  197. margin-top: 6rpx;
  198. color: #85858E;
  199. font-size: 22rpx;
  200. white-space: normal;
  201. display: -webkit-box;
  202. -webkit-box-orient: vertical;
  203. -webkit-line-clamp: 2;
  204. overflow: hidden;
  205. }
  206. }
  207. &__extra {
  208. width: 25%;
  209. display: flex;
  210. flex-direction: row;
  211. justify-content: flex-end;
  212. align-items: center;
  213. }
  214. &__icon {
  215. margin-right: 40rpx;
  216. display: flex;
  217. flex-direction: row;
  218. justify-content: center;
  219. align-items: center;
  220. &-img {
  221. height: 35rpx;
  222. width: 35rpx;
  223. }
  224. }
  225. }
  226. .uni-list > .uni-list-item:last-child .uni-list-item-container:after {
  227. height: 0px;
  228. }
  229. </style>