uni-list-item.vue 4.3 KB

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