import { useMessage } from '/@/hooks/web/useMessage';

const { createMessage } = useMessage();

export const useUpload = () => {
  //验证图片类型和大小
  const beforeUploadVerify = ({ type, size }) => {
    const isJpgOrPng = type === 'image/jpeg' || type === 'image/png';
    if (!isJpgOrPng) {
      createMessage.error('只能上传图片文件!');
    }
    const limitImgSize = (size as number) / 1024 / 1024 < 5;
    if (!limitImgSize) {
      createMessage.error('图片大小不能超过5MB!');
    }
    return isJpgOrPng && limitImgSize;
  };
  return {
    beforeUploadVerify,
  };
};
