lowcode-engine icon indicating copy to clipboard operation
lowcode-engine copied to clipboard

feature: 希望plugin-code-editor 能暴露保存的回调

Open 501981732 opened this issue 2 years ago • 1 comments

目前源码面板的保存可以直接报错schema,但是还需要单独在点击保存按钮,保存到自己的db中。

Expected behavior (required) / 预期行为(必填,非常重要)

A clear and concise description of what did you expect to happen. / 请清晰和精确的描述你预期的行为

期望能暴露保存的回调,开发者可以在自己程序里自由渲染保存后的操作。 是否可以插件暴露onSave方法,或者 onsave时emit一个事件出来。

Screenshots (optional) / bug 截图(可选)

Sceenshots for further information. (If applicable.) / 一些有用的截图将会帮助我们更好的明确以及定位问题 image

501981732 avatar Feb 03 '23 01:02 501981732

你的场景建议直接在页面级别保存上做操作。如果在代码侧保存就直接入库,很容易出现数据问题,因为这个代码还没有联调。

可能解决你的诉求最重要的功能是:点击页面级别的保存,如果打开了源码面板,则调用源码面板的保存方法:

  const doSave = async (unlock: boolean) => {
    // 触发源码面板的关闭
    editor.get('skeleton').getPanel('codeEditor')?.hide()

    try {
      await new Promise<void>((resolve, reject) => {
        // 100 ms 以后判断源码面板是否关闭成功
        setTimeout(() => {
          if (document.querySelector('.next-dialog-body')) {
            reject(new Error('源码面板未关闭成功,说明这个面板还有报错,后续保存就不进行了'))
          } else {
            resolve()
          }
        }, 100)
      })
    } catch (err) {
      return
    }
    // 继续进行保存操作
  }

alvarto avatar Feb 13 '23 03:02 alvarto