微信小程序> 小程序侧滑删除组件使用movablearea

小程序侧滑删除组件使用movablearea

浏览量:759 时间: 来源:三月柳絮四月雨

 组件页面代码:

movable-area  movable-view class='conversation' catchtap='toChat' direction='horizontal'    x='{{x}}' damping="100" data-index='{{index}}' data-userid='{{userid}}'    bind:touchstart='touchstart' bind:touchend='touchend' catch:change='onChange'    slot/slot    view class='delete' catchtap='delConversation' data-index='{{index}}'删除/view  /movable-view/movable-area

 组件JS代码: 

// pages/sliderLeft/sliderLeft.jsComponent({  /**   * 组件的属性列表   */  properties: {    userid: {      type: Number,      value: '1'    },    index: {      type: Number,      value: '0'    },    isOpen: {      type: Boolean,      value: false,      observer: function (isOpen) {        this.setData({          x: isOpen ? -100 : 0        })      }    }      },  /**   * 组件的初始数据   */  data: {    x: 0,  },  /**   * 组件的方法列表   */  methods: {    onChange: function (e) {      if (e.detail.source === 'touch') {        this.setData({ x: e.detail.x })      }    },    touchstart: function (e) {      if(!this.data.isOpen){        this.triggerEvent('conversationTouchstart', { index: e.currentTarget.dataset.index }, {})      }    },    touchend: function (e) {      var x = this.data.x;      //删除按钮已显示,则一滑动就关闭      if (this.data.isOpen && x  -96) {        this.setData({           x: 0,          isOpen: false        })      }else if(x  -40) {        //达到阈值则显示否则关闭        this.setData({          isOpen: true        })      } else {        this.setData({          x: 0,          isOpen: false        })      }    },    /**     * 删除会话     */    delConversation: function (e) {      this.triggerEvent('delConversation', {index: e.currentTarget.dataset.index}, {})    },    /**     * 跳转到聊天界面     */    toChat: function (e) {      wx.navigateTo({        url: '../chat/index?userId=' + e.currentTarget.dataset.userid,      })    },  }})

 组件CSS代码: 

movable-area{  width: 1150rpx;  height: 180rpx;  display: flex;  margin-left: -200rpx;  justify-content: flex-end;}.conversation{  width: 950rpx;  height: 180rpx;  position: static;   display: flex;}.delete{  width: 200rpx;  height: 180rpx;  background: red;  color: white;  font-size: 45rpx;  line-height: 180rpx;  text-align: center;}

使用页面代码: 

block wx:for='{{conversations}}' wx:for-item='item' wx:for-index='index' wx:key='{{item.userId}}'  swider-left is-open='{{item.isOpen}}'  userid='{{item.userId}}' index='{{index}}'     binddelConversation='delConversation' bindconversationTouchstart='touchstart'    view class='userInfo'        image class='avatar' src='{{item.avatar}}'/image        view class='info'          view class='name'{{item.name}}            view class='remind' wx:if='{{item.unread_msg_count  0}}'/view          /view          view{{item.mtime}}/view        /view      /view    /swider-left/block

使用页面JS代码:

 /**   * 隐藏所有删除按钮   */  touchstart: function(e){    var conversations = this.data.conversations;    conversations[e.detail.index].isOpen = false;    this.setData({      conversations: conversations    })  },  /**   * 删除列表项   */  delConversation: function (e) {    //选项索引    var index = e.detail.index;  },

 

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

最新资讯

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎