import { doFetch } from "@/utils/doFetch"; import { LoadingOutlined } from "@ant-design/icons"; import IconFont from "@/components/IconFont"; import { message, Upload } from "antd"; import ImgCrop from "antd-img-crop"; import { useState } from "react"; import "./index.less"; const beforeUpload = (file) => { const isJpgOrPng = file.type === "image/jpeg" || file.type === "image/png" || file.type === "image/jpg" || file.type === "image/svg" || file.type === "image/gif"; if (!isJpgOrPng) { message.error("仅可以上传 JPG/PNG/GIF/JPEG/SVG file!"); } const isLt2M = file.size / 1024 / 1024 < 2; if (!isLt2M) { message.error("图片必须小于 2MB!"); } return isJpgOrPng && isLt2M; }; const Head = ({ defaultImg, dofetchUserInfo }) => { const [loading, setLoading] = useState(false); const [imageUrl, setImageUrl] = useState(defaultImg); let token = localStorage.getItem("TOKENES"); const handleChange = async (info) => { if (info.file.status === "uploading") { setLoading(true); return; } if (info.file.status === "done") { const { response } = info.file; const data = response?.data?.dataList ?? {}; // 更新用户信息接口 // let res = await doFetch({ // url: "/user/updateHeadPortrait", // params: { // pic: data, // }, // }); if (res.code === "0000") { setLoading(false); setImageUrl(data[0]?.url); await dofetchUserInfo(); } } }; const uploadButton = (
仅可以上传 JPG/PNG/GIF/JPEG/SVG 格式的文件!
图片必须小于 2MB!