mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 10:59:42 +08:00
Merge pull request #7391 from hsm-lv/fix-event
fix:当按钮本身事件触发后,无法触发按钮的广播事件 Close #7358
This commit is contained in:
commit
cb06cb170d
@ -128,10 +128,13 @@ export const bindEvent = (renderer: any) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return (eventName?: string) => {
|
||||||
return () => {
|
// eventName用来避免过滤广播事件
|
||||||
rendererEventListeners = rendererEventListeners.filter(
|
rendererEventListeners = rendererEventListeners.filter(
|
||||||
(item: RendererEventListener) => item.renderer !== renderer
|
(item: RendererEventListener) =>
|
||||||
|
item.renderer !== renderer && eventName !== undefined
|
||||||
|
? item.type !== eventName
|
||||||
|
: true
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -147,7 +150,7 @@ export async function dispatchEvent(
|
|||||||
data: any,
|
data: any,
|
||||||
broadcast?: RendererEvent<any>
|
broadcast?: RendererEvent<any>
|
||||||
): Promise<RendererEvent<any> | void> {
|
): Promise<RendererEvent<any> | void> {
|
||||||
let unbindEvent: (() => void) | null | undefined = null;
|
let unbindEvent: ((eventName?: string) => void) | null | undefined = null;
|
||||||
const eventName = typeof e === 'string' ? e : e.type;
|
const eventName = typeof e === 'string' ? e : e.type;
|
||||||
|
|
||||||
renderer?.props?.env?.beforeDispatchEvent?.(
|
renderer?.props?.env?.beforeDispatchEvent?.(
|
||||||
@ -183,6 +186,7 @@ export async function dispatchEvent(
|
|||||||
data,
|
data,
|
||||||
scoped
|
scoped
|
||||||
});
|
});
|
||||||
|
|
||||||
// 过滤&排序
|
// 过滤&排序
|
||||||
const listeners = rendererEventListeners
|
const listeners = rendererEventListeners
|
||||||
.filter(
|
.filter(
|
||||||
@ -198,7 +202,7 @@ export async function dispatchEvent(
|
|||||||
const checkExecuted = () => {
|
const checkExecuted = () => {
|
||||||
executedCount++;
|
executedCount++;
|
||||||
if (executedCount === listeners.length) {
|
if (executedCount === listeners.length) {
|
||||||
unbindEvent?.();
|
unbindEvent?.(eventName);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
for (let listener of listeners) {
|
for (let listener of listeners) {
|
||||||
|
Loading…
Reference in New Issue
Block a user