eventBus.js 944 B

12345678910111213141516171819202122232425262728293031323334
  1. import Vue from 'vue';
  2. // 创建全局唯一的 EventBus 实例
  3. export const EventBus = new Vue();
  4. // 创建唯一的事件处理函数
  5. function dataInitHandler(_this, formData, bindComponents) {
  6. bindComponents?.forEach(com => {
  7. const maps = com.maps;
  8. const filterList = maps?.map(param => ({
  9. column: param.targetField,
  10. operator: param.queryRule,
  11. value: formData[param.sourceField],
  12. }));
  13. _this.$nextTick(() => {
  14. if (_this.$refs[com.componentKey] && _this.$refs[com.componentKey].dataInit) {
  15. _this.$refs[com.componentKey].dataInit(filterList);
  16. }
  17. });
  18. });
  19. }
  20. // 注册事件监听器
  21. export function dataInit(_this) {
  22. EventBus.$on('dataInit', (formData, bindComponents) => {
  23. // 在回调中调用处理函数并传递组件实例
  24. dataInitHandler(_this, formData, bindComponents);
  25. });
  26. }
  27. export function destroyedEvent() {
  28. EventBus.$off('dataInit', dataInitHandler);
  29. }