wujingjing
2024-08-09 fc3906e080b2204648ee83ee9a1db1584f818f4e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export const swipeCellBehavior = Behavior({
  data: {
    swipeCellQueue: [] // 用来存储滑动单元格实例
  },
 
  methods: {
    // 当用户打开滑块时触发
    swipeCellOpen(event) {
      // 获取单元格实例
      const instance = this.selectComponent(`#${event.target.id}`)
      // 将实例追加到数组中
      this.data.swipeCellQueue.push(instance)
    },
 
    // 给页面绑定点击事件
    onSwipeCellPage() {
      this.onSwipeCellCommonClick()
    },
 
    // 点击滑动单元格时触发的事件
    onSwipeCellClick() {
      this.onSwipeCellCommonClick()
    },
 
    // 关掉滑块统一的逻辑
    onSwipeCellCommonClick() {
      // 需要对单元格实例数组进行遍历,遍历以后获取每一个实例,让每一个实例调用 close 方法即可
      this.data.swipeCellQueue.forEach((instance) => {
        instance.close()
      })
 
      // 将滑动单元格数组重置为空
      this.data.swipeCellQueue = []
    }
  }
})