amis icon indicating copy to clipboard operation
amis copied to clipboard

crud点击第一列checkbox报Invariant Violation: Maximum update depth exceeded

Open kathygeng opened this issue 6 years ago • 1 comments

描述问题:

参考https://baidu.gitee.io/amis/examples/crud/table?page=1的增删改查第一个表格模式的示例开发了一个增删改查功能,在点击列表第一列checkbox选中一行的时候浏览器卡死并报错,等待一段时间发现整个表格被全选了。

截图或视频:

F12浏览器报错内容为: [mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: 'Reaction[TableRow.render()] Invariant Violation: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

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

  1. 你是如何使用 amis 的? 无论npm或者是直接在html页面中引用js和css,都是这样

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

{
    "$schema": "https://houtai.baidu.com/v2/schemas/page.json#",
    "title": "APP 管理",
    "body": [
        {
            "type": "crud",
            "draggable": true,
            "api": {
                "method": "get",
                "url": "http://civet.io:16500/api/v1/app",
                "headers": {
                    "Authorization": "Bearer",
                    "source": "amis"
                }
            },
            "keepItemSelectionOnPageChange": true,
            "labelTpl": "${id} ${engine}",
            "quickSaveApi": "https://houtai.baidu.com/api/sample/bulkUpdate",
            "quickSaveItemApi": {
                "url": "https://houtai.baidu.com/api/sample/$id",
                "data": {
                    "requestUrl": "$requestUrl",
                    "apiAlias": "$apiAlias"
                }
            },
            "filterTogglable": true,
            "headerToolbar": [
                "filter-toggler",
                "bulkActions",
                {
                    "type": "tpl",
                    "tpl": "当前有 ${total} 条数据",
                    "className": "v-middle"
                },
                {
                    "type": "columns-toggler",
                    "align": "right"
                },
                {
                    "type": "drag-toggler",
                    "align": "right"
                },
                {
                    "type": "pagination",
                    "align": "right"
                }
            ],
            "footerToolbar": [
                "statistics",
                "switch-per-page",
                "pagination"
            ],
            "columns": [
                {
                    "name": "technicalId",
                    "label": "技术ID",
                    "type": "text"
                },
                {
                    "name": "appId",
                    "label": "APP编码",
                    "type": "text"
                },
                {
                    "type": "text",
                    "name": "appName",
                    "label": "APP名称"
                },
                {
                    "type": "text",
                    "label": "版本号",
                    "name": "appVersion"
                },
                {
                    "type": "text",
                    "label": "创建人",
                    "name": "createBy"
                },
                {
                    "type": "text",
                    "label": "创建时间",
                    "name": "createAt"
                },
                {
                    "type": "text",
                    "label": "修改人",
                    "name": "modifyBy"
                },
                {
                    "type": "text",
                    "label": "修改时间",
                    "name": "modifyAt"
                },
                {
                    "type": "operation",
                    "label": "操作",
                    "width": 100,
                    "buttons": [
                        {
                            "type": "button",
                            "icon": "fa fa-eye",
                            "actionType": "dialog",
                            "tooltip": "查看",
                            "dialog": {
                                "title": "查看",
                                "body": {
                                    "type": "form",
                                    "controls": [
                                        {
                                            "type": "static",
                                            "name": "technicalId",
                                            "label": "技术ID"
                                        },
                                        {
                                            "type": "divider"
                                        },
                                        {
                                            "type": "static",
                                            "name": "appId",
                                            "label": "APP编码"
                                        },
                                        {
                                            "type": "divider"
                                        },
                                        {
                                            "type": "static",
                                            "name": "appName",
                                            "label": "APP名称"
                                        },
                                        {
                                            "type": "divider"
                                        },
                                        {
                                            "type": "static",
                                            "name": "appVersion",
                                            "label": "版本号"
                                        },
                                        {
                                            "type": "divider"
                                        },
                                        {
                                            "type": "static",
                                            "name": "desc",
                                            "label": "描述"
                                        }
                                    ]
                                }
                            }
                        },
                        {
                            "type": "button",
                            "icon": "fa fa-pencil",
                            "tooltip": "编辑",
                            "actionType": "drawer",
                            "drawer": {
                                "position": "left",
                                "size": "lg",
                                "title": "编辑",
                                "body": {
                                    "type": "form",
                                    "name": "sample-edit-form",
                                    "api": {
                                        "url": "http://civet.io:16500/api/v1/app/$technicalId",
                                        "headers": {
                                            "Authorition": "aaaaaa",
                                            "source": "amis"
                                        },
                                        "method": "put"
                                    },
                                    "controls": [
                                        {
                                            "type": "text",
                                            "label": "APP编码",
                                            "name": "appId",
                                            "size": "md"
                                        },
                                        {
                                            "label": "APP名称",
                                            "type": "text",
                                            "name": "appName",
                                            "autoComplete": false,
                                            "mode": "",
                                            "size": "md",
                                            "horizontal": {
                                                "leftFixed": "",
                                                "left": 2,
                                                "right": 10
                                            },
                                            "required": true
                                        },
                                        {
                                            "type": "text",
                                            "label": "版本号",
                                            "name": "appVersion",
                                            "autoComplete": false,
                                            "size": "md",
                                            "mode": ""
                                        },
                                        {
                                            "type": "textarea",
                                            "label": "描述",
                                            "name": "desc",
                                            "minRows": 3,
                                            "maxRows": 20,
                                            "size": "md"
                                        }
                                    ]
                                }
                            }
                        },
                        {
                            "type": "button",
                            "icon": "fa fa-times text-danger",
                            "actionType": "ajax",
                            "tooltip": "删除",
                            "confirmText": "您确认要删除?",
                            "api": "delete:http://civet.io:16500/api/v1/app/$technicalId"
                        }
                    ],
                    "toggled": true
                }
            ],
            "filter": {
                "title": "条件搜索",
                "submitText": "",
                "controls": [
                    {
                        "type": "text",
                        "name": "appName",
                        "placeholder": "通过APP名称搜索",
                        "addOn": {
                            "label": "搜索",
                            "type": "submit"
                        }
                    }
                ]
            },
            "bulkActions": [
                {
                    "label": "批量删除",
                    "actionType": "ajax",
                    "api": "delete:https://houtai.baidu.com/api/sample/${ids|raw}",
                    "confirmText": "确定要批量删除?"
                },
                {
                    "label": "批量修改",
                    "actionType": "dialog",
                    "dialog": {
                        "title": "批量编辑",
                        "name": "sample-bulk-edit",
                        "body": {
                            "type": "form",
                            "api": "https://houtai.baidu.com/api/sample/bulkUpdate2",
                            "controls": [
                                {
                                    "type": "hidden",
                                    "name": "ids"
                                },
                                {
                                    "type": "text",
                                    "name": "engine",
                                    "label": "Engine"
                                }
                            ]
                        }
                    }
                }
            ]
        }
    ],
    "toolbar": [
        {
            "type": "button",
            "actionType": "dialog",
            "label": "新增",
            "icon": "fa fa-plus pull-left",
            "primary": true,
            "dialog": {
                "title": "新增APP",
                "body": {
                    "type": "form",
                    "name": "sample-edit-form",
                    "api": {
                        "url": "http://civet.io:16500/api/v1/app",
                        "headers": {
                            "Authorition": "aaaaaa",
                            "source": "amis"
                        },
                        "method": "post"
                    },
                    "controls": [
                        {
                            "type": "text",
                            "label": "APP编码",
                            "name": "appId",
                            "size": "md"
                        },
                        {
                            "label": "APP名称",
                            "type": "text",
                            "name": "appName",
                            "autoComplete": false,
                            "mode": "",
                            "size": "md",
                            "horizontal": {
                                "leftFixed": "",
                                "left": 2,
                                "right": 10
                            },
                            "required": true
                        },
                        {
                            "type": "text",
                            "label": "版本号",
                            "name": "appVersion",
                            "autoComplete": false,
                            "size": "md",
                            "mode": ""
                        },
                        {
                            "type": "textarea",
                            "label": "描述",
                            "name": "desc",
                            "minRows": 3,
                            "maxRows": 20,
                            "size": "md"
                        }
                    ]
                }
            }
        }
    ]
}
  1. 操作步骤 点击表格前某一行数据的checkbox即可重现(要有数据)

kathygeng avatar Aug 24 '20 03:08 kathygeng

试试配置一下primaryField,设置你行数据中的一个唯一标识字段,例如id之类的

RickCole21 avatar Aug 24 '20 03:08 RickCole21