钩子介绍：

1、插入按钮的钩子，可以实现针对表单按钮的拦截复写

```javascript
registerOvDataEvent('OvButtons', (buttons, info) => {
    console.log(buttons);
    return buttons;
})
```

  
2、复写表单弹框关闭的方法

```javascript
  weappUtils.regOvProps('weappEbdfpage', 'CardDetailDlg', (props) => {
    const close = props.dialogProps?.onClose;
    props.dialogProps = {
      ...props.dialogProps,
      onClose: (...args) => {
        window.weappUi.Dialog.confirm({
          title: '关闭弹框',
          content: '提示信息',
          okText: 'ok',
          cancelText: 'cancel',
          onCancel: () => {}, // 点击取消按钮的回调
          onOk: () => {
            if (close) {
              close(...args);
            } else {
              ebdFormSdk?.closePageBySlide?.();
            }
          }, // 点击确认按钮的回调
        });
      },
    };
    return props;
  });
```

3、修改表单内容更改后，是否弹出默认的提示框

```javascript
props.needConfirmInClose = false
```

**4、配合ecode的全套开发方案**

**更新hotfix后，将下列代码放入ecode即可**

```typescript

import { regOvProps } from '@weapp/utils';

window.ebdfpage_isRouteMode = window.location.href.includes('/sp/ebdfpage/card/');

function registerCloseSingleWindow() {
  const isInIframe = window.self !== window.top;

  // 监听 beforeunload 事件
  window.addEventListener('beforeunload', function (event) {
    // 弹出确认提示
    event.preventDefault();
    event.returnValue = '确定要离开吗？'; // 兼容旧版浏览器
    return '确定要离开吗？'; // 兼容新版浏览器
  });

  // 监听页面卸载事件
  window.addEventListener('unload', function () {
    if (isInIframe) {
      try {
        window.top.close(); // 尝试关闭父窗口
      } catch (error) {
        console.error('无法关闭窗口:', error);
      }
    }
  });
}

const setButtons = (props) => {
  // 按钮注册钩子
  props.cardStore.SdkStore.registerOvDataEvent('OvButtons', (btns) => {
    const code = `
  function closeDlalogByDOM() {
    var dlgHeaders = document.querySelectorAll('.ui-dialog-portal .ui-dialog-layout-header');
    if (dlgHeaders.length > 0) {
      dlgHeaders[dlgHeaders.length - 1].querySelector('.ui-dialog-closeIcon')?.click?.();
    } else {
       if (window.ebdfpage_isRouteMode) {
        window.top.close();
      }
      if (window.ebdFormSdk) {
        window.ebdFormSdk.closePageBySlide();
      } else {
        window.weappUtils?.eventEmitter?.emit('@weapp/ebdpage', 'dialog.close');
      }
    }
  }
  closeDlalogByDOM(); //执行
`;

    const newBtn = {
      id: 'backClose',
      buttonKey: '',
      name: '退出',
      showPosition: ['rightTop'],
      hidden: false,
      onlyIcon: 0,
      iconPath: '',
      conditionEnable: 0,
      conditionId: '0',
      likeNum: 0,
      likeInfo: 0,
      showOrder: 0,
      conditionData: '',
      operatColumnFixation: 0,
      sysParams: '[]',
      buttonCustomParm: {
        enableLog: 1,
      },
      listDataFilterType: 'LIST',
      operateType: '1',
      actions: [
        {
          id: 'backClose',
          deleteType: 0,
          name: '',
          datarule: '',
          conditionTxt: '',
          url: '',
          urlType: '0',
          actionType: 'jsCode',
          params: '',
          enable: 1,
          showOrder: 0,
          openType: '1',
          windowSize: 30,
          interfacePath: '',
          confirmTitle: '',
          confirmContent: '',
          confirmTrue: '',
          confirmFalse: '',
          desc: '',
          ecode: code,
          showReplyNum: 0,
          enableLog: 1,
          parseType: 1,
          idStr: 'backClose',
          buttonId: 'backClose',
          interfaceType: '',
          executeSelectedDatas: 0,
          fieldAssignType: '[]',
          dataSource: '2',
        },
      ],
    };
    console.log(btns);
    return [newBtn, ...btns];
  });
};

regOvProps('weappEbdfpage', 'CardDetailDlg', (props) => {
  setButtons(props);
  if (window.ebdfpage_isRouteMode) {
    registerCloseSingleWindow(); // 1、单页关闭前提醒
  }
  const close = props.dialogProps?.onClose;
  props.dialogProps = {
    ...props.dialogProps,
    onClose: () => {
      // 2、点击×或按钮关闭前提醒
      window.weappUi.Dialog.confirm({
        title: '关闭弹框',
        content: '提示信息',
        okText: 'ok',
        cancelText: 'cancel',
        onCancel: () => {},
        onOk: () => {
          if (window.ebdfpage_isRouteMode && window.ebdfpage_closeSingleWindow) {
            // 调用方法
            window.ebdfpage_closeSingleWindow?.();
          } else {
            if (close) {
              close();
            } else {
              ebdFormSdk.closePageBySlide();
            }
          }
        },
      });
    },
  };
  // 隐藏内部弹框的钩子
  props.needConfirmInClose = false; //设置为false后，修改数据后，表单默认的提示弹框会被隐藏
  return props;
});
```
