From 18823112690efdd94e4c94cf0facd92ac0d3e7f5 Mon Sep 17 00:00:00 2001 From: hsm-lv <80095014+hsm-lv@users.noreply.github.com> Date: Thu, 5 May 2022 18:02:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=8E=BB=E6=8E=89Link=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E4=BA=8B=E4=BB=B6=E6=B4=BE=E5=8F=91=EF=BC=88=E6=84=8F?= =?UTF-8?q?=E4=B9=89=E4=B8=8D=E5=A4=A7=EF=BC=89&=E8=A1=A5=E5=85=85onClick?= =?UTF-8?q?=20(#4217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix:去掉Link组件的事件派发(意义不大)&补充onClick * feat:兼容一下老版本execOn --- docs/zh-CN/components/link.md | 10 ---------- docs/zh-CN/concepts/event-action.md | 6 +++--- src/actions/Action.ts | 9 +++++---- src/renderers/Link.tsx | 22 +++++----------------- 4 files changed, 13 insertions(+), 34 deletions(-) diff --git a/docs/zh-CN/components/link.md b/docs/zh-CN/components/link.md index cbed019e3..720885f43 100755 --- a/docs/zh-CN/components/link.md +++ b/docs/zh-CN/components/link.md @@ -78,13 +78,3 @@ order: 55 | disabled | `boolean` | | 禁用超链接 | | icon | `string` | | 超链接图标,以加强显示 | | rightIcon | `string` | | 右侧图标 | - -## 事件表 - -| 事件名称 | 事件参数 | 说明 | -| -------- | -------------------------------------------------------------------------------------------------- | ---- | -| click | `url: string` 链接地址
`blank: boolean` 是否在新标签页打开
`label: SchemaTpl` 标签内文本 | 点击 | - -## 动作表 - -暂无 diff --git a/docs/zh-CN/concepts/event-action.md b/docs/zh-CN/concepts/event-action.md index f5638e9b5..96c95f2d3 100644 --- a/docs/zh-CN/concepts/event-action.md +++ b/docs/zh-CN/concepts/event-action.md @@ -3231,9 +3231,9 @@ order: 9 "actionType": "toast", args: { "msgType": 'info', - "msg": '动作1', - "preventDefault": true - } + "msg": '动作1' + }, + "preventDefault": true } ] } diff --git a/src/actions/Action.ts b/src/actions/Action.ts index f6583f470..0efd07e8a 100644 --- a/src/actions/Action.ts +++ b/src/actions/Action.ts @@ -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; } diff --git a/src/renderers/Link.tsx b/src/renderers/Link.tsx index e0abebbb7..6ae2d265f 100644 --- a/src/renderers/Link.tsx +++ b/src/renderers/Link.tsx @@ -63,8 +63,10 @@ export class LinkCmpt extends React.Component { htmlTarget: '' }; - async handleClick(href: string) { - const {env, blank, body, dispatchEvent, data} = this.props; + @autobind + handleClick(e: React.MouseEvent) { + const {env, href, blank, body} = this.props; + env?.tracker( { eventType: 'url', @@ -73,21 +75,6 @@ export class LinkCmpt extends React.Component { }, 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 { htmlTarget={htmlTarget || (blank ? '_blank' : '_self')} icon={icon} rightIcon={rightIcon} + onClick={this.handleClick} > {body ? render('body', body) : value || __('link')}