Skip to content

Commit

Permalink
feat: 图片集优化
Browse files Browse the repository at this point in the history
  • Loading branch information
sqzhou committed Nov 16, 2023
1 parent 68e079b commit 09a4599
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 21 deletions.
60 changes: 59 additions & 1 deletion packages/amis-ui/scss/components/_image-gallery.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,46 @@
// max-width: calc(100% - #{px2rem(128px)});
padding: px2rem(44px) 0 px2rem(24px);

&-reverse {
flex-direction: row-reverse;

.#{$ns}ImageGallery-main {
margin-left: px2rem(14px);
margin-right: 0;
}
}

&-overlay {
background: rgba(7, 12, 20, .5);
}

&-embed {
display: inline-flex;
position: relative;
min-height: px2rem(370px);
width: px2rem(768px);
max-width: px2rem(768px);
width: auto;
padding: 0;

&-title {
min-height: px2rem(410px);
padding-top: px2rem(40px);
}

.#{$ns}ImageGallery-toptitle {
color: var(--dark);
}

.#{$ns}ImageGallery-main {
width: px2rem(546px);
height: unset;
flex: 0 0 px2rem(436px);
}

.#{$ns}ImageGallery-image {
height: calc(100% - #{px2rem(56px)});
}

.#{$ns}ImageGallery-info {
width: px2rem(208px);
background: var(--white);
Expand Down Expand Up @@ -70,6 +96,21 @@
}
}
}

&-pagination {


> ul {

li {
color: var(--dark);

svg {
color: var(--dark);
}
}
}
}
}
}

Expand Down Expand Up @@ -169,6 +210,23 @@
user-select: none;
position: relative;
overflow: hidden;

&-reverse {
flex-direction: column-reverse;

.#{$ns}ImageGallery-image {
height: calc(100% - #{px2rem(56px)});
margin: 0 0 px2rem(16px) 0;
}

.#{$ns}ImageGallery-image-bottom {
margin: 0;
}

.#{$ns}ImageGallery-toolbar {
margin: 0 0 px2rem(16px) 0;
}
}
}

&-image {
Expand Down
9 changes: 4 additions & 5 deletions packages/amis-ui/scss/components/_images.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
@use 'sass:math';

.#{$ns}Images {
display: flex;
flex-wrap: wrap;
display: grid;
grid-template-columns: repeat(auto-fill, 120px);
grid-row-gap: 8px;
grid-column-gap: 8px;
margin: calc(var(--gap-xs) * -1);

&-item {
display: flex;
margin: var(--image-images-item-marginTop)
var(--image-images-item-marginRight) var(--image-images-item-marginBottom)
var(--image-images-item-marginLeft);
}
}

Expand Down
53 changes: 41 additions & 12 deletions packages/amis-ui/src/components/ImageGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface ImageGalleryItem {

interface ImageGalleryPosition {
toolbar: 'top' | 'bottom';
list: 'top' | 'bottom';
description: 'left' | 'right';
}

export interface ImageGalleryProps
Expand Down Expand Up @@ -536,7 +536,8 @@ export class ImageGallery extends React.Component<
actions,
imageLoadInfo,
isNaturalSize,
imageLoading
imageLoading,
position
} = this.state;
const {translate: __, loadingConfig} = this.props;

Expand All @@ -559,8 +560,22 @@ export class ImageGallery extends React.Component<
~index && items[index] ? (
<>
<div className={cx('ImageGallery-main')} ref={this.galleryMainRef}>
<div className={cx('ImageGallery-preview')}>
<div className={cx('ImageGallery-image')}>
<div
className={cx(
'ImageGallery-preview',
position?.toolbar === 'top'
? 'ImageGallery-preview-reverse'
: ''
)}
>
<div
className={cx(
'ImageGallery-image',
enlargeWithGallary === false
? 'ImageGallery-image-bottom'
: ''
)}
>
<div className={cx('ImageGallery-image-wrap')}>
<img
draggable={false}
Expand Down Expand Up @@ -645,9 +660,21 @@ export class ImageGallery extends React.Component<
];
}

renderTitle() {
const {classnames: cx} = this.props;
const {items, index} = this.state;

return items[index]?.title && !items[index]?.caption ? (
<span className={cx('ImageGallery-toptitle')}>{items[index].title}</span>
) : null;
}

render() {
const {children, modalContainer, embed, classnames: cx} = this.props;
const {items, index, imageGallaryClassName, isOpened} = this.state;
const {items, index, imageGallaryClassName, isOpened, position} =
this.state;

const isTopTitle = items[index]?.title && !items[index]?.caption;

return (
<>
Expand All @@ -660,28 +687,30 @@ export class ImageGallery extends React.Component<
size="full"
onHide={this.close}
show={isOpened}
contentClassName={cx('ImageGallery', imageGallaryClassName)}
contentClassName={cx(
'ImageGallery',
imageGallaryClassName,
position?.description === 'left' ? 'ImageGallery-reverse' : ''
)}
modalMaskClassName={cx('ImageGallery-overlay')}
container={modalContainer}
>
<span className={cx('ImageGallery-close')} onClick={this.close}>
<Icon icon="close" className="icon" />
</span>
{items[index]?.title && !items[index]?.caption ? (
<span className={cx('ImageGallery-toptitle')}>
{items[index].title}
</span>
) : null}
{this.renderTitle()}
{this.renderBody()}
</Modal>
) : (
<div
className={cx(
'ImageGallery',
imageGallaryClassName,
'ImageGallery-embed'
'ImageGallery-embed',
isTopTitle ? 'ImageGallery-embed-title' : ''
)}
>
{this.renderTitle()}
{this.renderBody()}
</div>
)}
Expand Down
6 changes: 6 additions & 0 deletions packages/amis/src/renderers/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ export interface ImageSchema extends BaseSchema {
* 工具栏配置
*/
toolbarActions?: ImageToolbarAction[];

/** 位置 */
position?: {
toolbar: 'top' | 'bottom';
description: 'left' | 'right';
};
}

export interface ImageThumbProps
Expand Down
13 changes: 10 additions & 3 deletions packages/amis/src/renderers/Images.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ export interface ImagesSchema extends BaseSchema {
/** 位置 */
position?: {
toolbar: 'top' | 'bottom';
list: 'top' | 'bottom';
description: 'left' | 'right';
};

imageStyle?: React.CSSProperties;
}

export interface ImagesProps
Expand Down Expand Up @@ -218,7 +220,8 @@ export class ImagesField extends React.Component<ImagesProps> {
env,
themeCss,
embed,
position
position,
imageStyle
} = this.props;

let value: any;
Expand Down Expand Up @@ -280,6 +283,7 @@ export class ImagesField extends React.Component<ImagesProps> {
{list.map((item: any, index: number) => (
<Image
index={index}
style={imageStyle}
className={cx('Images-item')}
key={index}
src={item.src}
Expand All @@ -291,8 +295,11 @@ export class ImagesField extends React.Component<ImagesProps> {
enlargeAble={enlargeAble!}
enlargeWithGallary={enlargeWithGallary}
onEnlarge={this.handleEnlarge}
position={position}
showToolbar={showToolbar}
imageGallaryClassName={`${imageGallaryClassName} ${setThemeClassName(
imageGallaryClassName={`${
imageGallaryClassName ?? ''
} ${setThemeClassName(
'imageGallaryClassName',
id,
themeCss
Expand Down

0 comments on commit 09a4599

Please sign in to comment.