uni-events-helper-wx
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
7.3 KiB

3 years ago
  1. <template>
  2. <view class="u-cell" :class="[customClass]" :style="[$u.addStyle(customStyle)]"
  3. :hover-class="(!disabled && (clickable || isLink)) ? 'u-cell--clickable' : ''" :hover-stay-time="250"
  4. @tap="clickHandler">
  5. <view class="u-cell__body" :class="[ center && 'u-cell--center', size === 'large' && 'u-cell__body--large']">
  6. <view class="u-cell__body__content">
  7. <view class="u-cell__left-icon-wrap" v-if="$slots.icon || icon">
  8. <slot name="icon" v-if="$slots.icon">
  9. </slot>
  10. <u-icon v-else :name="icon" :custom-style="iconStyle" :size="size === 'large' ? 22 : 18"></u-icon>
  11. </view>
  12. <view class="u-cell__title">
  13. <slot name="title">
  14. <text v-if="title" class="u-cell__title-text"
  15. :class="[disabled && 'u-cell--disabled', size === 'large' && 'u-cell__title-text--large']">{{ title }}</text>
  16. </slot>
  17. <slot name="label">
  18. <text class="u-cell__label" v-if="label"
  19. :class="[disabled && 'u-cell--disabled', size === 'large' && 'u-cell__label--large']">{{ label }}</text>
  20. </slot>
  21. </view>
  22. </view>
  23. <slot name="value">
  24. <text class="u-cell__value"
  25. :class="[disabled && 'u-cell--disabled', size === 'large' && 'u-cell__value--large']"
  26. v-if="!$u.test.empty(value)">{{ value }}</text>
  27. </slot>
  28. <view class="u-cell__right-icon-wrap" v-if="$slots['right-icon'] || isLink"
  29. :class="[`u-cell__right-icon-wrap--${arrowDirection}`]">
  30. <slot name="right-icon" v-if="$slots['right-icon']">
  31. </slot>
  32. <u-icon v-else :name="rightIcon" :custom-style="rightIconStyle" :color="disabled ? '#c8c9cc' : 'info'"
  33. :size="size === 'large' ? 18 : 16"></u-icon>
  34. </view>
  35. </view>
  36. <u-line v-if="border"></u-line>
  37. </view>
  38. </template>
  39. <script>
  40. import props from './props.js';
  41. /**
  42. * cell 单元格
  43. * @description cell单元格一般用于一组列表的情况比如个人中心页设置页等
  44. * @tutorial https://uviewui.com/components/cell.html
  45. * @property {String | Number} title 标题
  46. * @property {String | Number} label 标题下方的描述信息
  47. * @property {String | Number} value 右侧的内容
  48. * @property {String} icon 左侧图标名称或者图片链接(本地文件建议使用绝对地址)
  49. * @property {String | Number} titleWidth 标题的宽度单位任意数值默认为px单位
  50. * @property {Boolean} disabled 是否禁用cell
  51. * @property {Boolean} border 是否显示下边框 (默认 true )
  52. * @property {Boolean} center 内容是否垂直居中(主要是针对右侧的value部分) (默认 false )
  53. * @property {String} url 点击后跳转的URL地址
  54. * @property {String} linkType 链接跳转的方式内部使用的是uView封装的route方法可能会进行拦截操作 (默认 'navigateTo' )
  55. * @property {Boolean} clickable 是否开启点击反馈(表现为点击时加上灰色背景) 默认 false
  56. * @property {Boolean} isLink 是否展示右侧箭头并开启点击反馈 默认 false
  57. * @property {Boolean} required 是否显示表单状态下的必填星号(此组件可能会内嵌入input组件) 默认 false
  58. * @property {String} rightIcon 右侧的图标箭头 默认 'arrow-right'
  59. * @property {String} arrowDirection 右侧箭头的方向可选值为leftupdown
  60. * @property {Object} rightIconStyle 右侧箭头图标的样式
  61. * @property {Object} titleStyle 标题的样式
  62. * @property {String} size 单位元的大小可选值为 largenormalmini
  63. * @property {Boolean} stop 点击cell是否阻止事件传播 (默认 true )
  64. * @property {Object} customStyle 定义需要用到的外部样式
  65. *
  66. * @event {Function} click 点击cell列表时触发
  67. * @example 该组件需要搭配cell-group组件使用见官方文档示例
  68. */
  69. export default {
  70. name: 'u-cell',
  71. data() {
  72. return {
  73. }
  74. },
  75. mixins: [uni.$u.mpMixin, uni.$u.mixin, props],
  76. methods: {
  77. // 点击cell
  78. clickHandler(e) {
  79. if (this.disabled) return
  80. this.$emit('click', {
  81. name: this.name
  82. })
  83. // 如果配置了url(此props参数通过mixin引入)参数,跳转页面
  84. this.openPage()
  85. // 是否阻止事件传播
  86. this.stop && this.preventEvent(e)
  87. },
  88. }
  89. }
  90. </script>
  91. <style lang="scss">
  92. @import "../../libs/css/components.scss";
  93. $u-cell-padding: 10px 15px !default;
  94. $u-cell-font-size: 15px !default;
  95. $u-cell-line-height: 24px !default;
  96. $u-cell-color: $u-main-color !default;
  97. $u-cell-icon-size: 16px !default;
  98. $u-cell-title-font-size: 15px !default;
  99. $u-cell-title-line-height: 22px !default;
  100. $u-cell-title-color: $u-main-color !default;
  101. $u-cell-label-font-size: 12px !default;
  102. $u-cell-label-color: $u-tips-color !default;
  103. $u-cell-label-line-height: 18px !default;
  104. $u-cell-value-font-size: 14px !default;
  105. $u-cell-value-color: $u-content-color !default;
  106. $u-cell-clickable-color: $u-bg-color !default;
  107. $u-cell-disabled-color: #c8c9cc !default;
  108. $u-cell-padding-top-large: 13px !default;
  109. $u-cell-padding-bottom-large: 13px !default;
  110. $u-cell-value-font-size-large: 15px !default;
  111. $u-cell-label-font-size-large: 14px !default;
  112. $u-cell-title-font-size-large: 16px !default;
  113. $u-cell-left-icon-wrap-margin-right: 4px !default;
  114. $u-cell-right-icon-wrap-margin-left: 4px !default;
  115. $u-cell-title-flex:1 !default;
  116. $u-cell-label-margin-top:5px !default;
  117. .u-cell {
  118. &__body {
  119. @include flex();
  120. /* #ifndef APP-NVUE */
  121. box-sizing: border-box;
  122. /* #endif */
  123. padding: $u-cell-padding;
  124. font-size: $u-cell-font-size;
  125. color: $u-cell-color;
  126. // line-height: $u-cell-line-height;
  127. align-items: center;
  128. &__content {
  129. @include flex(row);
  130. align-items: center;
  131. flex: 1;
  132. }
  133. &--large {
  134. padding-top: $u-cell-padding-top-large;
  135. padding-bottom: $u-cell-padding-bottom-large;
  136. }
  137. }
  138. &__left-icon-wrap,
  139. &__right-icon-wrap {
  140. @include flex();
  141. align-items: center;
  142. // height: $u-cell-line-height;
  143. font-size: $u-cell-icon-size;
  144. }
  145. &__left-icon-wrap {
  146. margin-right: $u-cell-left-icon-wrap-margin-right;
  147. }
  148. &__right-icon-wrap {
  149. margin-left: $u-cell-right-icon-wrap-margin-left;
  150. transition: transform 0.3s;
  151. &--up {
  152. transform: rotate(-90deg);
  153. }
  154. &--down {
  155. transform: rotate(90deg);
  156. }
  157. }
  158. &__title {
  159. flex: $u-cell-title-flex;
  160. &-text {
  161. font-size: $u-cell-title-font-size;
  162. line-height: $u-cell-title-line-height;
  163. color: $u-cell-title-color;
  164. &--large {
  165. font-size: $u-cell-title-font-size-large;
  166. }
  167. }
  168. }
  169. &__label {
  170. margin-top: $u-cell-label-margin-top;
  171. font-size: $u-cell-label-font-size;
  172. color: $u-cell-label-color;
  173. line-height: $u-cell-label-line-height;
  174. &--large {
  175. font-size: $u-cell-label-font-size-large;
  176. }
  177. }
  178. &__value {
  179. text-align: right;
  180. font-size: $u-cell-value-font-size;
  181. line-height: $u-cell-line-height;
  182. color: $u-cell-value-color;
  183. &--large {
  184. font-size: $u-cell-value-font-size-large;
  185. }
  186. }
  187. &--clickable {
  188. background-color: $u-cell-clickable-color;
  189. }
  190. &--disabled {
  191. color: $u-cell-disabled-color;
  192. /* #ifndef APP-NVUE */
  193. cursor: not-allowed;
  194. /* #endif */
  195. }
  196. &--center {
  197. align-items: center;
  198. }
  199. }
  200. </style>