珠宝小程序前端代码
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.

208 lines
7.4 KiB

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