mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-11 03:24:16 +00:00
fix upload behavior
This commit is contained in:
parent
617ae389fa
commit
02c0c0353f
@ -6,19 +6,24 @@ import "./index.less"
|
|||||||
|
|
||||||
export default (props) => {
|
export default (props) => {
|
||||||
const [value, setValue] = React.useState(props.ctx.currentValue)
|
const [value, setValue] = React.useState(props.ctx.currentValue)
|
||||||
|
const [uploading, setUploading] = React.useState(false)
|
||||||
|
|
||||||
const uploadImage = async (req) => {
|
const uploadImage = async (req) => {
|
||||||
|
setUploading(true)
|
||||||
|
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
|
|
||||||
formData.append("files", req.file)
|
formData.append("files", req.file)
|
||||||
|
|
||||||
const request = await window.app.api.withEndpoints("main").post.upload(formData, undefined).catch((error) => {
|
const request = await window.app.api.withEndpoints("main").post.upload(formData, undefined).catch((error) => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
antd.message.error(error)
|
app.message.error(error)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
setUploading(false)
|
||||||
|
|
||||||
if (request) {
|
if (request) {
|
||||||
setValue(request.files[0].url)
|
setValue(request.files[0].url)
|
||||||
props.ctx.dispatchUpdate(request.files[0].url)
|
props.ctx.dispatchUpdate(request.files[0].url)
|
||||||
@ -57,6 +62,7 @@ export default (props) => {
|
|||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
icon={<Icons.Upload />}
|
icon={<Icons.Upload />}
|
||||||
|
loading={uploading}
|
||||||
>
|
>
|
||||||
Upload
|
Upload
|
||||||
</Button>
|
</Button>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user