Image 图片

基本使用

  1. {
  2. "type": "page",
  3. "body": {
  4. "type": "image",
  5. "src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80"
  6. }
  7. }

也可以配置name属性关联上下文数据

  1. {
  2. "type": "page",
  3. "data": {
  4. "imageUrl": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80"
  5. },
  6. "body": {
  7. "type": "image",
  8. "name": "imageUrl"
  9. }
  10. }

配置标题和说明

  1. {
  2. "type": "page",
  3. "body": {
  4. "type": "image",
  5. "src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
  6. "title": "这是标题",
  7. "imageCaption": "这是一段说明"
  8. }
  9. }

配置缩略图

显示模式

```schema: scope=”body” { “type”: “form”, “mode”: “horizontal”, “data”: { “image”: “https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80“ }, “body”: [ { “type”: “static-image”, “name”: “image”, “label”: “宽度占满”, “thumbMode”: “w-full” }, { “type”: “static-image”, “name”: “image”, “label”: “高度占满”, “thumbMode”: “h-full” }, { “type”: “static-image”, “name”: “image”, “label”: “颜色”, “label”: “默认”, “thumbMode”: “contain” }, { “type”: “static-image”, “name”: “image”, “label”: “覆盖”, “thumbMode”: “cover” } ] }

  1. ### 显示比例
  2. ```schema: scope="body"
  3. {
  4. "type": "form",
  5. "mode": "horizontal",
  6. "data": {
  7. "image": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80"
  8. },
  9. "body": [
  10. {
  11. "type": "static-image",
  12. "name": "image",
  13. "label": "1比1",
  14. "thumbRatio": "1:1",
  15. "thumbMode": "cover"
  16. },
  17. {
  18. "type": "static-image",
  19. "name": "image",
  20. "label": "4比3",
  21. "thumbRatio": "4:3",
  22. "thumbMode": "cover"
  23. },
  24. {
  25. "type": "static-image",
  26. "name": "image",
  27. "label": "颜色",
  28. "label": "16比9",
  29. "thumbRatio": "16:9",
  30. "thumbMode": "cover"
  31. }
  32. ]
  33. }

放大功能

配置"enlargeAble": true,鼠标移动到图片上会显示可点击图标,点击可放大展示

  1. {
  2. "type": "page",
  3. "body": {
  4. "type": "image",
  5. "src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
  6. "enlargeAble": true
  7. }
  8. }

可以配置originalSrc,来指定原图资源地址,作为放大预览的图片地址

  1. {
  2. "type": "page",
  3. "body": {
  4. "type": "image",
  5. "src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
  6. "originalSrc": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg",
  7. "enlargeAble": true
  8. }
  9. }

enlargeTitleenlargeCaption可以配置放大预览中的标题和描述

  1. {
  2. "type": "page",
  3. "body": {
  4. "type": "image",
  5. "src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
  6. "originalSrc": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg",
  7. "enlargeAble": true,
  8. "enlargeTitle": "这是一个标题",
  9. "enlargeCaption": "这是一段描述"
  10. }
  11. }

设置高宽

通过 widthheight 可以设置缩率图显示的高宽

  1. {
  2. "type": "page",
  3. "body": {
  4. "type": "image",
  5. "width": "200px",
  6. "height": "200px",
  7. "src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_400,l_1,f_jpg,q_80"
  8. }
  9. }

原图模式

1.2.3 及以上版本

默认图片为缩略图模式,可以通过配置 imageMode: “original” 修改为原图模式,原图模式为块状展示,宽度尽可能占满。

  1. {
  2. "type": "page",
  3. "data": {
  4. "imageUrl": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg"
  5. },
  6. "body": {
  7. "type": "image",
  8. "imageMode": "original",
  9. "name": "imageUrl",
  10. "title": "这是标题",
  11. "imageCaption": "这是一段说明"
  12. }
  13. }

打开外部链接

1.3.3 及以上版本

可以设置 href 属性来支持图片点击打开链接,需要注意这和放大功能是冲突的,只能二选一。

```schema: scope=”body” { “type”: “image”, “src”: “https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80“, “href”: “https://github.com/baidu/amis“ }

  1. href 也可以是模板
  2. ```schema
  3. {
  4. "type": "page",
  5. "data": {
  6. "imageUrl": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg",
  7. "imageHref": "https://github.com/baidu/amis"
  8. },
  9. "body": {
  10. "type": "image",
  11. "name": "imageUrl",
  12. "href": "${imageHref}"
  13. }
  14. }

用作 Field 时

当用在 Table 的列配置 Column、List 的内容、Card 卡片的内容和表单的 Static-XXX 中时,可以设置name属性,映射同名变量

Table 中的列类型

```schema: scope=”body” { “type”: “table”, “data”: { “items”: [ { “id”: “1”, “image”: “https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80“ }, { “id”: “2”, “image”: “https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80“ }, { “id”: “3”, “image”: “https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80“ } ] }, “columns”: [ { “name”: “id”, “label”: “Id” },

  1. {
  2. "name": "image",
  3. "label": "图片",
  4. "type": "image"
  5. }
  6. ]

}

  1. List 的内容、Card 卡片的内容配置同上
  2. ### Form 中静态展示
  3. ```schema: scope="body"
  4. {
  5. "type": "form",
  6. "data": {
  7. "image": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80"
  8. },
  9. "body": [
  10. {
  11. "type": "static-image",
  12. "name": "image",
  13. "label": "颜色"
  14. }
  15. ]
  16. }

自定义点击行为

1.5.0 及以上版本

可以通过 clickAction 设置点击触发行为。

schema: scope="body" { "type": "image", "src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80", "class": "cursor-pointer", "clickAction": { "actionType": "dialog", "dialog": { "title": "弹框标题", "body": "这是一个弹框" } } }

属性表

属性名 类型 默认值 说明
type string 如果在 Table、Card 和 List 中,为"image";在 Form 中用作静态展示,为"static-image"
className string 外层 CSS 类名
imageClassName string 图片 CSS 类名
thumbClassName string 图片缩率图 CSS 类名
height string 图片缩率高度
width string 图片缩率宽度
title string 标题
imageCaption string 描述
placeholder string 占位文本
defaultImage string 无数据时显示的图片
src string 缩略图地址
href 模板 外部链接地址
originalSrc string 原图地址
enlargeAble boolean 支持放大预览
enlargeTitle string 放大预览的标题
enlargeCaption string 放大预览的描述
thumbMode string contain 预览图模式,可选:'w-full', 'h-full', 'contain', 'cover'
thumbRatio string 1:1 预览图比例,可选:'1:1', '4:3', '16:9'
imageMode string thumb 图片展示模式,可选:'thumb', 'original' 即:缩略图模式 或者 原图模式