breaking change(SwipeCell): adjust before-close usage
This commit is contained in:
@@ -78,15 +78,15 @@ export default {
|
||||
case 'left':
|
||||
case 'cell':
|
||||
case 'outside':
|
||||
instance.close();
|
||||
break;
|
||||
return true;
|
||||
case 'right':
|
||||
Dialog.confirm({
|
||||
message: 'Are you sure to delete?',
|
||||
}).then(() => {
|
||||
instance.close();
|
||||
return new Promise((resolve) => {
|
||||
this.$dialog
|
||||
.confirm({
|
||||
message: 'Are you sure to delete?',
|
||||
})
|
||||
.then(resolve);
|
||||
});
|
||||
break;
|
||||
}
|
||||
},
|
||||
},
|
||||
@@ -102,7 +102,7 @@ export default {
|
||||
| name | Identifier of SwipeCell | _number \| string_ | - |
|
||||
| left-width | Width of the left swipe area | _number \| string_ | `auto` |
|
||||
| right-width | Width of the right swipe area | _number \| string_ | `auto` |
|
||||
| before-close `v2.3.0` | Callback function before close | _Function_ | - |
|
||||
| before-close `v2.3.0` | Callback function before close | _(args) => boolean \| Promise_ | - |
|
||||
| disabled | Whether to disabled swipe | _boolean_ | `false` |
|
||||
| stop-propagation | Whether to stop touchmove event propagation | _boolean_ | `false` |
|
||||
|
||||
|
||||
@@ -80,21 +80,20 @@ app.use(SwipeCell);
|
||||
export default {
|
||||
methods: {
|
||||
// position 为关闭时点击的位置
|
||||
// instance 为对应的 SwipeCell 实例
|
||||
beforeClose({ position, instance }) {
|
||||
beforeClose({ position }) {
|
||||
switch (position) {
|
||||
case 'left':
|
||||
case 'cell':
|
||||
case 'outside':
|
||||
instance.close();
|
||||
break;
|
||||
return true;
|
||||
case 'right':
|
||||
Dialog.confirm({
|
||||
message: '确定删除吗?',
|
||||
}).then(() => {
|
||||
instance.close();
|
||||
return new Promise((resolve) => {
|
||||
this.$dialog
|
||||
.confirm({
|
||||
message: '确定删除吗?',
|
||||
})
|
||||
.then(resolve);
|
||||
});
|
||||
break;
|
||||
}
|
||||
},
|
||||
},
|
||||
@@ -110,7 +109,7 @@ export default {
|
||||
| name | 标识符,可以在事件参数中获取到 | _number \| string_ | - |
|
||||
| left-width | 指定左侧滑动区域宽度,单位为`px` | _number \| string_ | `auto` |
|
||||
| right-width | 指定右侧滑动区域宽度,单位为`px` | _number \| string_ | `auto` |
|
||||
| before-close `v2.3.0` | 关闭前的回调函数 | _Function_ | - |
|
||||
| before-close | 关闭前的回调函数,返回 `false` 可阻止关闭,支持返回 Promise | _(args) => boolean \| Promise_ | - |
|
||||
| disabled | 是否禁用滑动 | _boolean_ | `false` |
|
||||
| stop-propagation | 是否阻止滑动事件冒泡 | _boolean_ | `false` |
|
||||
|
||||
@@ -134,11 +133,10 @@ export default {
|
||||
|
||||
beforeClose 的第一个参数为对象,对象中包含以下属性:
|
||||
|
||||
| 参数名 | 说明 | 类型 |
|
||||
| -------- | -------------------------------------------------- | ----------- |
|
||||
| name | 标识符 | _string_ |
|
||||
| position | 关闭时的点击位置 (`left` `right` `cell` `outside`) | _string_ |
|
||||
| instance | SwipeCell 实例,用于调用实例方法 | _SwipeCell_ |
|
||||
| 参数名 | 说明 | 类型 |
|
||||
| -------- | -------------------------------------------------- | -------- |
|
||||
| name | 标识符 | _string_ |
|
||||
| position | 关闭时的点击位置 (`left` `right` `cell` `outside`) | _string_ |
|
||||
|
||||
### 方法
|
||||
|
||||
|
||||
@@ -81,22 +81,20 @@ export default {
|
||||
},
|
||||
|
||||
methods: {
|
||||
beforeClose({ position, instance }) {
|
||||
beforeClose({ position }) {
|
||||
switch (position) {
|
||||
case 'left':
|
||||
case 'cell':
|
||||
case 'outside':
|
||||
instance.close();
|
||||
break;
|
||||
return true;
|
||||
case 'right':
|
||||
this.$dialog
|
||||
.confirm({
|
||||
message: this.t('confirm'),
|
||||
})
|
||||
.then(() => {
|
||||
instance.close();
|
||||
});
|
||||
break;
|
||||
return new Promise((resolve) => {
|
||||
this.$dialog
|
||||
.confirm({
|
||||
message: this.t('confirm'),
|
||||
})
|
||||
.then(resolve);
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
+13
-9
@@ -2,6 +2,7 @@
|
||||
import { createNamespace } from '../utils';
|
||||
import { range } from '../utils/format/number';
|
||||
import { preventDefault } from '../utils/dom/event';
|
||||
import { callInterceptor } from '../utils/interceptor';
|
||||
|
||||
// Mixins
|
||||
import { TouchMixin } from '../mixins/touch';
|
||||
@@ -167,15 +168,18 @@ export default createComponent({
|
||||
this.$emit('click', position);
|
||||
|
||||
if (this.opened && !this.lockClick) {
|
||||
if (this.beforeClose) {
|
||||
this.beforeClose({
|
||||
position,
|
||||
name: this.name,
|
||||
instance: this,
|
||||
});
|
||||
} else {
|
||||
this.close(position);
|
||||
}
|
||||
callInterceptor({
|
||||
interceptor: this.beforeClose,
|
||||
args: [
|
||||
{
|
||||
position,
|
||||
name: this.name,
|
||||
},
|
||||
],
|
||||
done: () => {
|
||||
this.close(position);
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user