打开弹窗/抽屉的动作如何在弹窗关闭后扩展逻辑

介绍

在业务中,我们可能会遇到在弹窗关闭后执行业务逻辑的场景,这个时候可以通过自定义弹窗动作来实现

注意: oinone已经内置了弹窗内的动作触发后刷新主视图、刷新当前视图、提交数据的能力,可以通过界面设计器在动作的属性面板配置,本文档为内置能力不满足需求的场景使用

场景案例

弹窗动作组件示例

import {
  ActionType,
  ActiveRecord,
  BaseActionWidget,
  DialogViewActionWidget,
  SPI,
  ViewActionTarget,
  DisposeEventHandler,
  IPopupInstance,
  PopupManager,
  RuntimeAction,
} from '@kunlun/dependencies';

/**
 * 弹出层销毁回调 - 建议抽到工具类中
 * @param popupKey 弹出层key
 * @param disposeEventHandler 销毁的回调
 */
function popupDisposeCallback(
  popupKey: string,
  disposeEventHandler: DisposeEventHandler,
) {
  const innerDisposeFn = (manager: PopupManager, instance: IPopupInstance, action?: RuntimeAction) => {
    if (instance.key === popupKey) {
      disposeEventHandler?.(manager, instance, action);
    }
    PopupManager.INSTANCE.clearOnClose(innerDisposeFn);
  };
  PopupManager.INSTANCE.onClose(innerDisposeFn);
}

@SPI.ClassFactory(
  BaseActionWidget.Token({
    actionType: [ActionType.View],
    target: [ViewActionTarget.Dialog],
    model: 'resource.k2.Model0000000109',
    name: 'dialogActionName001'
  })
)
export class CustomDialogViewActionWidget extends DialogViewActionWidget {
  protected createPopupWidget(data: ActiveRecord[]) {
    super.createPopupWidget(data);
    popupDisposeCallback(this.dialog.getHandle(), async (manager: PopupManager, instance: IPopupInstance, action?: RuntimeAction) => {
      // action为触发关闭弹窗的动作,点击动作关闭弹出层该参数才有值,如果是点击遮罩背景层则无该参数
      if (action?.name === 'actionName001') {
        // 以下为示例代码,指定name的动作关闭弹窗后刷新当前视图的数据查询
        this.refreshCallChaining?.syncCall();
      }
    });
  }
}

函数式调用打开弹窗的示例

以下为在自定义字段组件中手动触发打开弹窗

import {
  BaseFieldWidget, Dialog, DialogWidget, DisposeEventHandler,
  FormStringFieldSingleWidget, IPopupInstance, ModelDefaultActionName,
  ModelFieldType, PopupManager, RuntimeAction,
  RuntimeViewAction, SPI, ViewType, Widget
} from '@kunlun/dependencies';

/**
 * 弹出层销毁回调 - 建议抽到工具类中
 * @param popupKey 弹出层key
 * @param disposeEventHandler 销毁的回调
 */
function popupDisposeCallback(
  popupKey: string,
  disposeEventHandler: DisposeEventHandler,
) {
  const innerDisposeFn = (manager: PopupManager, instance: IPopupInstance, action?: RuntimeAction) => {
    if (instance.key === popupKey) {
      disposeEventHandler?.(manager, instance, action);
    }
    PopupManager.INSTANCE.clearOnClose(innerDisposeFn);
  };
  PopupManager.INSTANCE.onClose(innerDisposeFn);
}

@SPI.ClassFactory(
  BaseFieldWidget.Token({
    viewType: ViewType.Form,
    ttype: ModelFieldType.String,
    model: 'resource.k2.Model0000000109',
    name: 'code',
  })
)
export class MyFormStringDialogFieldWidget extends FormStringFieldSingleWidget {

  @Widget.Method()
  protected onCustomClick() {
    const action = this.model.modelActions.find(i => i.name === 'your action name');
    if (!action) {
      return;
    }
    const dialogKey = Dialog.createByViewAction(action as RuntimeViewAction);
    popupDisposeCallback(dialogKey, (manager: PopupManager, instance: IPopupInstance, action?: RuntimeAction) => {
      // action为关闭弹窗的动作,需要自行判断哪些动作可以进入下一步的业务处理,这里已弹窗的提交数据的动作为例
      if (action?.fun !== ModelDefaultActionName.$$internal_DialogSubmit) {
        return;
      }
      const dialogWidget = instance.widget as DialogWidget;
      const activeRecord = dialogWidget?.activeRecords?.[0];
      if (activeRecord) {
        // TODO 拿到弹窗内的数据自行处理
      }
    });
  }
}

Oinone社区 作者:nation原创文章,如若转载,请注明出处:https://doc.oinone.top/frontend/16280.html

访问Oinone官网:https://www.oinone.top获取数式Oinone低代码应用平台体验

(0)
nation的头像nation数式员工
上一篇 2024年8月21日 下午10:33
下一篇 2024年8月22日 上午11:56

相关推荐

  • 打开弹窗的action,传入默认的查询条件不生效

    场景 form视图中的action,点击后打开table的弹窗的,xml中配置的filter,但是table查询的时候没有带上查询条件: <action name=”action_name” label=”打开tabel弹窗视图” filter=”id==${activeRecord.id}” /> 解决方案 将xml中的activeRecord…

    2023年11月1日
    37500
  • 自定义字段的数据联动

    某种情况下,开发人员期望自定以的字段发生变化后,需要修改其他的字段,这篇文章从两个维度来讲解如果处理数据的联动 界面设计器配置 1: 在界面设计器页面中的的组件区域找到自定义的字段,设计元件 2: 在模型区域,搜索提交方式,如果找到了,就把该字段拖拽进来, 如果找不到,就在元件中的组件区域,拖拽一个文本字段,按照下面的配置进行配置,然后保存 图一是找到了对应…

    2023年11月9日
    74400
  • PC端默认布局模板

    默认布局 表格视图(TABLE) <view type="TABLE"> <pack widget="group"> <view type="SEARCH"> <element widget="search" slot="sea…

    2023年11月1日
    52601
  • 前端-如何修改指定页面的内组件的css样式

    为组件加自定义class,用该class作为父选择器写特定的css样式 以form为例,自定义了以下class <view/>标签的表单视图(FormView)组件 <element/>标签的form(FormWidget)组件 <element/>标签的actionBar(ActionBarWidget)组件 impor…

    2024年6月17日
    59300
  • oio-switch 开关

    API 参数 说明 类型 默认值 版本 autofocus 组件自动获取焦点 boolean false checked(v-model: checked ) 指定当前是否选中 checkedValue | unCheckedValue false checkedChildren 选中时的内容 slot checkedValue 选中时的值 boolean …

    2023年12月18日
    41000

发表回复

登录后才能评论