| 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 | | <template> |  |   <view class="tn-swipe-action-class tn-swipe-action"> |  |     <slot></slot> |  |   </view> |  | </template> |  |   |  | <script> |  |   export default { |  |     name: 'tn-swipe-action', |  |     props: { |  |       // 是否自动关闭其他swipe按钮组 |  |       autoClose: { |  |         type: Boolean, |  |         default: true |  |       } |  |     }, |  |     provide() { |  |       return { |  |         swipeAction: this |  |       } |  |     }, |  |     computed: { |  |       // 用于监听父组件参数变化 |  |       parentData() { |  |         return [this.autoClose] |  |       } |  |     }, |  |     data() { |  |       return {} |  |     }, |  |     watch: { |  |       parentData() { |  |         if (this.children.length) { |  |           this.children.map(child => { |  |             // 判断子组件(tn-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> |  | </style> | 
 |