¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <view class="u-cell" :class="[customClass]" :style="[$u.addStyle(customStyle)]" |
| | | :hover-class="(!disabled && (clickable || isLink)) ? 'u-cell--clickable' : ''" :hover-stay-time="250" |
| | | @tap="clickHandler"> |
| | | <view class="u-cell__body" :class="[ center && 'u-cell--center', size === 'large' && 'u-cell__body--large']"> |
| | | <view class="u-cell__body__content"> |
| | | <view class="u-cell__left-icon-wrap" v-if="$slots.icon || icon"> |
| | | <slot name="icon" v-if="$slots.icon"> |
| | | </slot> |
| | | <u-icon v-else :name="icon" :custom-style="iconStyle" :size="size === 'large' ? 22 : 18"></u-icon> |
| | | </view> |
| | | <view class="u-cell__title"> |
| | | <slot name="title"> |
| | | <text v-if="title" class="u-cell__title-text" :style="[titleTextStyle]" |
| | | :class="[disabled && 'u-cell--disabled', size === 'large' && 'u-cell__title-text--large']">{{ title }}</text> |
| | | </slot> |
| | | <slot name="label"> |
| | | <text class="u-cell__label" v-if="label" |
| | | :class="[disabled && 'u-cell--disabled', size === 'large' && 'u-cell__label--large']">{{ label }}</text> |
| | | </slot> |
| | | </view> |
| | | </view> |
| | | <slot name="value"> |
| | | <text class="u-cell__value" |
| | | :class="[disabled && 'u-cell--disabled', size === 'large' && 'u-cell__value--large']" |
| | | v-if="!$u.test.empty(value)">{{ value }}</text> |
| | | </slot> |
| | | <view class="u-cell__right-icon-wrap" v-if="$slots['right-icon'] || isLink" |
| | | :class="[`u-cell__right-icon-wrap--${arrowDirection}`]"> |
| | | <slot name="right-icon" v-if="$slots['right-icon']"> |
| | | </slot> |
| | | <u-icon v-else :name="rightIcon" :custom-style="rightIconStyle" :color="disabled ? '#c8c9cc' : 'info'" |
| | | :size="size === 'large' ? 18 : 16"></u-icon> |
| | | </view> |
| | | </view> |
| | | <u-line v-if="border"></u-line> |
| | | </view> |
| | | </template> |
| | | |
| | | <script> |
| | | import props from './props.js'; |
| | | /** |
| | | * cell åå
æ ¼ |
| | | * @description cellåå
æ ¼ä¸è¬ç¨äºä¸ç»å表çæ
åµï¼æ¯å¦ä¸ªäººä¸å¿é¡µï¼è®¾ç½®é¡µçã |
| | | * @tutorial https://uviewui.com/components/cell.html |
| | | * @property {String | Number} title æ é¢ |
| | | * @property {String | Number} label æ é¢ä¸æ¹çæè¿°ä¿¡æ¯ |
| | | * @property {String | Number} value å³ä¾§çå
容 |
| | | * @property {String} icon 左侧徿 åç§°ï¼æè
å¾ç龿¥(æ¬å°æä»¶å»ºè®®ä½¿ç¨ç»å¯¹å°å) |
| | | * @property {Boolean} disabled æ¯å¦ç¦ç¨cell |
| | | * @property {Boolean} border æ¯å¦æ¾ç¤ºä¸è¾¹æ¡ (é»è®¤ true ) |
| | | * @property {Boolean} center å
容æ¯å¦åç´å±
ä¸(ä¸»è¦æ¯é对å³ä¾§çvalueé¨å) (é»è®¤ false ) |
| | | * @property {String} url ç¹å»å跳转çURLå°å |
| | | * @property {String} linkType 龿¥è·³è½¬çæ¹å¼ï¼å
é¨ä½¿ç¨çæ¯uViewå°è£
çrouteæ¹æ³ï¼å¯è½ä¼è¿è¡æ¦æªæä½ (é»è®¤ 'navigateTo' ) |
| | | * @property {Boolean} clickable æ¯å¦å¼å¯ç¹å»åé¦(表ç°ä¸ºç¹å»æ¶å ä¸ç°è²èæ¯) ï¼é»è®¤ false ï¼ |
| | | * @property {Boolean} isLink æ¯å¦å±ç¤ºå³ä¾§ç®å¤´å¹¶å¼å¯ç¹å»åé¦ ï¼é»è®¤ false ï¼ |
| | | * @property {Boolean} required æ¯å¦æ¾ç¤ºè¡¨åç¶æä¸çå¿
å¡«æå·(æ¤ç»ä»¶å¯è½ä¼å
åµå
¥inputç»ä»¶) ï¼é»è®¤ false ï¼ |
| | | * @property {String} rightIcon å³ä¾§ç徿 ç®å¤´ ï¼é»è®¤ 'arrow-right'ï¼ |
| | | * @property {String} arrowDirection å³ä¾§ç®å¤´çæ¹åï¼å¯éå¼ä¸ºï¼leftï¼upï¼down |
| | | * @property {Object | String} rightIconStyle å³ä¾§ç®å¤´å¾æ çæ ·å¼ |
| | | * @property {Object | String} titleStyle æ é¢çæ ·å¼ |
| | | * @property {Object | String} iconStyle 左侧徿 æ ·å¼ |
| | | * @property {String} size åä½å
ç大å°ï¼å¯éå¼ä¸º largeï¼normalï¼mini |
| | | * @property {Boolean} stop ç¹å»cellæ¯å¦é»æ¢äºä»¶ä¼ æ (é»è®¤ true ) |
| | | * @property {Object} customStyle å®ä¹éè¦ç¨å°çå¤é¨æ ·å¼ |
| | | * |
| | | * @event {Function} click ç¹å»cellå表æ¶è§¦å |
| | | * @example 该ç»ä»¶éè¦æé
cell-groupç»ä»¶ä½¿ç¨ï¼è§å®æ¹ææ¡£ç¤ºä¾ |
| | | */ |
| | | export default { |
| | | name: 'u-cell', |
| | | data() { |
| | | return { |
| | | |
| | | } |
| | | }, |
| | | mixins: [uni.$u.mpMixin, uni.$u.mixin, props], |
| | | computed: { |
| | | titleTextStyle() { |
| | | return uni.$u.addStyle(this.titleStyle) |
| | | } |
| | | }, |
| | | methods: { |
| | | // ç¹å»cell |
| | | clickHandler(e) { |
| | | if (this.disabled) return |
| | | this.$emit('click', { |
| | | name: this.name |
| | | }) |
| | | // 妿é
ç½®äºurl(æ¤propsåæ°éè¿mixinå¼å
¥)åæ°ï¼è·³è½¬é¡µé¢ |
| | | this.openPage() |
| | | // æ¯å¦é»æ¢äºä»¶ä¼ æ |
| | | this.stop && this.preventEvent(e) |
| | | }, |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <style lang="scss" scoped> |
| | | @import "../../libs/css/components.scss"; |
| | | |
| | | $u-cell-padding: 10px 15px !default; |
| | | $u-cell-font-size: 15px !default; |
| | | $u-cell-line-height: 24px !default; |
| | | $u-cell-color: $u-main-color !default; |
| | | $u-cell-icon-size: 16px !default; |
| | | $u-cell-title-font-size: 15px !default; |
| | | $u-cell-title-line-height: 22px !default; |
| | | $u-cell-title-color: $u-main-color !default; |
| | | $u-cell-label-font-size: 12px !default; |
| | | $u-cell-label-color: $u-tips-color !default; |
| | | $u-cell-label-line-height: 18px !default; |
| | | $u-cell-value-font-size: 14px !default; |
| | | $u-cell-value-color: $u-content-color !default; |
| | | $u-cell-clickable-color: $u-bg-color !default; |
| | | $u-cell-disabled-color: #c8c9cc !default; |
| | | $u-cell-padding-top-large: 13px !default; |
| | | $u-cell-padding-bottom-large: 13px !default; |
| | | $u-cell-value-font-size-large: 15px !default; |
| | | $u-cell-label-font-size-large: 14px !default; |
| | | $u-cell-title-font-size-large: 16px !default; |
| | | $u-cell-left-icon-wrap-margin-right: 4px !default; |
| | | $u-cell-right-icon-wrap-margin-left: 4px !default; |
| | | $u-cell-title-flex:1 !default; |
| | | $u-cell-label-margin-top:5px !default; |
| | | |
| | | |
| | | .u-cell { |
| | | &__body { |
| | | @include flex(); |
| | | /* #ifndef APP-NVUE */ |
| | | box-sizing: border-box; |
| | | /* #endif */ |
| | | padding: $u-cell-padding; |
| | | font-size: $u-cell-font-size; |
| | | color: $u-cell-color; |
| | | // line-height: $u-cell-line-height; |
| | | align-items: center; |
| | | |
| | | &__content { |
| | | @include flex(row); |
| | | align-items: center; |
| | | flex: 1; |
| | | } |
| | | |
| | | &--large { |
| | | padding-top: $u-cell-padding-top-large; |
| | | padding-bottom: $u-cell-padding-bottom-large; |
| | | } |
| | | } |
| | | |
| | | &__left-icon-wrap, |
| | | &__right-icon-wrap { |
| | | @include flex(); |
| | | align-items: center; |
| | | // height: $u-cell-line-height; |
| | | font-size: $u-cell-icon-size; |
| | | } |
| | | |
| | | &__left-icon-wrap { |
| | | margin-right: $u-cell-left-icon-wrap-margin-right; |
| | | } |
| | | |
| | | &__right-icon-wrap { |
| | | margin-left: $u-cell-right-icon-wrap-margin-left; |
| | | transition: transform 0.3s; |
| | | |
| | | &--up { |
| | | transform: rotate(-90deg); |
| | | } |
| | | |
| | | &--down { |
| | | transform: rotate(90deg); |
| | | } |
| | | } |
| | | |
| | | &__title { |
| | | flex: $u-cell-title-flex; |
| | | |
| | | &-text { |
| | | font-size: $u-cell-title-font-size; |
| | | line-height: $u-cell-title-line-height; |
| | | color: $u-cell-title-color; |
| | | |
| | | &--large { |
| | | font-size: $u-cell-title-font-size-large; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | &__label { |
| | | margin-top: $u-cell-label-margin-top; |
| | | font-size: $u-cell-label-font-size; |
| | | color: $u-cell-label-color; |
| | | line-height: $u-cell-label-line-height; |
| | | |
| | | &--large { |
| | | font-size: $u-cell-label-font-size-large; |
| | | } |
| | | } |
| | | |
| | | &__value { |
| | | text-align: right; |
| | | font-size: $u-cell-value-font-size; |
| | | line-height: $u-cell-line-height; |
| | | color: $u-cell-value-color; |
| | | |
| | | &--large { |
| | | font-size: $u-cell-value-font-size-large; |
| | | } |
| | | } |
| | | |
| | | &--clickable { |
| | | background-color: $u-cell-clickable-color; |
| | | } |
| | | |
| | | &--disabled { |
| | | color: $u-cell-disabled-color; |
| | | /* #ifndef APP-NVUE */ |
| | | cursor: not-allowed; |
| | | /* #endif */ |
| | | } |
| | | |
| | | &--center { |
| | | align-items: center; |
| | | } |
| | | } |
| | | </style> |