From 2d87024a5ecae0263ccf8856cea2f9ca78a85b2a Mon Sep 17 00:00:00 2001 From: Simplyme0823 <1213966903@qq.com> Date: Wed, 20 Apr 2022 11:33:57 +0800 Subject: [PATCH] feat(swipe-action): support "dataSet" --- src/SwipeAction/index.md | 4 ++-- src/SwipeAction/index.ts | 13 +++++++++++-- src/SwipeAction/props.d.ts | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/SwipeAction/index.md b/src/SwipeAction/index.md index 2aca7a290..2c1d8781d 100644 --- a/src/SwipeAction/index.md +++ b/src/SwipeAction/index.md @@ -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) => void | 从左往右起,第 n 个按钮 | +| onRightButtonTap | 点击右侧按钮,触发回调 | (index: number, text: string, type: string, extraInfo?: unknown, dateSet: Record) => void | 从左往右起,第 n 个按钮 | ## 样式类 | 类名 | 说明 | diff --git a/src/SwipeAction/index.ts b/src/SwipeAction/index.ts index 7b140648c..23691d878 100644 --- a/src/SwipeAction/index.ts +++ b/src/SwipeAction/index.ts @@ -165,7 +165,7 @@ Component({ }); } if (onLeftButtonTap) { - return onLeftButtonTap(index, text, type, extraInfo); + return onLeftButtonTap(index, text, type, extraInfo, this.getDataSet()); } }, onRightButtonTap(e) { @@ -177,7 +177,7 @@ Component({ }); } if (onRightButtonTap) { - return onRightButtonTap(index, text, type, extraInfo); + return onRightButtonTap(index, text, type, extraInfo, this.getDataSet()); } }, getRef() { @@ -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 { diff --git a/src/SwipeAction/props.d.ts b/src/SwipeAction/props.d.ts index 83f43a6f0..0f04a698b 100644 --- a/src/SwipeAction/props.d.ts +++ b/src/SwipeAction/props.d.ts @@ -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) => 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) => void; /** * @description 获取组件实例与设置滑动距离 */