uni-list-item.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <!-- #ifdef APP-NVUE -->
  3. <cell>
  4. <!-- #endif -->
  5. <view :class="disabled ? 'uni-list-item--disabled' : ''" :hover-class="disabled || showSwitch ? '' : 'uni-list-item--hover'"
  6. class="uni-list-item" @click="onClick">
  7. <view class="uni-list-item__container" :class="{'uni-list-item--first':isFirstChild}">
  8. <view v-if="thumb" class="uni-list-item__icon">
  9. <image :src="thumb" class="uni-list-item__icon-img" />
  10. </view>
  11. <view v-else-if="showExtraIcon" class="uni-list-item__icon">
  12. <uni-icons :color="extraIcon.color" :size="extraIcon.size" :type="extraIcon.type" class="uni-icon-wrapper" />
  13. </view>
  14. <view class="uni-list-item__content">
  15. <slot />
  16. <text class="uni-list-item__content-title">{{ title }}</text>
  17. <text v-if="note" class="uni-list-item__content-note">{{ note }}</text>
  18. </view>
  19. <view class="uni-list-item__extra">
  20. <text v-if="rightText" class="uni-list-item__extra-text">{{rightText}}</text>
  21. <image v-if="rightImage" :src="rightImage" class="uni-list-item__image"></image>
  22. <uni-badge v-if="showBadge" :type="badgeType" :text="badgeText" />
  23. <switch v-if="showSwitch" :disabled="disabled" :checked="switchChecked" @change="onSwitchChange" />
  24. <slot name="right"></slot>
  25. <uni-icons v-if="showArrow" :size="20" class="uni-icon-wrapper" color="#bbb" type="arrowright" />
  26. </view>
  27. </view>
  28. </view>
  29. <!-- #ifdef APP-NVUE -->
  30. </cell>
  31. <!-- #endif -->
  32. </template>
  33. <script>
  34. import uniIcons from '../uni-icons/uni-icons.vue'
  35. import uniBadge from '../uni-badge/uni-badge.vue'
  36. /**
  37. * ListItem 列表子组件
  38. * @description 列表子组件
  39. * @tutorial https://ext.dcloud.net.cn/plugin?id=24
  40. * @property {String} title 标题
  41. * @property {String} note 描述
  42. * @property {String} thumb 左侧缩略图,若thumb有值,则不会显示扩展图标
  43. * @property {String} badgeText 数字角标内容
  44. * @property {String} badgeType 数字角标类型,参考[uni-icons](https://ext.dcloud.net.cn/plugin?id=21)
  45. * @property {String} rightText 右侧文字内容
  46. * @property {Boolean} disabled = [true|false]是否禁用
  47. * @property {Boolean} showArrow = [true|false] 是否显示箭头图标
  48. * @property {Boolean} showBadge = [true|false] 是否显示数字角标
  49. * @property {Boolean} showSwitch = [true|false] 是否显示Switch
  50. * @property {Boolean} switchChecked = [true|false] Switch是否被选中
  51. * @property {Boolean} showExtraIcon = [true|false] 左侧是否显示扩展图标
  52. * @property {Boolean} scrollY = [true|false] 允许纵向滚动,需要显式的设置其宽高
  53. * @property {Object} extraIcon 扩展图标参数,格式为 {color: '#4cd964',size: '22',type: 'spinner'}
  54. * @event {Function} click 点击 uniListItem 触发事件
  55. * @event {Function} switchChange 点击切换 Switch 时触发
  56. */
  57. export default {
  58. name: 'UniListItem',
  59. components: {
  60. uniIcons,
  61. uniBadge
  62. },
  63. props: {
  64. rightImage:{
  65. type: String,
  66. default: ''
  67. },
  68. title: {
  69. type: String,
  70. default: ''
  71. }, // 列表标题
  72. note: {
  73. type: String,
  74. default: ''
  75. }, // 列表描述
  76. disabled: {
  77. // 是否禁用
  78. type: [Boolean, String],
  79. default: false
  80. },
  81. showArrow: {
  82. // 是否显示箭头
  83. type: [Boolean, String],
  84. default: true
  85. },
  86. showBadge: {
  87. // 是否显示数字角标
  88. type: [Boolean, String],
  89. default: false
  90. },
  91. showSwitch: {
  92. // 是否显示Switch
  93. type: [Boolean, String],
  94. default: false
  95. },
  96. switchChecked: {
  97. // Switch是否被选中
  98. type: [Boolean, String],
  99. default: false
  100. },
  101. badgeText: {
  102. // badge内容
  103. type: String,
  104. default: ''
  105. },
  106. badgeType: {
  107. // badge类型
  108. type: String,
  109. default: 'success'
  110. },
  111. rightText: {
  112. // 右侧文字内容
  113. type: String,
  114. default: ''
  115. },
  116. thumb: {
  117. // 缩略图
  118. type: String,
  119. default: ''
  120. },
  121. showExtraIcon: {
  122. // 是否显示扩展图标
  123. type: [Boolean, String],
  124. default: false
  125. },
  126. extraIcon: {
  127. type: Object,
  128. default () {
  129. return {
  130. type: 'contact',
  131. color: '#000000',
  132. size: 20
  133. }
  134. }
  135. }
  136. },
  137. inject: ['list'],
  138. data() {
  139. return {
  140. isFirstChild: false
  141. }
  142. },
  143. mounted() {
  144. if (!this.list.firstChildAppend) {
  145. this.list.firstChildAppend = true
  146. this.isFirstChild = true
  147. }
  148. },
  149. methods: {
  150. onClick() {
  151. this.$emit('click')
  152. },
  153. setTitle(title){
  154. this.title = title
  155. },
  156. onSwitchChange(e) {
  157. this.$emit('switchChange', e.detail)
  158. }
  159. }
  160. }
  161. </script>
  162. <!--padding-left: $uni-spacing-row-lg;-->
  163. <style lang="scss" scoped>
  164. $list-item-pd: $uni-spacing-col-lg $uni-spacing-row-lg;
  165. .uni-list-item {
  166. font-size: $uni-font-size-lg;
  167. position: relative;
  168. flex-direction: column;
  169. justify-content: space-between;
  170. }
  171. .uni-list-item--disabled {
  172. opacity: 0.3;
  173. }
  174. .uni-list-item--hover {
  175. background-color: $uni-bg-color-hover;
  176. }
  177. .uni-list-item__container {
  178. position: relative;
  179. /* #ifndef APP-NVUE */
  180. display: flex;
  181. /* #endif */
  182. flex-direction: row;
  183. padding: $list-item-pd;
  184. padding-left: 12px;
  185. flex: 1;
  186. position: relative;
  187. justify-content: space-between;
  188. align-items: center;
  189. /* #ifdef APP-PLUS */
  190. border-top-color: $uni-border-color;
  191. border-top-style: solid;
  192. border-top-width: 0.5px;
  193. /* #endif */
  194. }
  195. .uni-list-item--first {
  196. border-top-width: 0px;
  197. }
  198. /* #ifndef APP-NVUE */
  199. .uni-list-item__container:after {
  200. position: absolute;
  201. top: 0;
  202. right: 0;
  203. left: 0;
  204. height: 1px;
  205. content: '';
  206. -webkit-transform: scaleY(.5);
  207. transform: scaleY(.5);
  208. background-color: $uni-border-color;
  209. }
  210. .uni-list-item--first:after {
  211. height: 0px;
  212. }
  213. /* #endif */
  214. .uni-list-item__content {
  215. /* #ifndef APP-NVUE */
  216. display: flex;
  217. /* #endif */
  218. flex: 1;
  219. overflow: hidden;
  220. flex-direction: column;
  221. color: #3b4144;
  222. }
  223. .uni-list-item__content-title {
  224. font-size: 13px;
  225. color: black;
  226. font-weight: 400;
  227. margin-left: 10px;
  228. margin-right: 10px;
  229. }
  230. .uni-list-item__content-note {
  231. margin-top: 6rpx;
  232. color: $uni-text-color-grey;
  233. font-size: $uni-font-size-sm;
  234. overflow: hidden;
  235. }
  236. .uni-list-item__extra {
  237. // width: 25%;
  238. /* #ifndef APP-NVUE */
  239. display: flex;
  240. /* #endif */
  241. flex-direction: row;
  242. justify-content: flex-end;
  243. align-items: center;
  244. }
  245. .uni-list-item__icon {
  246. margin-right: 18rpx;
  247. flex-direction: row;
  248. justify-content: center;
  249. align-items: center;
  250. }
  251. .uni-list-item__icon-img {
  252. height: $uni-img-size-base;
  253. width: $uni-img-size-base;
  254. }
  255. .uni-list-item__extra-text {
  256. color: $uni-text-color-grey;
  257. font-size: $uni-font-size-sm;
  258. word-break: break-all;
  259. width: 400rpx;
  260. }
  261. .uni-list-item__image{
  262. width: 40px;
  263. height: 40px;
  264. margin-right: 320rpx;
  265. }
  266. </style>