Cmen
3 years ago
7 changed files with 138 additions and 18 deletions
@ -0,0 +1,43 @@
|
||||
import { CSSProperties } from "react"; |
||||
import { Upload } from "antd"; |
||||
import { IOverlay } from "@map"; |
||||
import { editorAction } from "@store"; |
||||
|
||||
export type OverlayBackgroundProps = { |
||||
overlay: IOverlay; |
||||
}; |
||||
|
||||
export const OverlayBackground = (props: OverlayBackgroundProps) => { |
||||
const { overlay } = props; |
||||
const { id, backgroundImage } = overlay; |
||||
|
||||
const beforeUpload = (file: File) => { |
||||
const reader = new FileReader(); |
||||
reader.onload = () => { |
||||
editorAction.updateOverlay({ |
||||
id, |
||||
backgroundImage: reader.result as string, |
||||
}); |
||||
}; |
||||
reader.readAsDataURL(file); |
||||
return false; |
||||
}; |
||||
|
||||
const style: CSSProperties = {}; |
||||
if (backgroundImage) { |
||||
style.backgroundImage = `url(${backgroundImage})`; |
||||
} |
||||
|
||||
return ( |
||||
<div style={style} className="overlay-background"> |
||||
<Upload |
||||
showUploadList={false} |
||||
className="overlay-background-upload" |
||||
accept="image/png, image/jpg" |
||||
beforeUpload={beforeUpload} |
||||
> |
||||
上传 |
||||
</Upload> |
||||
</div> |
||||
); |
||||
}; |
@ -1,3 +1,22 @@
|
||||
.property-area{ |
||||
padding: 8px; |
||||
} |
||||
.overlay-background{ |
||||
background-size: cover; |
||||
} |
||||
.overlay-background-upload{ |
||||
display: inline-block; |
||||
width: 100%; |
||||
height: 120px; |
||||
line-height: 120px; |
||||
text-align: center; |
||||
vertical-align: middle; |
||||
background-color: rgba(0, 0, 0, .2); |
||||
border: 1px dashed #d9d9d9; |
||||
border-radius: 2px; |
||||
cursor: pointer; |
||||
transition: border-color .3s; |
||||
} |
||||
.ant-form-item .ant-upload{ |
||||
color: #fff; |
||||
} |
Loading…
Reference in new issue