baidu/amis

amis-editor,编辑器初始化改变schema,导致功能无法使用

Opened this issue · 0 comments

描述问题:

升级amis版本至6.3.0后,amis-editor编辑器初始化会改变原有schema格式,导致功能不可用。

背景介绍,项目中有很多通用的crud表单操作是相似的,于是想通过schemaApi方式将通用的crud json schema保存到后端,前端拿到数据动态的修改columns,实现复用CRUD组件的功能。

Screen Shot 2024-04-29 at 14 08 22 Screen Shot 2024-04-29 at 14 09 57

截图或视频:

Screen.Recording.2024-04-29.at.14.01.57.mov

如何复现(请务必完整填写下面内容):

  1. 你是如何使用 amis 的?
    npm

  2. amis 版本是什么?请先在最新 beta 版本测试问题是否存在
    amis-editor: 6.3.0

  3. 粘贴有问题的完整 amis schema 代码:

{
  "type": "page",
  "title": "Simple Form Page",
  "regions": [
    "body"
  ],
  "body": [
    {
      "type": "amis",
      "id": "u:463c31ac62aa",
      "name": "crudSchema"
    }
  ],
  "id": "u:ad97cbe6e33a",
  "initApi": {
    "url": "/api/debug/schema",
    "data": {
      "idm": "${id}"
    },
    "method": "get",
    "adaptor": "  return {...payload,  \n data: {...payload.data.amisJson,idm:api.query.idm} \n}",
    "responseData": {
      "crudSchema": {
        "&": "$$",
        "id": "u:6e3b8f2d63da",
        "columns": "${CONCAT(columns[0], GETRENDERERDATA('u:ad97cbe6e33a','column1'),GETRENDERERDATA('u:ad97cbe6e33a','column2'),columns[1])}"
      }
    }
  },
  "pullRefresh": {
    "disabled": true
  },
  "data": {
    "column1": {
      "label": "测试1",
      "name": "test1"
    },
    "column2": {
      "label": "测试2",
      "name": "test2"
    }
  },
  "asideResizor": false
}

mock 接口代码

module.exports = function (req, res) {
  setTimeout(() => {
    res.json({
      status: 0,
      msg: 'ok',
      data: {
        amisJson: {
          type: 'crud',
          columns: [
            {
              label: '序号',
              tpl: '${index+ 1}'
            },
            {
              label: '操作',
              type: 'opeartion',
              buttons: [
                {
                  type: 'button',
                  label: '编辑',
                  onEvent: {
                    click: {}
                  }
                }
              ]
            }
          ]
        }
      }
    });
  }, 2000);
};
  1. 操作步骤
    将上诉schema复制到编辑器里面,点击右上角【预览】按钮,再次点击【编辑】按钮,触发编辑器初始化schema逻辑,schema会被编辑器重置修改,导致功能不可用。