¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <view class="u-swipe-action-item" ref="u-swipe-action-item"> |
| | | <view class="u-swipe-action-item__right"> |
| | | <slot name="button"> |
| | | <view v-for="(item,index) in options" :key="index" class="u-swipe-action-item__right__button" |
| | | :ref="`u-swipe-action-item__right__button-${index}`" :style="[{ |
| | | alignItems: item.style && item.style.borderRadius ? 'center' : 'stretch' |
| | | }]" @tap="buttonClickHandler(item, index)"> |
| | | <view class="u-swipe-action-item__right__button__wrapper" :style="[{ |
| | | backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD', |
| | | borderRadius: item.style && item.style.borderRadius ? item.style.borderRadius : '0', |
| | | padding: item.style && item.style.borderRadius ? '0' : '0 15px', |
| | | }, item.style]"> |
| | | <u-icon v-if="item.icon" :name="item.icon" |
| | | :color="item.style && item.style.color ? item.style.color : '#ffffff'" |
| | | :size="item.iconSize ? $u.addUnit(item.iconSize) : item.style && item.style.fontSize ? $u.getPx(item.style.fontSize) * 1.2 : 17" |
| | | :customStyle="{ |
| | | marginRight: item.text ? '2px' : 0 |
| | | }"></u-icon> |
| | | <text v-if="item.text" class="u-swipe-action-item__right__button__wrapper__text u-line-1" |
| | | :style="[{ |
| | | color: item.style && item.style.color ? item.style.color : '#ffffff', |
| | | fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px', |
| | | lineHeight: item.style && item.style.fontSize ? item.style.fontSize : '16px', |
| | | }]">{{ item.text }}</text> |
| | | </view> |
| | | </view> |
| | | </slot> |
| | | </view> |
| | | <!-- #ifdef APP-VUE || MP-WEIXIN || H5 || MP-QQ --> |
| | | <view class="u-swipe-action-item__content" @touchstart="wxs.touchstart" @touchmove="wxs.touchmove" |
| | | @touchend="wxs.touchend" :status="status" :change:status="wxs.statusChange" :size="size" |
| | | :change:size="wxs.sizeChange"> |
| | | <!-- #endif --> |
| | | <!-- #ifdef APP-NVUE --> |
| | | <view class="u-swipe-action-item__content" ref="u-swipe-action-item__content" @panstart="onTouchstart" |
| | | @tap="clickHandler"> |
| | | <!-- #endif --> |
| | | <slot /> |
| | | </view> |
| | | </view> |
| | | </template> |
| | | <!-- #ifdef APP-VUE || MP-WEIXIN || H5 || MP-QQ --> |
| | | <script src="./index.wxs" module="wxs" lang="wxs"></script> |
| | | <!-- #endif --> |
| | | <script> |
| | | import touch from '../../libs/mixin/touch.js' |
| | | import props from './props.js'; |
| | | // #ifdef APP-NVUE |
| | | import nvue from './nvue.js'; |
| | | // #endif |
| | | // #ifdef APP-VUE || MP-WEIXIN || H5 || MP-QQ |
| | | import wxs from './wxs.js'; |
| | | // #endif |
| | | /** |
| | | * SwipeActionItem æ»å¨åå
æ ¼åç»ä»¶ |
| | | * @description 该ç»ä»¶ä¸è¬ç¨äºå·¦æ»å¤åºæä½èåçåºæ¯ï¼ç¨çæå¤çæ¯å·¦æ»å é¤æä½ |
| | | * @tutorial https://www.uviewui.com/components/swipeAction.html |
| | | * @property {Boolean} show æ§å¶æå¼æè
å
³éï¼é»è®¤ false ï¼ |
| | | * @property {String | Number} index æ è¯ç¬¦ï¼å¦ææ¯v-forï¼å¯ç¨indexç´¢å¼ |
| | | * @property {Boolean} disabled æ¯å¦ç¦ç¨ï¼é»è®¤ false ï¼ |
| | | * @property {Boolean} autoClose æ¯å¦èªå¨å
³éå
¶ä»swipeæé®ç»ï¼é»è®¤ true ï¼ |
| | | * @property {Number} threshold æ»å¨è·ç¦»éå¼ï¼åªæå¤§äºæ¤å¼ï¼æè¢«è®¤ä¸ºæ¯è¦æå¼èåï¼é»è®¤ 30 ï¼ |
| | | * @property {Array} options å³ä¾§æé®å
容 |
| | | * @property {String | Number} duration å¨ç»è¿æ¸¡æ¶é´ï¼åä½msï¼é»è®¤ 350 ï¼ |
| | | * @event {Function(index)} open ç»ä»¶æå¼æ¶è§¦å |
| | | * @event {Function(index)} close ç»ä»¶å
³éæ¶è§¦å |
| | | * @example <u-swipe-action><u-swipe-action-item :options="options1" ></u-swipe-action-item></u-swipe-action> |
| | | */ |
| | | export default { |
| | | name: 'u-swipe-action-item', |
| | | mixins: [uni.$u.mpMixin, uni.$u.mixin, props, touch], |
| | | // #ifdef APP-NVUE |
| | | mixins: [uni.$u.mpMixin, uni.$u.mixin, props, nvue, touch], |
| | | // #endif |
| | | // #ifdef APP-VUE || MP-WEIXIN || H5 || MP-QQ |
| | | mixins: [uni.$u.mpMixin, uni.$u.mixin, props, touch, wxs], |
| | | // #endif |
| | | data() { |
| | | return { |
| | | // æé®çå°ºå¯¸ä¿¡æ¯ |
| | | size: {}, |
| | | // ç¶ç»ä»¶u-swipe-actionçåæ° |
| | | parentData: { |
| | | autoClose: true, |
| | | }, |
| | | // å½åç¶æï¼open-æå¼ï¼close-å
³é |
| | | status: 'close', |
| | | } |
| | | }, |
| | | watch: { |
| | | // ç±äºwxsæ æ³ç´æ¥è¯»åå¤é¨çå¼ï¼éè¦å¨å¤é¨å¼ååæ¶ï¼éæ°æ§è¡èµå¼é»è¾ |
| | | wxsInit(newValue, oldValue) { |
| | | this.queryRect() |
| | | } |
| | | }, |
| | | computed: { |
| | | wxsInit() { |
| | | return [this.disabled, this.autoClose, this.threshold, this.options, this.duration] |
| | | } |
| | | }, |
| | | mounted() { |
| | | this.init() |
| | | }, |
| | | methods: { |
| | | init() { |
| | | // åå§åç¶ç»ä»¶æ°æ® |
| | | this.updateParentData() |
| | | // #ifndef APP-NVUE |
| | | uni.$u.sleep().then(() => { |
| | | this.queryRect() |
| | | }) |
| | | // #endif |
| | | }, |
| | | updateParentData() { |
| | | // æ¤æ¹æ³å¨mixinä¸ |
| | | this.getParentData('u-swipe-action') |
| | | }, |
| | | // #ifndef APP-NVUE |
| | | // æ¥è¯¢èç¹ |
| | | queryRect() { |
| | | this.$uGetRect('.u-swipe-action-item__right__button', true).then(buttons => { |
| | | this.size = { |
| | | buttons, |
| | | show: this.show, |
| | | disabled: this.disabled, |
| | | threshold: this.threshold, |
| | | duration: this.duration |
| | | } |
| | | }) |
| | | }, |
| | | // #endif |
| | | // æé®è¢«ç¹å» |
| | | buttonClickHandler(item, index) { |
| | | this.$emit('click', { |
| | | index, |
| | | name: this.name |
| | | }) |
| | | } |
| | | }, |
| | | } |
| | | </script> |
| | | |
| | | <style lang="scss" scoped> |
| | | @import "../../libs/css/components.scss"; |
| | | |
| | | .u-swipe-action-item { |
| | | position: relative; |
| | | overflow: hidden; |
| | | /* #ifndef APP-NVUE || MP-WEIXIN */ |
| | | touch-action: pan-y; |
| | | /* #endif */ |
| | | |
| | | &__content { |
| | | background-color: #FFFFFF; |
| | | z-index: 10; |
| | | } |
| | | |
| | | &__right { |
| | | position: absolute; |
| | | top: 0; |
| | | bottom: 0; |
| | | right: 0; |
| | | @include flex; |
| | | |
| | | &__button { |
| | | @include flex; |
| | | justify-content: center; |
| | | overflow: hidden; |
| | | align-items: center; |
| | | |
| | | &__wrapper { |
| | | @include flex; |
| | | align-items: center; |
| | | justify-content: center; |
| | | padding: 0 15px; |
| | | |
| | | &__text { |
| | | @include flex; |
| | | align-items: center; |
| | | color: #FFFFFF; |
| | | font-size: 15px; |
| | | text-align: center; |
| | | justify-content: center; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | </style> |