uni-list-item.vue 4.4 KB

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