From a733617e36456fe7606bfd9f1dc44833ce6549a0 Mon Sep 17 00:00:00 2001 From: "liu.shiyi" <liu.shiyi@ustcinfo.com> Date: Wed, 29 Nov 2023 15:59:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=81=94=E5=8A=A8=E5=AD=98=E5=9C=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data-room-ui/packages/js/utils/eventBus.js | 52 +++++++++++++--------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/data-room-ui/packages/js/utils/eventBus.js b/data-room-ui/packages/js/utils/eventBus.js index f104926e..ecbab2f4 100644 --- a/data-room-ui/packages/js/utils/eventBus.js +++ b/data-room-ui/packages/js/utils/eventBus.js @@ -1,26 +1,34 @@ -import Vue from 'vue' -export const EventBus = new Vue() +import Vue from 'vue'; -export function dataInit (_this) { +// 创建全局唯一的 EventBus 实例 +export const EventBus = new Vue(); + +// 创建唯一的事件处理函数 +function dataInitHandler(_this, formData, bindComponents) { + bindComponents?.forEach(com => { + const maps = com.maps; + const filterList = maps?.map(param => ({ + column: param.targetField, + operator: param.queryRule, + value: formData[param.sourceField], + })); + + _this.$nextTick(() => { + if (_this.$refs[com.componentKey] && _this.$refs[com.componentKey].dataInit) { + _this.$refs[com.componentKey].dataInit(filterList); + } + }); + }); +} + +// 注册事件监听器 +export function dataInit(_this) { EventBus.$on('dataInit', (formData, bindComponents) => { - // eslint-disable-next-line no-unused-expressions - bindComponents?.forEach(com => { - const maps = com.maps - const filterList = maps?.map(param => ({ - column: param.targetField, - operator: param.queryRule, - value: formData[param.sourceField] - })) - _this.$nextTick(() => { - if (_this.$refs[com.componentKey]) { - if (_this.$refs[com.componentKey].dataInit) { - _this.$refs[com.componentKey].dataInit(filterList) - } - } - }) - }) - }) + // 在回调中调用处理函数并传递组件实例 + dataInitHandler(_this, formData, bindComponents); + }); } -export function destroyedEvent () { - EventBus.$off('dataInit') + +export function destroyedEvent() { + EventBus.$off('dataInit', dataInitHandler); }