import { UploadOutlined } from "@ant-design/icons" import { Button, Input, Space } from "antd" import { useRef, useState } from "react" import uploadOss from "../_lib/upload" export default function ImageUpload(props: { accept: string width?: number height?: number value?: string background?: string hiddenCover?: boolean onChange?: (val: string) => void }) { const inputRef = useRef(null) const [loading, setLoading] = useState(false) const handleFile = async (file: File) => { setLoading(true) try { const url = await uploadOss(file, "aibot") setLoading(false) if (url) { props.onChange?.(url) } } catch { setLoading(false) } } return ( <> { !props?.hiddenCover &&
} { props.onChange?.(e.target.value) }}> { const file = e.target.files?.[0] e.target.value = "" if (!file) return handleFile(file) }} /> ) }