baidu / amis

前端低代码框架,通过 JSON 配置就能生成各种页面。
https://baidu.github.io/amis/
Apache License 2.0
16.49k stars 2.41k forks source link

crud 内,通过initAPI获取的数据,在Operation组件内失效 #10445

Open Shazoo opened 2 weeks ago

Shazoo commented 2 weeks ago

实现场景:

基础实例的修改

存在的问题:

在initApi内获取的数据,在crud内展示。

问题是,到了operation部分,就无法获取这个数据了。

当前方案:

(function () {
    const response = {
        data: {
            "type": "page",
            "initApi": "get:/api/users/GetMe",
            // 获取一个"me"的对象
            "title": "${me.username},欢迎回来!",
                       // 这里正常获取了。
            "debug": true,
            "body": [
                {
                    "label": "新增",
                    "type": "button",
                    "actionType": "dialog",
                    "level": "primary",
                    "className": "m-b-sm",
                    "dialog": {
                        "title": "新增表单",
                        "body": {
                            "type": "form",
                            "api": "post:/api/users/CreateUser",
                            "body": [
                                {
                                    "type": "input-text",
                                    "name": "username",
                                    "label": "用户名",
                                    "required": true
                                },
                                {
                                    "type": "input-password",
                                    "name": "password",
                                    "label": "密码",
                                    "required": true,
                                    "validations": "minLength:6,maxLength:12"
                                },
                                {
                                    "type": "input-password",
                                    "name": "repassword",
                                    "label": "确认密码",
                                    "required": true,
                                    "validations": "equalsField:password"
                                },
                                {
                                    "type": "input-text",
                                    "name": "memo",
                                    "label": "备注"
                                },
                                {
                                    "type": "switch",
                                    "name": "is_admin",
                                    "label": "管理员",
                                    "value": false
                                },
                                {
                                    "type": "input-date",
                                    "name": "expired_time",
                                    "minDate": "+1days",
                                    "value": "+30days",
                                    "label": "过期时间"
                                }
                            ]
                        }
                    }
                },
                {
                    "type": "crud",
                    "perPage": 20,
                    "api": {
                        "method": "GET",
                        "url": "/api/users/GetUsers/${page}/${perPage}"
                    },
                    "syncLocation": false,
                    "columns": [
                        {
                            "name": "id",
                            "label": "用户ID"
                        },
                        {
                            "name": "username",
                            "label": "用户名"
                        },
                        {
                            "name": "create_time",
                            "type": "date",
                            "label": "创建时间"
                        },
                        {
                            "name": "expired_time",
                            "type": "date",
                            "label": "过期时间"
                        },
                        {
                            "name": "memo",
                            "label": "备注"
                        },
                        {
                            "name": "is_admin",
                            "label": "是否管理员",
                            "type": 'status',
                        },
                        {
                            "type": "operation",
                            "label": "操作",
                            "buttons": [
                                {
                                    //从这里开始,me就无法使用了。
                                    "label": "详情",
                                    "type": "button",
                                    "level": "link",
                                    "actionType": "dialog",
                                    "dialog": {
                                        "title": "用户详情",
                                        "body": {
                                            "type": "form",
                                            "static": true,
                                            "body": [
                                                {
                                                    "type": "input-text",
                                                    "name": "username",
                                                    "label": "用户名"
                                                },
                                                {
                                                    "type": "input-text",
                                                    "name": "memo",
                                                    "label": "备注"
                                                },
                                                {
                                                    "type": "checkbox",
                                                    "name": "is_admin",
                                                    "label": "管理员"
                                                },
                                                {
                                                    "type": "input-date",
                                                    "name": "create_time",
                                                    "label": "version"
                                                },
                                                {
                                                    "type": "input-date",
                                                    "name": "expired_time",
                                                    "label": "version"
                                                }
                                            ]

                                        },
                                        "actions": [
                                            {
                                                "type": "button",
                                                "actionType": "confirm",
                                                "label": "确定",
                                                "primary": true
                                            }
                                        ],
                                    }
                                },
                                {
                                    "label": "${me.username}",
                                    "type": "button",
                                    "level": "link",
                                    "className": "text-danger",
                                    "actionType": "ajax",
                                    // "disabledOn": "${id === me.id}",
                                    "api": "/api/users/DeleteUser/${id}",
                                }
                            ]
                        }
                    ]
                }],
        },
        status: 0
    }

    window.jsonpCallback && window.jsonpCallback(response);
})();

注意其中的注释。crud内的很多组件都可以正常获取 ${me.username} ,但是,我把删除的 label换成了 ${me.username},无法使用了。当然,也无法用表达式判断是否显示了。