图片上传样式修复

This commit is contained in:
liaoxuezhi 2020-01-08 22:31:26 +08:00
parent 5a63c6752d
commit 719d497c32
2 changed files with 45 additions and 13 deletions

View File

@ -15,8 +15,7 @@
border: $borderWidth solid $borderColor; border: $borderWidth solid $borderColor;
cursor: pointer; cursor: pointer;
@include button-variant( @include button-variant($ImageControl-addBtn-bg,
$ImageControl-addBtn-bg,
$ImageControl-addBtn-border, $ImageControl-addBtn-border,
$ImageControl-addBtn-color, $ImageControl-addBtn-color,
$ImageControl-addBtn-onHover-bg, $ImageControl-addBtn-onHover-bg,
@ -24,10 +23,9 @@
$ImageControl-addBtn-onHover-color, $ImageControl-addBtn-onHover-color,
$ImageControl-addBtn-onActive-bg, $ImageControl-addBtn-onActive-bg,
$ImageControl-addBtn-onActive-border, $ImageControl-addBtn-onActive-border,
$ImageControl-addBtn-onActive-color $ImageControl-addBtn-onActive-color);
);
> svg { >svg {
width: px2rem(50px); width: px2rem(50px);
height: px2rem(50px); height: px2rem(50px);
top: 0; top: 0;
@ -75,6 +73,7 @@
margin-right: $gap-base; margin-right: $gap-base;
margin-bottom: $gap-base; margin-bottom: $gap-base;
position: relative; position: relative;
width: px2rem(120px);
} }
&-image { &-image {
@ -100,13 +99,13 @@
flex-wrap: wrap; flex-wrap: wrap;
color: #fff; color: #fff;
> div { >div {
width: 100%; width: 100%;
text-align: center; text-align: center;
margin-bottom: 5px; margin-bottom: 5px;
} }
> a { >a {
cursor: pointer; cursor: pointer;
color: #fff; color: #fff;
display: inline-block; display: inline-block;
@ -129,7 +128,7 @@
right: 5px; right: 5px;
line-height: 1; line-height: 1;
> svg { >svg {
top: 0; top: 0;
width: 10px; width: 10px;
height: 10px; height: 10px;
@ -145,7 +144,7 @@
align-content: center; align-content: center;
flex-wrap: wrap; flex-wrap: wrap;
> p { >p {
width: 100%; width: 100%;
text-align: center; text-align: center;
font-size: 12px; font-size: 12px;
@ -192,7 +191,7 @@
text-decoration: none; text-decoration: none;
} }
> p { >p {
width: 100%; width: 100%;
text-align: center; text-align: center;
color: $danger; color: $danger;
@ -227,7 +226,7 @@
flex-direction: column; flex-direction: column;
align-items: flex-end; align-items: flex-end;
> a { >a {
color: #fff; color: #fff;
padding: 2px 5px; padding: 2px 5px;
cursor: pointer; cursor: pointer;
@ -250,4 +249,4 @@
line-height: 120px; line-height: 120px;
text-align: center; text-align: center;
} }
} }

View File

@ -14,7 +14,7 @@ import Button from '../../components/Button';
// @ts-ignore // @ts-ignore
import accepts from 'attr-accept'; import accepts from 'attr-accept';
import {getNameFromUrl} from './File'; import {getNameFromUrl} from './File';
import ImageComponent from '../Image'; import ImageComponent, {ImageThumbProps} from '../Image';
let preventEvent = (e: any) => e.stopPropagation(); let preventEvent = (e: any) => e.stopPropagation();
@ -47,6 +47,14 @@ export interface ImageProps extends FormControlProps {
multiple?: boolean; multiple?: boolean;
thumbMode?: 'w-full' | 'h-full' | 'contain' | 'cover'; thumbMode?: 'w-full' | 'h-full' | 'contain' | 'cover';
thumbRatio?: '1:1' | '4:3' | '16:9'; thumbRatio?: '1:1' | '4:3' | '16:9';
onImageEnlarge?: (
info: Pick<ImageThumbProps, 'src' | 'originalSrc' | 'title' | 'caption'> & {
index?: number;
list?: Array<
Pick<ImageThumbProps, 'src' | 'originalSrc' | 'title' | 'caption'>
>;
}
) => void;
} }
export interface ImageState { export interface ImageState {
@ -458,6 +466,26 @@ export default class ImageControl extends React.Component<
); );
} }
previewImage(file: FileX, index: number, e: React.MouseEvent<any>) {
const {onImageEnlarge} = this.props;
if (onImageEnlarge) {
const files = this.files;
e.preventDefault();
onImageEnlarge({
src: (file.preview || file.url) as string,
originalSrc: (file.preview || file.url) as string,
index,
list: files.map(file => ({
src: (file.preview || file.url) as string,
originalSrc: (file.preview || file.url) as string,
title: file.name || getNameFromUrl(file.value || file.url)
}))
});
}
}
editImage(index: number) { editImage(index: number) {
const {multiple} = this.props; const {multiple} = this.props;
@ -1035,6 +1063,11 @@ export default class ImageControl extends React.Component<
data-position="bottom" data-position="bottom"
target="_blank" target="_blank"
href={file.url || file.preview} href={file.url || file.preview}
onClick={this.previewImage.bind(
this,
file,
key
)}
> >
<Icon icon="view" className="icon" /> <Icon icon="view" className="icon" />
</a> </a>