mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +08:00
feat: image 支持 width height (#1624)
* 修复 string2regExp 报错, 传入的时候先转成字符 * 修复 diffEditor 报错 * 修复 default filter 问题 * 修复文档链接错误 * feat:image 支持设置高宽 Co-authored-by: 2betop <2betop.cn@gmail.com>
This commit is contained in:
parent
70102c3c16
commit
c3dff89ce1
@ -165,6 +165,22 @@ order: 52
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 设置高宽
|
||||||
|
|
||||||
|
通过 `width` 和 `height` 可以设置缩率图显示的高宽
|
||||||
|
|
||||||
|
```schema
|
||||||
|
{
|
||||||
|
"type": "page",
|
||||||
|
"body": {
|
||||||
|
"type": "image",
|
||||||
|
"width": "200px",
|
||||||
|
"height": "200px",
|
||||||
|
"src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## 用作 Field 时
|
## 用作 Field 时
|
||||||
|
|
||||||
当用在 Table 的列配置 Column、List 的内容、Card 卡片的内容和表单的 Static-XXX 中时,可以设置`name`属性,映射同名变量
|
当用在 Table 的列配置 Column、List 的内容、Card 卡片的内容和表单的 Static-XXX 中时,可以设置`name`属性,映射同名变量
|
||||||
@ -225,11 +241,16 @@ List 的内容、Card 卡片的内容配置同上
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 属性表
|
||||||
|
|
||||||
| 属性名 | 类型 | 默认值 | 说明 |
|
| 属性名 | 类型 | 默认值 | 说明 |
|
||||||
| -------------- | --------- | --------- | -------------------------------------------------------------------------------------- |
|
| -------------- | --------- | --------- | -------------------------------------------------------------------------------------- |
|
||||||
| type | `string` | | 如果在 Table、Card 和 List 中,为`"color"`;在 Form 中用作静态展示,为`"static-color"` |
|
| type | `string` | | 如果在 Table、Card 和 List 中,为`"color"`;在 Form 中用作静态展示,为`"static-color"` |
|
||||||
| className | `string` | | 外层 CSS 类名 |
|
| className | `string` | | 外层 CSS 类名 |
|
||||||
| imageClassName | `string` | | 图片 CSS 类名 |
|
| imageClassName | `string` | | 图片 CSS 类名 |
|
||||||
|
| thumbClassName | `string` | | 图片缩率图 CSS 类名 |
|
||||||
|
| height | `string` | | 图片缩率高度 |
|
||||||
|
| width | `string` | | 图片缩率宽度 |
|
||||||
| title | `string` | | 标题 |
|
| title | `string` | | 标题 |
|
||||||
| imageCaption | `string` | | 描述 |
|
| imageCaption | `string` | | 描述 |
|
||||||
| placeholder | `string` | | 占位文本 |
|
| placeholder | `string` | | 占位文本 |
|
||||||
|
@ -154,7 +154,7 @@ fis.match('{*.ts,*.jsx,*.tsx,/src/**.js,/src/**.ts}', {
|
|||||||
importHelpers: true,
|
importHelpers: true,
|
||||||
esModuleInterop: true,
|
esModuleInterop: true,
|
||||||
experimentalDecorators: true,
|
experimentalDecorators: true,
|
||||||
sourceMap: true,
|
inlineSourceMap: true,
|
||||||
target: 4
|
target: 4
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
@ -86,20 +86,19 @@
|
|||||||
"video-react": "0.14.1"
|
"video-react": "0.14.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/file-saver": "^2.0.1",
|
|
||||||
"@types/papaparse": "^5.2.2",
|
|
||||||
"@types/async": "^2.0.45",
|
"@types/async": "^2.0.45",
|
||||||
"@types/classnames": "^2.2.3",
|
"@types/classnames": "^2.2.3",
|
||||||
"@types/dom-helpers": "^3.4.1",
|
"@types/dom-helpers": "^3.4.1",
|
||||||
"@types/echarts": "^4.9.2",
|
"@types/echarts": "^4.9.2",
|
||||||
|
"@types/file-saver": "^2.0.1",
|
||||||
"@types/history": "^4.6.0",
|
"@types/history": "^4.6.0",
|
||||||
"history": "4.7.2",
|
|
||||||
"@types/hoist-non-react-statics": "^3.3.1",
|
"@types/hoist-non-react-statics": "^3.3.1",
|
||||||
"@types/jest": "^24.9.1",
|
"@types/jest": "^24.9.1",
|
||||||
"@types/jquery": "^3.3.1",
|
"@types/jquery": "^3.3.1",
|
||||||
"@types/lodash": "^4.14.76",
|
"@types/lodash": "^4.14.76",
|
||||||
"@types/mkdirp": "^1.0.1",
|
"@types/mkdirp": "^1.0.1",
|
||||||
"@types/node": "^12.7.1",
|
"@types/node": "^12.7.1",
|
||||||
|
"@types/papaparse": "^5.2.2",
|
||||||
"@types/prop-types": "^15.5.2",
|
"@types/prop-types": "^15.5.2",
|
||||||
"@types/qs": "^6.5.1",
|
"@types/qs": "^6.5.1",
|
||||||
"@types/react": "^16.9.35",
|
"@types/react": "^16.9.35",
|
||||||
@ -137,6 +136,7 @@
|
|||||||
"font-awesome": "4.7.0",
|
"font-awesome": "4.7.0",
|
||||||
"fs-walk": "0.0.2",
|
"fs-walk": "0.0.2",
|
||||||
"glob": "^7.1.6",
|
"glob": "^7.1.6",
|
||||||
|
"history": "4.7.2",
|
||||||
"husky": "^2.2.0",
|
"husky": "^2.2.0",
|
||||||
"jest": "^26.6.3",
|
"jest": "^26.6.3",
|
||||||
"jest-canvas-mock": "^2.3.0",
|
"jest-canvas-mock": "^2.3.0",
|
||||||
|
@ -11,12 +11,11 @@
|
|||||||
|
|
||||||
.#{$ns}Image {
|
.#{$ns}Image {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: px2rem(120px);
|
|
||||||
border: var(--borderWidth) solid var(--borderColor);
|
border: var(--borderWidth) solid var(--borderColor);
|
||||||
padding: var(--gap-xs);
|
padding: var(--gap-xs);
|
||||||
|
|
||||||
&-thumb {
|
&-thumb {
|
||||||
width: 100%;
|
width: px2rem(108px);
|
||||||
height: px2rem(108px);
|
height: px2rem(108px);
|
||||||
background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgd2lkdGg9IjIwMCIgaGVpZ2h0PSI0MDA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gPHJlY3QgZmlsbD0id2hpdGUiIHg9IjEwIiB5PSIwIiB3aWR0aD0iMTAiIGhlaWdodD0iMTAiIC8+CiAgICAgICAgICAgIDxyZWN0IGZpbGw9ImJsYWNrIiB4PSIxMCIgeT0iMTAiIHdpZHRoPSIxMCIgaGVpZ2h0PSIxMCIgb3BhY2l0eT0iMC4xIiAvPgogICAgICAgICAgICA8cmVjdCBmaWxsPSJ3aGl0ZSIgeD0iMCIgeT0iMTAiIHdpZHRoPSIxMCIgaGVpZ2h0PSIxMCIgLz4KICAgICAgICA8L3BhdHRlcm4+CiAgICA8L2RlZnM+CiAgICA8cmVjdCBmaWxsPSJ1cmwoI2dyaWQpIiB4PSIwIiB5PSIwIiB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiAvPgo8L3N2Zz4=');
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
@ -57,9 +57,36 @@ export interface ImageSchema extends BaseSchema {
|
|||||||
*/
|
*/
|
||||||
showDimensions?: boolean;
|
showDimensions?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片无法显示时的替换文本
|
||||||
|
*/
|
||||||
alt?: string;
|
alt?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 高度
|
||||||
|
*/
|
||||||
|
height?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 宽度
|
||||||
|
*/
|
||||||
|
width?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片 css 类名
|
||||||
|
*/
|
||||||
imageClassName?: SchemaClassName;
|
imageClassName?: SchemaClassName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外层 css 类名
|
||||||
|
*/
|
||||||
|
className?: SchemaClassName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片缩率图外层 css 类名
|
||||||
|
*/
|
||||||
|
thumbClassName?: SchemaClassName;
|
||||||
|
|
||||||
caption?: SchemaTpl;
|
caption?: SchemaTpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,8 +121,11 @@ export class ImageThumb extends React.Component<ImageThumbProps> {
|
|||||||
classnames: cx,
|
classnames: cx,
|
||||||
className,
|
className,
|
||||||
imageClassName,
|
imageClassName,
|
||||||
|
thumbClassName,
|
||||||
thumbMode,
|
thumbMode,
|
||||||
thumbRatio,
|
thumbRatio,
|
||||||
|
height,
|
||||||
|
width,
|
||||||
src,
|
src,
|
||||||
alt,
|
alt,
|
||||||
title,
|
title,
|
||||||
@ -110,9 +140,11 @@ export class ImageThumb extends React.Component<ImageThumbProps> {
|
|||||||
<div
|
<div
|
||||||
className={cx(
|
className={cx(
|
||||||
'Image-thumb',
|
'Image-thumb',
|
||||||
|
thumbClassName,
|
||||||
thumbMode ? `Image-thumb--${thumbMode}` : '',
|
thumbMode ? `Image-thumb--${thumbMode}` : '',
|
||||||
thumbRatio ? `Image-thumb--${thumbRatio.replace(/:/g, '-')}` : ''
|
thumbRatio ? `Image-thumb--${thumbRatio.replace(/:/g, '-')}` : ''
|
||||||
)}
|
)}
|
||||||
|
style={{height: height, width: width}}
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
onLoad={onLoad}
|
onLoad={onLoad}
|
||||||
@ -221,6 +253,9 @@ export class ImageField extends React.Component<ImageFieldProps, object> {
|
|||||||
title,
|
title,
|
||||||
data,
|
data,
|
||||||
imageClassName,
|
imageClassName,
|
||||||
|
thumbClassName,
|
||||||
|
height,
|
||||||
|
width,
|
||||||
classnames: cx,
|
classnames: cx,
|
||||||
src,
|
src,
|
||||||
thumbMode,
|
thumbMode,
|
||||||
@ -239,6 +274,9 @@ export class ImageField extends React.Component<ImageFieldProps, object> {
|
|||||||
{value ? (
|
{value ? (
|
||||||
<ThemedImageThumb
|
<ThemedImageThumb
|
||||||
imageClassName={imageClassName}
|
imageClassName={imageClassName}
|
||||||
|
thumbClassName={thumbClassName}
|
||||||
|
height={height}
|
||||||
|
width={width}
|
||||||
src={value}
|
src={value}
|
||||||
title={filter(title, data)}
|
title={filter(title, data)}
|
||||||
caption={filter(imageCaption, data)}
|
caption={filter(imageCaption, data)}
|
||||||
|
Loading…
Reference in New Issue
Block a user