From ac00d78a46327450b3b0cc87475457deeb7ad673 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 19 Dec 2019 21:02:46 +0800 Subject: [PATCH] feat(SwipeCell): add before-close prop (#5320) --- src/swipe-cell/README.md | 16 ++++----- src/swipe-cell/README.zh-CN.md | 25 ++++++++------ src/swipe-cell/demo/index.vue | 6 ++-- src/swipe-cell/index.js | 11 +++++- src/swipe-cell/test/index.spec.js | 56 +++++++++++++++++++++++++------ 5 files changed, 81 insertions(+), 33 deletions(-) diff --git a/src/swipe-cell/README.md b/src/swipe-cell/README.md index 0cd32f4de..cc6222793 100644 --- a/src/swipe-cell/README.md +++ b/src/swipe-cell/README.md @@ -31,7 +31,7 @@ Vue.use(SwipeCell); ### Async close ```html - + @@ -47,8 +47,8 @@ Vue.use(SwipeCell); ```js export default { methods: { - onClose(clickPosition, instance) { - switch (clickPosition) { + beforeClose({ position, instance }) { + switch (position) { case 'left': case 'cell': case 'outside': @@ -74,7 +74,7 @@ export default { | Attribute | Description | Type | Default | Version | |------|------|------|------|------| | name | Identifier of SwipeCell | *string \| number* | - | 2.0.4 | -| on-close | Callback function before close | *Function* | - | - | +| before-close | Callback function before close | *Function* | - | 2.3.0 | | disabled | Whether to disabled swipe | *boolean* | `false` | - | | left-width | Width of the left swipe area | *number* | `auto` | - | | right-width | Width of the right swipe area | *number* | `auto` | - | @@ -95,13 +95,13 @@ export default { | click | Triggered when clicked | Click positon (`left` `right` `cell` `outside`) | | open | Triggered when opened | { position: 'left' \| 'right' , name: string } | -### onClose Params +### beforeClose Params | Attribute | Description | Type | |------|------|------| -| clickPosition | Click positon (`left` `right` `cell` `outside`) | *string* | -| instance | SwipeCell instance | *object* | -| detail | Detail info | *object* | +| name | Name | *string* | +| position | Click positon (`left` `right` `cell` `outside`) | *string* | +| instance | SwipeCell instance | *SwipeCell* | ### Methods diff --git a/src/swipe-cell/README.zh-CN.md b/src/swipe-cell/README.zh-CN.md index d1ea4df8e..9a40c25cf 100644 --- a/src/swipe-cell/README.zh-CN.md +++ b/src/swipe-cell/README.zh-CN.md @@ -32,10 +32,10 @@ Vue.use(SwipeCell); ### 异步关闭 -通过传入`on-close`回调函数,可以自定义两侧滑动内容关闭时的行为 +通过传入`before-close`回调函数,可以自定义两侧滑动内容关闭时的行为 ```html - + @@ -51,9 +51,10 @@ Vue.use(SwipeCell); ```js export default { methods: { - // clickPosition 表示关闭时点击的位置 - onClose(clickPosition, instance) { - switch (clickPosition) { + // position 为关闭时点击的位置 + // instance 为对应的 SwipeCell 实例 + beforeClose({ position, instance }) { + switch (position) { case 'left': case 'cell': case 'outside': @@ -78,8 +79,8 @@ export default { | 参数 | 说明 | 类型 | 默认值 | 版本 | |------|------|------|------|------| -| name | 标识符,可以在 onClose 的参数中获取到 | *string \| number* | - | 2.0.4 | -| on-close | 关闭时的回调函数 | *Function* | - | - | +| name | 标识符,可以在事件参数中获取到 | *string \| number* | - | 2.0.4 | +| before-close | 关闭前的回调函数 | *Function* | - | 2.3.0 | | disabled | 是否禁用滑动 | *boolean* | `false` | - | | left-width | 指定左侧滑动区域宽度 | *number* | `auto` | - | | right-width | 指定右侧滑动区域宽度 | *number* | `auto` | - | @@ -100,13 +101,15 @@ export default { | click | 点击时触发 | 关闭时的点击位置 (`left` `right` `cell` `outside`) | | open | 打开时触发 | { position: 'left' \| 'right' , name: string } | -### onClose 参数 +### beforeClose 参数 + +beforeClose 的第一个参数为对象,对象中包含以下属性: | 参数名 | 说明 | 类型 | |------|------|------| -| clickPosition | 关闭时的点击位置 (`left` `right` `cell` `outside`) | *string* | -| instance | SwipeCell 实例,用于调用实例方法 | *object* | -| detail | 额外信息,包含 name 字段 | *object* | +| name | 标识符 | *string* | +| position | 关闭时的点击位置 (`left` `right` `cell` `outside`) | *string* | +| instance | SwipeCell 实例,用于调用实例方法 | *SwipeCell* | ### 方法 diff --git a/src/swipe-cell/demo/index.vue b/src/swipe-cell/demo/index.vue index 673fa787e..374c8b679 100644 --- a/src/swipe-cell/demo/index.vue +++ b/src/swipe-cell/demo/index.vue @@ -31,7 +31,7 @@ - +