¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <view class="u-swipe-action"> |
| | | <slot></slot> |
| | | </view> |
| | | </template> |
| | | |
| | | <script> |
| | | import props from './props.js'; |
| | | /** |
| | | * SwipeAction æ»å¨åå
æ ¼ |
| | | * @description 该ç»ä»¶ä¸è¬ç¨äºå·¦æ»å¤åºæä½èåçåºæ¯ï¼ç¨çæå¤çæ¯å·¦æ»å é¤æä½ |
| | | * @tutorial https://www.uviewui.com/components/swipeAction.html |
| | | * @property {Boolean} autoClose æ¯å¦èªå¨å
³éå
¶ä»swipeæé®ç» |
| | | * @event {Function(index)} click ç¹å»ç»ä»¶æ¶è§¦å |
| | | * @example <u-swipe-action><u-swipe-action-item :rightOptions="options1" ></u-swipe-action-item></u-swipe-action> |
| | | */ |
| | | export default { |
| | | name: 'u-swipe-action', |
| | | mixins: [uni.$u.mpMixin, uni.$u.mixin, props], |
| | | data() { |
| | | return {} |
| | | }, |
| | | provide() { |
| | | return { |
| | | swipeAction: this |
| | | } |
| | | }, |
| | | computed: { |
| | | // è¿écomputedçåéï¼é½æ¯åç»ä»¶u-swipe-action-iteméè¦ç¨å°çï¼ç±äºå¤´æ¡å°ç¨åºçå
¼å®¹æ§å·®å¼ï¼åç»ä»¶æ æ³å®æ¶çå¬ç¶ç»ä»¶åæ°çåå |
| | | // æä»¥éè¦æå¨éç¥åç»ä»¶ï¼è¿éè¿åä¸ä¸ªparentDataåéï¼ä¾watchçå¬ï¼å¨å
¶ä¸å»éç¥æ¯ä¸ä¸ªåç»ä»¶éæ°ä»ç¶ç»ä»¶(u-swipe-action-item) |
| | | // æåç¶ç»ä»¶æ°çåååçåæ° |
| | | parentData() { |
| | | return [this.autoClose] |
| | | } |
| | | }, |
| | | watch: { |
| | | // å½ç¶ç»ä»¶éè¦åç»ä»¶éè¦å
±äº«çåæ°åçäºååï¼æå¨éç¥åç»ä»¶ |
| | | parentData() { |
| | | if (this.children.length) { |
| | | this.children.map(child => { |
| | | // 夿åç»ä»¶(u-swipe-action-item)妿æupdateParentDataæ¹æ³çè¯ï¼å°±å°±æ§è¡(æ§è¡çç»ææ¯åç»ä»¶éæ°ä»ç¶ç»ä»¶æåäºææ°çå¼) |
| | | typeof(child.updateParentData) === 'function' && child.updateParentData() |
| | | }) |
| | | } |
| | | }, |
| | | }, |
| | | created() { |
| | | this.children = [] |
| | | }, |
| | | methods: { |
| | | closeOther(child) { |
| | | if (this.autoClose) { |
| | | // åéææçåå
æ ¼ï¼æ¾åºéå½åæä½ä¸çåå
æ ¼ï¼è¿è¡å
³é |
| | | this.children.map((item, index) => { |
| | | if (child !== item) { |
| | | item.closeHandler() |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <style lang="scss" scoped> |
| | | |
| | | </style> |