Skip to content

Commit

Permalink
feat(swipe-action): support "dataSet" (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simplyme0823 committed Apr 21, 2022
1 parent 0f9a1df commit 42b0188
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/SwipeAction/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ toc: false
## 事件
| 事件名 | 说明 | 类型 | 补充 |
| -----|-----|-----|-----|
| onLeftButtonTap | 点击左侧按钮,触发回调 | (v: number) => void | 从左往右起,第 n 个按钮 |
| onRightButtonTap | 点击右侧按钮,触发回调 | (v: number) => void | 从左往右起,第 n 个按钮 |
| onLeftButtonTap | 点击左侧按钮,触发回调 | (index: number, text: string, type: string, extraInfo?: unknown, dateSet: Record<string, any>) => void | 从左往右起,第 n 个按钮 |
| onRightButtonTap | 点击右侧按钮,触发回调 | (index: number, text: string, type: string, extraInfo?: unknown, dateSet: Record<string, any>) => void | 从左往右起,第 n 个按钮 |

## 样式类
| 类名 | 说明 |
Expand Down
13 changes: 11 additions & 2 deletions src/SwipeAction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Component({
});
}
if (onLeftButtonTap) {
return onLeftButtonTap(index, text, type, extraInfo);
return onLeftButtonTap(index, text, type, extraInfo, this.getDataSet());
}
},
onRightButtonTap(e) {
Expand All @@ -177,7 +177,7 @@ Component({
});
}
if (onRightButtonTap) {
return onRightButtonTap(index, text, type, extraInfo);
return onRightButtonTap(index, text, type, extraInfo, this.getDataSet());
}
},
getRef() {
Expand All @@ -190,6 +190,15 @@ Component({
}
};
},
getDataSet(){
return Object.entries(this.props).reduce((prev,cur)=>{
const [key, val] = cur
if(key.startsWith('data-')){
prev[key.replace('data-','')] = val
}
return prev
},{})
}
},
ref() {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/SwipeAction/props.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ export interface ISwipeActionProps extends IBaseProps {
* 属性添加方式参考demo示例
*/
onLeftButtonTap?:
(index: number, text: string, type: string, extraInfo?: unknown) => void;
(index: number, text: string, type: string, extraInfo: unknown, dateSet: Record<string, any>) => void;
/**
* @description 点击右侧按钮回调,extraInfo是一个对象,
* extraInfo包含若干属性,支持用户传入附加参数,以实现组件使用者的删除逻辑
* 属性添加方式参考demo示例
*/
onRightButtonTap?:
(index: number, text: string, type: string, extraInfo?: unknown) => void;
(index: number, text: string, type: string, extraInfo: unknown, dateSet: Record<string, any>) => void;
/**
* @description 获取组件实例与设置滑动距离
*/
Expand Down

0 comments on commit 42b0188

Please sign in to comment.