amis icon indicating copy to clipboard operation
amis copied to clipboard

crud组件支持前端搜索嘛 就和分页一样

Open 502647092 opened this issue 6 years ago • 12 comments

502647092 avatar Dec 23 '19 06:12 502647092

{
    type: 'crud',
    loadDataOnce: true,
    api: 'xxx',
    source: '${rows | filter:engine:match:keywords}',
    ...
}

rows:crud接口返回的数组项的字段 engine:是需要检索的那一列的字段名 keywords:是检索关键字input的name值

image

RickCole21 avatar Dec 25 '19 12:12 RickCole21

好的 感谢

502647092 avatar Dec 26 '19 02:12 502647092

加了之后就报错了 麻烦问下问题在哪里 image

{
    "$schema": "https://houtai.baidu.com/v2/schemas/crud.json",
    "name": "service",
    "type": "crud",
    "api": "/service/list",
    "source": "${rows | filter:service-name:match:search}",
    "loadDataOnce": true,
    "syncLocation": false,
    "headerToolbar": [
        {
            "name": "form",
            "type": "form",
            "wrapWithPanel": false,
            "controls": [
                {
                    "type": "text",
                    "name": "search",
                    "label": false
                }
            ]
        },
        {
            "type": "button",
            "label": "刷新",
            "level": "dark",
            "align": "right",
            "actionType": "reload",
            "target": "service"
        }
    ],
    "footerToolbar": [
        "statistics",
        "switch-per-page",
        "pagination"
    ],
    "columns": [
        {
            "name": "service-name",
            "label": "服务名称",
            "popOver": {
                "body": {
                    "type": "tpl",
                    "tpl": "${service-name}"
                },
                "offset": {
                    "x": 100
                }
            },
            "type": "tpl",
            "tpl": "${service-name|truncate:30}"
        },
        {
            "name": "image",
            "label": "镜像名称",
            "popOver": {
                "body": {
                    "type": "tpl",
                    "tpl": "${image}"
                },
                "offset": {
                    "x": 20
                }
            },
            "type": "tpl",
            "tpl": "${image|truncate:50}"
        },
        {
            "name": "mode",
            "label": "模式",
            "type": "tpl",
            "tpl": "<% if (data.mode.Replicated) { %> \n                            <span class='label label-success'> <% print('Replicated '+data.mode.Replicated.Replicas) \n                        } else { %> \n                            <span class='label label-primary'> <% print('Global') \n                        } %> </span>"
        },
        {
            "name": "updated_at",
            "type": "date",
            "label": "更新时间",
            "format": "YYYY-MM-DD hh:mm:ss"
        },
        {
            "name": "update_status.State",
            "label": "更新状态",
            "type": "mapping",
            "map": {
                "completed": "<span class='label label-success'>已完成</span>",
                "updating": "<span class='label label-warning'>更新中</span>",
                "failed": "<span class='label label-danger'>更新失败</span>",
                "rollback_started": "<span class='label label-warning'>回滚中</span>",
                "rollback_completed": "<span class='label label-success'>回滚完成</span>",
                "*": "<span class='label label-default'>${update_status.State}</span>"
            }
        },
        {
            "type": "operation",
            "label": "操作",
            "width": 200,
            "fixed": "right",
            "buttons": [
                {
                    "type": "button",
                    "level": "warning",
                    "label": "重启",
                    "actionType": "ajax",
                    "confirmText": "是否重启 ${name} 服务?",
                    "api": "/service/${name}/restart"
                },
                {
                    "type": "button",
                    "level": "primary",
                    "label": "回滚",
                    "actionType": "ajax",
                    "disabledOn": "!data.update_status",
                    "confirmText": "是否回滚 ${name} 服务?",
                    "api": "/service/${name}/rollback"
                },
                {
                    "type": "button",
                    "level": "danger",
                    "label": "删除",
                    "actionType": "ajax",
                    "confirmText": "是否删除 ${name} 服务?",
                    "api": "/service/${name}/delete"
                },
                {
                    "type": "button",
                    "level": "info",
                    "label": "详情",
                    "actionType": "drawer",
                    "drawer": {
                        "title": "服务 ${name}",
                        "size": "lg",
                        "body": {
                            "type": "service",
                            "schemaApi": "get:/page/manager/service-details"
                        }
                    }
                }
            ]
        }
    ]
}

502647092 avatar Dec 26 '19 10:12 502647092

后端返回的数据结构是

{"status":0,"msg":"","data":[]}

502647092 avatar Dec 26 '19 10:12 502647092

后端返回的数据结构是

{"status":0,"msg":"","data":[]}
{
    "status":0,
    "msg":"",
    "data":{
        "rows":[]
    }
}

RickCole21 avatar Dec 26 '19 10:12 RickCole21

直接渲染的时候是正常的 能不能直接把data用数组返回 source里直接引用data的内容过滤

502647092 avatar Dec 26 '19 10:12 502647092

source 里面 ${rows} 就不会报错了。不能直接是数组,必须得有个 key

2betop avatar Dec 26 '19 11:12 2betop

问下 headerToolbar 里的Form的字段 是不是不能用在这层的crud的搜索里 image 好像这个参数取不到值

502647092 avatar Dec 26 '19 11:12 502647092

@2betop 好的 我加上key了 不过 我感觉可以试试用 ${& | xxx} 这种方式 直接取data处理 这样就和Tpl的逻辑一致了

502647092 avatar Dec 26 '19 11:12 502647092

因为 headerToolbar 里的参数取不到 我现在把搜索参数放到crud的filter上面了 但是每次提交就会重新从后端获取数据 能不能加个功能 match 的字段变更的时候 如果是 loadDataOnce 那就不从后端获取 只执行source的过滤

502647092 avatar Dec 26 '19 11:12 502647092

这两种需求都可能有 @RickCole21 考虑加个参数?

2betop avatar Dec 26 '19 11:12 2betop

这两种需求都可能有 @RickCole21 考虑加个参数?

👌

RickCole21 avatar Dec 26 '19 11:12 RickCole21