参考: https://blog.csdn.net/jyn15159/article/details/108833869
或 参考: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept
自己项目里面:
const onChange = (info) => {
// if (info.file.status !== 'uploading') {
// console.log(info.file, info.fileList);
// }
if (info.file.status === 'done') {
message.success(`${info.file.response.message}` || `${info.file.name}文件导入成功`);
} else if (info.file.status === 'error') {
message.error(`${info.file.name}文件导入失败`);
}
};
// const beforeUpload = (file) => {
// const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
// if (!isJpgOrPng) {
// message.error('只能上传Excle文件');
// }
// const isLt2M = file.size / 1024 / 1024 < 2;
// if (!isLt2M) {
// message.error('Image must smaller than 2MB!');
// }
// return isJpgOrPng && isLt2M;
// };
const [prop] = useState({
name: 'file',
showUploadList: false,
// beforeUpload: beforeUpload,
onChange: onChange,
action: `/api/hotel/lock/room_code/import?hotel_group_id=${JSON.parse(sessionStorage.getItem('currentUser')).hotel_group_id}&hotel_id=${JSON.parse(sessionStorage.getItem('currentUser')).hotel_id}&modify_user=${JSON.parse(sessionStorage.getItem('currentUser')).id}`,
headers: {
authorization: 'authorization-text',
},
accept: "application/vnd.ms-excel" || "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
});
