Card 卡片

基本用法

```schema: scope=”body” { “type”: “card”, “header”: { “title”: “标题”, “subTitle”: “副标题”, “description”: “这是一段描述”, “avatarClassName”: “pull-left thumb-md avatar b-3x m-r”, “avatar”: “data:image/svg+xml,%3C%3Fxml version=’1.0’ standalone=’no’%3F%3E%3C!DOCTYPE svg PUBLIC ‘-//W3C//DTD SVG 1.1//EN’ ‘http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg t=’1631083237695’ class=’icon’ viewBox=’0 0 1024 1024’ version=’1.1’ xmlns=’http://www.w3.org/2000/svg‘ p-id=’2420’ xmlns:xlink=’http://www.w3.org/1999/xlink‘ width=’1024’ height=’1024’%3E%3Cdefs%3E%3Cstyle type=’text/css’%3E%3C/style%3E%3C/defs%3E%3Cpath d=’M959.872 128c0.032 0.032 0.096 0.064 0.128 0.128v767.776c-0.032 0.032-0.064 0.096-0.128 0.128H64.096c-0.032-0.032-0.096-0.064-0.128-0.128V128.128c0.032-0.032 0.064-0.096 0.128-0.128h895.776zM960 64H64C28.8 64 0 92.8 0 128v768c0 35.2 28.8 64 64 64h896c35.2 0 64-28.8 64-64V128c0-35.2-28.8-64-64-64z’ p-id=’2421’ fill=’%23bfbfbf’%3E%3C/path%3E%3Cpath d=’M832 288c0 53.024-42.976 96-96 96s-96-42.976-96-96 42.976-96 96-96 96 42.976 96 96zM896 832H128V704l224-384 256 320h64l224-192z’ p-id=’2422’ fill=’%23bfbfbf’%3E%3C/path%3E%3C/svg%3E” }, “body”: “这里是内容”, “actions”: [ { “type”: “button”, “label”: “编辑”, “actionType”: “dialog”, “dialog”: { “title”: “编辑”, “body”: “你正在编辑该卡片” } }, { “type”: “button”, “label”: “删除”, “actionType”: “dialog”, “dialog”: { “title”: “提示”, “body”: “你删掉了该卡片” } } ] }

  1. ## 打开链接
  2. > 1.4.0 及以上版本
  3. 通过 `href` 属性可以设置点击卡片打开外部链接
  4. ```schema: scope="body"
  5. {
  6. "type": "card",
  7. "href": "https://github.com/baidu/amis",
  8. "header": {
  9. "title": "标题",
  10. "subTitle": "副标题",
  11. "description": "这是一段描述",
  12. "avatarClassName": "pull-left thumb-md avatar b-3x m-r",
  13. "avatar": "data:image/svg+xml,%3C%3Fxml version='1.0' standalone='no'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg t='1631083237695' class='icon' viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' p-id='2420' xmlns:xlink='http://www.w3.org/1999/xlink' width='1024' height='1024'%3E%3Cdefs%3E%3Cstyle type='text/css'%3E%3C/style%3E%3C/defs%3E%3Cpath d='M959.872 128c0.032 0.032 0.096 0.064 0.128 0.128v767.776c-0.032 0.032-0.064 0.096-0.128 0.128H64.096c-0.032-0.032-0.096-0.064-0.128-0.128V128.128c0.032-0.032 0.064-0.096 0.128-0.128h895.776zM960 64H64C28.8 64 0 92.8 0 128v768c0 35.2 28.8 64 64 64h896c35.2 0 64-28.8 64-64V128c0-35.2-28.8-64-64-64z' p-id='2421' fill='%23bfbfbf'%3E%3C/path%3E%3Cpath d='M832 288c0 53.024-42.976 96-96 96s-96-42.976-96-96 42.976-96 96-96 96 42.976 96 96zM896 832H128V704l224-384 256 320h64l224-192z' p-id='2422' fill='%23bfbfbf'%3E%3C/path%3E%3C/svg%3E"
  14. },
  15. "body": "这里是内容",
  16. "actions": [
  17. {
  18. "type": "button",
  19. "label": "编辑",
  20. "actionType": "dialog",
  21. "dialog": {
  22. "title": "编辑",
  23. "body": "你正在编辑该卡片"
  24. }
  25. },
  26. {
  27. "type": "button",
  28. "label": "删除",
  29. "actionType": "dialog",
  30. "dialog": {
  31. "title": "提示",
  32. "body": "你删掉了该卡片"
  33. }
  34. }
  35. ]
  36. }

设置头像文本

如果没有 avatar,还可以通过 avatarText 设置头像文本

```schema: scope=”body” { “type”: “card”, “href”: “https://github.com/baidu/amis“, “header”: { “title”: “标题”, “subTitle”: “副标题”, “description”: “这是一段描述”, “avatarText”: “AMIS” }, “body”: “这里是内容” }

  1. > 1.5.0 及以上版本
  2. 可以设置文本背景色,它会根据数据分配一个颜色,主要配合 `cards` 使用
  3. ```schema
  4. {
  5. "type": "page",
  6. "data": {
  7. "items": [
  8. {
  9. "engine": "Trident",
  10. "browser": "Internet Explorer 4.0"
  11. },
  12. {
  13. "engine": "Chrome",
  14. "browser": "Chrome 44"
  15. },
  16. {
  17. "engine": "Gecko",
  18. "browser": "Firefox 1.0"
  19. },
  20. {
  21. "engine": "Presto",
  22. "browser": "Opera 10"
  23. },
  24. {
  25. "engine": "Webkie",
  26. "browser": "Safari 12"
  27. }
  28. ]
  29. },
  30. "body": {
  31. "type": "cards",
  32. "source": "$items",
  33. "card": {
  34. "header": {
  35. "avatarText": "${engine|substring:0:2|upperCase}",
  36. "avatarTextBackground": ["#FFB900", "#D83B01", "#B50E0E", "#E81123", "#B4009E", "#5C2D91", "#0078D7", "#00B4FF", "#008272"]
  37. },
  38. "body": [
  39. {
  40. "label": "Browser",
  41. "name": "browser"
  42. }
  43. ]
  44. }
  45. }
  46. }

点击卡片的行为

1.4.0 及以上版本

通过设置 itemAction 可以设置整个卡片的点击行为

```schema: scope=”body” { “type”: “card”, “itemAction”: { “type”: “button”, “actionType”: “dialog”, “dialog”: { “title”: “详情”, “body”: “当前描述” } }, “header”: { “title”: “标题”, “subTitle”: “副标题”, “description”: “这是一段描述”, “avatarClassName”: “pull-left thumb-md avatar b-3x m-r”, “avatar”: “data:image/svg+xml,%3C%3Fxml version=’1.0’ standalone=’no’%3F%3E%3C!DOCTYPE svg PUBLIC ‘-//W3C//DTD SVG 1.1//EN’ ‘http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg t=’1631083237695’ class=’icon’ viewBox=’0 0 1024 1024’ version=’1.1’ xmlns=’http://www.w3.org/2000/svg‘ p-id=’2420’ xmlns:xlink=’http://www.w3.org/1999/xlink‘ width=’1024’ height=’1024’%3E%3Cdefs%3E%3Cstyle type=’text/css’%3E%3C/style%3E%3C/defs%3E%3Cpath d=’M959.872 128c0.032 0.032 0.096 0.064 0.128 0.128v767.776c-0.032 0.032-0.064 0.096-0.128 0.128H64.096c-0.032-0.032-0.096-0.064-0.128-0.128V128.128c0.032-0.032 0.064-0.096 0.128-0.128h895.776zM960 64H64C28.8 64 0 92.8 0 128v768c0 35.2 28.8 64 64 64h896c35.2 0 64-28.8 64-64V128c0-35.2-28.8-64-64-64z’ p-id=’2421’ fill=’%23bfbfbf’%3E%3C/path%3E%3Cpath d=’M832 288c0 53.024-42.976 96-96 96s-96-42.976-96-96 42.976-96 96-96 96 42.976 96 96zM896 832H128V704l224-384 256 320h64l224-192z’ p-id=’2422’ fill=’%23bfbfbf’%3E%3C/path%3E%3C/svg%3E” }, “body”: “这里是内容” }

  1. 注意它和前面的 `href` 配置冲突,如果设置了 `href` 这个将不会生效
  2. ## 设置多媒体卡片
  3. > 1.5.0 及以上版本
  4. 通过设置 `media` 可以设置为多媒体卡片, 通过 `mediaPosition` 可以设置多媒体位置
  5. ```schema: scope="body"
  6. {
  7. "type": "card",
  8. "header": {
  9. "title": "标题"
  10. },
  11. "media": {
  12. "type": "image",
  13. "className": "w-36 h-24",
  14. "url": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
  15. "position": "left"
  16. },
  17. "body": "这里是内容",
  18. "secondary": "次要说明",
  19. "actions": [
  20. {
  21. "type": "button",
  22. "label": "操作",
  23. "actionType": "dialog",
  24. "className": "mr-4",
  25. "dialog": {
  26. "title": "操作",
  27. "body": "你正在编辑该卡片"
  28. }
  29. },
  30. {
  31. "type": "button",
  32. "label": "操作",
  33. "actionType": "dialog",
  34. "className": "mr-2.5",
  35. "dialog": {
  36. "title": "操作",
  37. "body": "你正在编辑该卡片"
  38. }
  39. },
  40. {
  41. "type": "dropdown-button",
  42. "level": "link",
  43. "icon": "fa fa-ellipsis-h",
  44. "className": "pr-1 flex",
  45. "hideCaret": true,
  46. "buttons": [
  47. {
  48. "type": "button",
  49. "label": "编辑",
  50. "actionType": "dialog",
  51. "dialog": {
  52. "title": "编辑",
  53. "body": "你正在编辑该卡片"
  54. }
  55. },
  56. {
  57. "type": "button",
  58. "label": "删除",
  59. "actionType": "dialog",
  60. "dialog": {
  61. "title": "提示",
  62. "body": "你删掉了该卡片"
  63. }
  64. }
  65. ]
  66. }
  67. ],
  68. "toolbar": [
  69. {
  70. "type": "tpl",
  71. "tpl": "标签",
  72. "className": "label label-warning"
  73. }
  74. ]
  75. }

设置标签卡片

1.5.0 及以上版本

```schema: scope=”body” { “type”: “card”, “header”: { “title”: “标题” }, “body”: “这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容”, “secondary”: “次要说明”, “actions”: [ { “type”: “button”, “label”: “操作”, “actionType”: “dialog”, “className”: “mr-4”, “dialog”: { “title”: “操作”, “body”: “你正在编辑该卡片” } }, { “type”: “button”, “label”: “操作”, “actionType”: “dialog”, “className”: “mr-2.5”, “dialog”: { “title”: “操作”, “body”: “你正在编辑该卡片” } }, { “type”: “dropdown-button”, “level”: “link”, “icon”: “fa fa-ellipsis-h”, “className”: “pr-1 flex”, “hideCaret”: true, “buttons”: [ { “type”: “button”, “label”: “编辑”, “actionType”: “dialog”, “dialog”: { “title”: “编辑”, “body”: “你正在编辑该卡片” } }, { “type”: “button”, “label”: “删除”, “actionType”: “dialog”, “dialog”: { “title”: “提示”, “body”: “你删掉了该卡片” } } ] } ], “toolbar”: [ { “type”: “tpl”, “tpl”: “标签”, “className”: “label label-warning” } ] }

  1. ## 设置按钮卡片
  2. > 1.5.0 及以上版本
  3. 按钮卡片一般以卡片形式展示当前卡片的执行语义,例如:创建卡片、添加卡片等场景。
  4. ```schema: scope="body"
  5. {
  6. "type": "card",
  7. "className": "hover:shadow",
  8. "body": {
  9. "type": "wrapper",
  10. "className": "h-32 flex items-center justify-center",
  11. "body": [
  12. {
  13. "type": "wrapper",
  14. "size": "none",
  15. "className": "text-center",
  16. "body": {
  17. "type": "icon",
  18. "icon": "plus",
  19. "className": "text-2xl",
  20. }
  21. },
  22. {
  23. "type": "wrapper",
  24. "size": "none",
  25. "body": "点击会有弹框"
  26. }
  27. ]
  28. },
  29. "itemAction": {
  30. "type": "button",
  31. "actionType": "dialog",
  32. "dialog": {
  33. "title": "详情",
  34. "body": "当前描述"
  35. }
  36. }
  37. }

设置文本卡片

1.5.0 及以上版本

```schema: scope=”body” { “type”: “card”, “header”: { “className”: “items-center”, “title”: “卡片标题” }, “body”: { “type”: “wrapper”, “size”: “none”, “body”: { “type”: “tabs”, “tabs”: [ { “title”: “标签1”, “className”: “p-0”, “tab”: [ { “type”: “card”, “className”: “border-0”, “header”: { “className”: “p-0 pb-2”, “title”: “内容标题” }, “body”: “卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容”, “bodyClassName”: “p-0” }, { “type”: “card”, “className”: “border-0”, “header”: { “className”: “p-0 pb-2”, “title”: “内容标题” }, “body”: “卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容”, “bodyClassName”: “p-0” } ] }, { “title”: “标签2”, “className”: “p-0”, “tab”: “卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容卡片内容” } ] } }, “toolbar”: [ { “type”: “button”, “label”: “操作”, “actionType”: “dialog”, “dialog”: { “title”: “操作”, “body”: “你正在编辑该卡片” } } ] }

  1. ## 设置单元格卡片
  2. > 1.5.0 及以上版本
  3. ```schema: scope="body"
  4. {
  5. "type": "card",
  6. "body": [
  7. {
  8. "type": "wrapper",
  9. "size": "none",
  10. "body": {
  11. "type": "wrapper",
  12. "size": "none",
  13. "style": {
  14. "display": "flex",
  15. "align-items": "center",
  16. "justify-content": "space-between",
  17. "margin-bottom": "4px"
  18. },
  19. "body": [
  20. {
  21. "type": "wrapper",
  22. "size": "none",
  23. "style": {
  24. "flex": "1",
  25. "overflow": "hidden",
  26. "white-space": "nowrap",
  27. "text-overflow": "ellipsis"
  28. },
  29. "body": "单元格"
  30. },
  31. {
  32. "type": "wrapper",
  33. "size": "none",
  34. "style": {
  35. "color": "#999"
  36. },
  37. "body": "内容"
  38. }
  39. ]
  40. }
  41. },
  42. {
  43. "type": "divider"
  44. },
  45. {
  46. "type": "wrapper",
  47. "size": "none",
  48. "body": [
  49. {
  50. "type": "wrapper",
  51. "size": "none",
  52. "style": {
  53. "display": "flex",
  54. "alignItems": "center",
  55. "justifyContent": "space-between",
  56. "marginBottom": "4px"
  57. },
  58. "body": [
  59. {
  60. "type": "wrapper",
  61. "size": "none",
  62. "style": {
  63. "flex": "1",
  64. "overflow": "hidden",
  65. "whiteSpace": "nowrap",
  66. "textOverflow": "ellipsis"
  67. },
  68. "body": "单元格"
  69. },
  70. {
  71. "type": "wrapper",
  72. "size": "none",
  73. "style": {
  74. "color": "#999"
  75. },
  76. "body": "内容"
  77. }
  78. ]
  79. },
  80. {
  81. "type": "wrapper",
  82. "size": "none",
  83. "style": {
  84. "color": "#999",
  85. "fontSize": "12px"
  86. },
  87. "body": "描述信息"
  88. }
  89. ]
  90. }
  91. ]
  92. }

配置工具栏

1.5.0 及以上版本

schema: scope="body" { "type": "card", "header": { "title": "标题", "subTitle": "副标题", "description": "这是一段描述", "avatarClassName": "pull-left thumb-md avatar b-3x m-r", "avatar": "data:image/svg+xml,%3C%3Fxml version='1.0' standalone='no'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg t='1631083237695' class='icon' viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' p-id='2420' xmlns:xlink='http://www.w3.org/1999/xlink' width='1024' height='1024'%3E%3Cdefs%3E%3Cstyle type='text/css'%3E%3C/style%3E%3C/defs%3E%3Cpath d='M959.872 128c0.032 0.032 0.096 0.064 0.128 0.128v767.776c-0.032 0.032-0.064 0.096-0.128 0.128H64.096c-0.032-0.032-0.096-0.064-0.128-0.128V128.128c0.032-0.032 0.064-0.096 0.128-0.128h895.776zM960 64H64C28.8 64 0 92.8 0 128v768c0 35.2 28.8 64 64 64h896c35.2 0 64-28.8 64-64V128c0-35.2-28.8-64-64-64z' p-id='2421' fill='%23bfbfbf'%3E%3C/path%3E%3Cpath d='M832 288c0 53.024-42.976 96-96 96s-96-42.976-96-96 42.976-96 96-96 96 42.976 96 96zM896 832H128V704l224-384 256 320h64l224-192z' p-id='2422' fill='%23bfbfbf'%3E%3C/path%3E%3C/svg%3E" }, "body": "这里是内容", "toolbar": [ { "type": "button", "icon": "fa fa-eye", "actionType": "dialog", "dialog": { "title": "查看", "body": { "type": "form", "body": [ { "type": "static", "name": "engine", "label": "Engine" }, { "type": "divider" }, { "type": "static", "name": "browser", "label": "Browser" }, { "type": "divider" }, { "type": "static", "name": "platform", "label": "Platform(s)" }, { "type": "divider" }, { "type": "static", "name": "version", "label": "Engine version" }, { "type": "divider" }, { "type": "static", "name": "grade", "label": "CSS grade" }, { "type": "divider" }, { "type": "html", "html": "<p>添加其他 <span>Html 片段</span> 需要支持变量替换(todo).</p>" } ] } } }, { "type": "dropdown-button", "level": "link", "icon": "fa fa-ellipsis-h", "hideCaret": true, "buttons": [ { "type": "button", "label": "编辑", "actionType": "dialog", "dialog": { "title": "编辑", "body": "你正在编辑该卡片" } }, { "type": "button", "label": "删除", "actionType": "dialog", "dialog": { "title": "提示", "body": "你删掉了该卡片" } } ] } ] }

属性表

属性名 类型 默认值 说明
type string "card" 指定为 Card 渲染器
className string 外层 Dom 的类名
href 模板 外部链接
header Object Card 头部内容设置
header.className string 头部类名
header.title 模板 标题
header.titleClassName string 标题类名
header.subTitle 模板 副标题
header.subTitleClassName string 副标题类名
header.subTitlePlaceholder string 副标题占位
header.description 模板 描述
header.descriptionClassName string 描述类名
header.descriptionPlaceholder string 描述占位
header.avatar 模板 图片
header.avatarClassName string "pull-left thumb avatar b-3x m-r" 图片包括层类名
header.imageClassName string 图片类名
header.avatarText 模板 如果不配置图片,则会在图片处显示该文本
header.avatarTextBackground Array 设置文本背景色,它会根据数据分配一个颜色
header.avatarTextClassName string 图片文本类名
header.highlight boolean false 是否显示激活样式
header.highlightClassName string 激活样式类名
header.href 模板 点击卡片跳转的链接地址
header.blank boolean true 是否新窗口打开
body Array 内容容器,主要用来放置非表单项组件
bodyClassName string 内容区域类名
actions Array<Action> 配置按钮集合
actionsCount number 4 按钮集合每行个数
itemAction Action 点击卡片的行为
media Object Card 多媒体部内容设置
media.type `’image’\ ‘video’` 多媒体类型
media.url string 图片/视频链接
media.position `’left’\ ‘right’\ ‘top’\ ‘bottom’` 'left' 多媒体位置
media.className string "w-44 h-28" 多媒体类名
media.isLive boolean false 视频是否为直播
media.autoPlay boolean false 视频是否自动播放
media.poster string false 视频封面
secondary 模板 次要说明
toolbar Array<Action> 工具栏按钮
dragging boolean false 是否显示拖拽图标
selectable boolean false 卡片是否可选
checkable boolean true 卡片选择按钮是否禁用
selected boolean false 卡片选择按钮是否选中
hideCheckToggler boolean false 卡片选择按钮是否隐藏
multiple boolean false 卡片是否为多选