Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

u-cell-item.vue 7.0 KiB

há 3 anos
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <view
  3. @tap="click"
  4. class="u-cell"
  5. :class="{ 'u-border-bottom': borderBottom, 'u-border-top': borderTop, 'u-col-center': center, 'u-cell--required': required }"
  6. hover-stay-time="150"
  7. :hover-class="hoverClass"
  8. :style="{
  9. backgroundColor: bgColor
  10. }"
  11. >
  12. <u-icon :size="iconSize" :name="icon" v-if="icon" :custom-style="iconStyle" class="u-cell__left-icon-wrap"></u-icon>
  13. <view class="u-flex" v-else>
  14. <slot name="icon"></slot>
  15. </view>
  16. <view
  17. class="u-cell_title"
  18. :style="[
  19. {
  20. width: titleWidth ? titleWidth + 'rpx' : 'auto'
  21. },
  22. titleStyle
  23. ]"
  24. >
  25. <block v-if="title">{{ title }}</block>
  26. <slot name="title" v-else></slot>
  27. <view class="u-cell__label" v-if="label || $slots.label" :style="[labelStyle]">
  28. <block v-if="label">{{ label }}</block>
  29. <slot name="label" v-else></slot>
  30. </view>
  31. </view>
  32. <view class="u-cell__value" :style="[valueStyle]">
  33. <block class="u-cell__value" v-if="value">{{ value }}</block>
  34. <slot v-else></slot>
  35. </view>
  36. <u-icon v-if="arrow" name="arrow-right" :style="[arrowStyle]" class="u-icon-wrap u-cell__right-icon-wrap"></u-icon>
  37. <view class="u-flex" v-if="$slots['right-icon']">
  38. <slot name="right-icon"></slot>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. /**
  44. * cellItem 单元格Item
  45. * @description cell单元格一般用于一组列表的情况,比如个人中心页,设置页等。搭配u-cell-group使用
  46. * @tutorial https://www.uviewui.com/components/cell.html
  47. * @property {String} title 左侧标题
  48. * @property {String} icon 左侧图标名,只支持uView内置图标,见Icon 图标
  49. * @property {Object} icon-style 左边图标的样式,对象形式
  50. * @property {String} value 右侧内容
  51. * @property {String} label 标题下方的描述信息
  52. * @property {Boolean} border-bottom 是否显示cell的下边框(默认true)
  53. * @property {Boolean} border-top 是否显示cell的上边框(默认false)
  54. * @property {Boolean} center 是否使内容垂直居中(默认false)
  55. * @property {String} hover-class 是否开启点击反馈,none为无效果(默认true)
  56. * // @property {Boolean} border-gap border-bottom为true时,Cell列表中间的条目的下边框是否与左边有一个间隔(默认true)
  57. * @property {Boolean} arrow 是否显示右侧箭头(默认true)
  58. * @property {Boolean} required 箭头方向,可选值(默认right)
  59. * @property {Boolean} arrow-direction 是否显示左边表示必填的星号(默认false)
  60. * @property {Object} title-style 标题样式,对象形式
  61. * @property {Object} value-style 右侧内容样式,对象形式
  62. * @property {Object} label-style 标题下方描述信息的样式,对象形式
  63. * @property {String} bg-color 背景颜色(默认transparent)
  64. * @property {String Number} index 用于在click事件回调中返回,标识当前是第几个Item
  65. * @property {String Number} title-width 标题的宽度,单位rpx
  66. * @example <u-cell-item icon="integral-fill" title="会员等级" value="新版本"></u-cell-item>
  67. */
  68. export default {
  69. name: 'u-cell-item',
  70. props: {
  71. // 左侧图标名称(只能uView内置图标),或者图标src
  72. icon: {
  73. type: String,
  74. default: ''
  75. },
  76. // 左侧标题
  77. title: {
  78. type: [String, Number],
  79. default: ''
  80. },
  81. // 右侧内容
  82. value: {
  83. type: [String, Number],
  84. default: ''
  85. },
  86. // 标题下方的描述信息
  87. label: {
  88. type: [String, Number],
  89. default: ''
  90. },
  91. // 是否显示下边框
  92. borderBottom: {
  93. type: Boolean,
  94. default: true
  95. },
  96. // 是否显示上边框
  97. borderTop: {
  98. type: Boolean,
  99. default: false
  100. },
  101. // 多个cell中,中间的cell显示下划线时,下划线是否给一个到左边的距离
  102. // 1.4.0版本废除此参数,默认边框由border-top和border-bottom提供,此参数会造成干扰
  103. // borderGap: {
  104. // type: Boolean,
  105. // default: true
  106. // },
  107. // 是否开启点击反馈,即点击时cell背景为灰色,none为无效果
  108. hoverClass: {
  109. type: String,
  110. default: 'u-cell-hover'
  111. },
  112. // 是否显示右侧箭头
  113. arrow: {
  114. type: Boolean,
  115. default: true
  116. },
  117. // 内容是否垂直居中
  118. center: {
  119. type: Boolean,
  120. default: false
  121. },
  122. // 是否显示左边表示必填的星号
  123. required: {
  124. type: Boolean,
  125. default: false
  126. },
  127. // 标题的宽度,单位rpx
  128. titleWidth: {
  129. type: [Number, String],
  130. default: ''
  131. },
  132. // 右侧箭头方向,可选值:right|up|down,默认为right
  133. arrowDirection: {
  134. type: String,
  135. default: 'right'
  136. },
  137. // 控制标题的样式
  138. titleStyle: {
  139. type: Object,
  140. default() {
  141. return {};
  142. }
  143. },
  144. // 右侧显示内容的样式
  145. valueStyle: {
  146. type: Object,
  147. default() {
  148. return {};
  149. }
  150. },
  151. // 描述信息的样式
  152. labelStyle: {
  153. type: Object,
  154. default() {
  155. return {};
  156. }
  157. },
  158. // 背景颜色
  159. bgColor: {
  160. type: String,
  161. default: 'transparent'
  162. },
  163. // 用于识别被点击的是第几个cell
  164. index: {
  165. type: [String, Number],
  166. default: ''
  167. },
  168. // 是否使用lable插槽
  169. useLabelSlot: {
  170. type: Boolean,
  171. default: false
  172. },
  173. // 左边图标的大小,单位rpx,只对传入icon字段时有效
  174. iconSize: {
  175. type: [Number, String],
  176. default: 34
  177. },
  178. // 左边图标的样式,对象形式
  179. iconStyle: {
  180. type: Object,
  181. default() {
  182. return {}
  183. }
  184. },
  185. },
  186. data() {
  187. return {
  188. };
  189. },
  190. computed: {
  191. arrowStyle() {
  192. let style = {};
  193. if (this.arrowDirection == 'up') style.transform = 'rotate(-90deg)';
  194. else if (this.arrowDirection == 'down') style.transform = 'rotate(90deg)';
  195. else style.transform = 'rotate(0deg)';
  196. return style;
  197. }
  198. },
  199. methods: {
  200. click() {
  201. this.$emit('click', this.index);
  202. }
  203. }
  204. };
  205. </script>
  206. <style lang="scss" scoped>
  207. @import "../../libs/css/style.components.scss";
  208. .u-cell {
  209. position: relative;
  210. display: flex;
  211. box-sizing: border-box;
  212. width: 100%;
  213. padding: 26rpx 32rpx;
  214. font-size: 28rpx;
  215. line-height: 54rpx;
  216. color: $u-content-color;
  217. background-color: #fff;
  218. text-align: left;
  219. }
  220. .u-cell_title {
  221. font-size: 28rpx;
  222. }
  223. .u-cell__left-icon-wrap {
  224. margin-right: 10rpx;
  225. font-size: 32rpx;
  226. }
  227. .u-cell__right-icon-wrap {
  228. margin-left: 10rpx;
  229. color: #969799;
  230. font-size: 28rpx;
  231. }
  232. .u-cell__left-icon-wrap,
  233. .u-cell__right-icon-wrap {
  234. display: flex;
  235. align-items: center;
  236. height: 48rpx;
  237. }
  238. .u-cell-border:after {
  239. position: absolute;
  240. box-sizing: border-box;
  241. content: ' ';
  242. pointer-events: none;
  243. right: 0;
  244. left: 0;
  245. top: 0;
  246. border-bottom: 1px solid $u-border-color;
  247. -webkit-transform: scaleY(0.5);
  248. transform: scaleY(0.5);
  249. }
  250. .u-cell-border {
  251. position: relative;
  252. }
  253. .u-cell__label {
  254. margin-top: 6rpx;
  255. font-size: 26rpx;
  256. line-height: 36rpx;
  257. color: $u-tips-color;
  258. word-wrap: break-word;
  259. }
  260. .u-cell__value {
  261. overflow: hidden;
  262. text-align: right;
  263. vertical-align: middle;
  264. color: $u-tips-color;
  265. font-size: 26rpx;
  266. }
  267. .u-cell__title,
  268. .u-cell__value {
  269. flex: 1;
  270. }
  271. .u-cell--required {
  272. overflow: visible;
  273. display: flex;
  274. align-items: center;
  275. }
  276. .u-cell--required:before {
  277. position: absolute;
  278. content: '*';
  279. left: 8px;
  280. margin-top: 4rpx;
  281. font-size: 14px;
  282. color: $u-type-error;
  283. }
  284. </style>