Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(swipe-action): support "dataSet" #64

Merged
merged 1 commit into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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