fix:去掉Link组件的事件派发(意义不大)&补充onClick (#4217)

* fix:去掉Link组件的事件派发(意义不大)&补充onClick

* feat:兼容一下老版本execOn
This commit is contained in:
hsm-lv 2022-05-05 18:02:05 +08:00 committed by GitHub
parent 5bffc59db6
commit 1882311269
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 34 deletions

View File

@ -78,13 +78,3 @@ order: 55
| disabled | `boolean` | | 禁用超链接 |
| icon | `string` | | 超链接图标,以加强显示 |
| rightIcon | `string` | | 右侧图标 |
## 事件表
| 事件名称 | 事件参数 | 说明 |
| -------- | -------------------------------------------------------------------------------------------------- | ---- |
| click | `url: string` 链接地址 <br> `blank: boolean` 是否在新标签页打开 <br> `label: SchemaTpl` 标签内文本 | 点击 |
## 动作表
暂无

View File

@ -3231,10 +3231,10 @@ order: 9
"actionType": "toast",
args: {
"msgType": 'info',
"msg": '动作1',
"msg": '动作1'
},
"preventDefault": true
}
}
]
}
}

View File

@ -26,6 +26,7 @@ export interface ListenerAction {
preventDefault?: boolean; // 阻止原有组件的动作行为
stopPropagation?: boolean; // 阻止后续的事件处理器执行
expression?: string; // 执行条件
execOn?: string; // 执行条件1.9.0废弃
}
export interface ILogicAction extends ListenerAction {
@ -119,10 +120,10 @@ export const runAction = async (
event
});
if (
actionConfig.expression &&
!evalExpression(actionConfig.expression, mergeData)
) {
// 兼容一下1.9.0之前的版本
const expression = actionConfig.expression ?? actionConfig.execOn;
if (expression && !evalExpression(expression, mergeData)) {
return;
}

View File

@ -63,8 +63,10 @@ export class LinkCmpt extends React.Component<LinkProps, object> {
htmlTarget: ''
};
async handleClick(href: string) {
const {env, blank, body, dispatchEvent, data} = this.props;
@autobind
handleClick(e: React.MouseEvent<any>) {
const {env, href, blank, body} = this.props;
env?.tracker(
{
eventType: 'url',
@ -73,21 +75,6 @@ export class LinkCmpt extends React.Component<LinkProps, object> {
},
this.props
);
// 触发渲染器事件
const rendererEvent = await dispatchEvent(
'click',
createObject(data, {
// 注意:每个组件都必须把数据链带上
url: href,
blank,
label: body
})
);
// 阻止原有动作执行
if (rendererEvent?.prevented) {
return;
}
}
getHref() {}
@ -123,6 +110,7 @@ export class LinkCmpt extends React.Component<LinkProps, object> {
htmlTarget={htmlTarget || (blank ? '_blank' : '_self')}
icon={icon}
rightIcon={rightIcon}
onClick={this.handleClick}
>
{body ? render('body', body) : value || __('link')}
</Link>