Files
zhxg_app_v1.0/utils/checkPic.js

30 lines
843 B
JavaScript
Raw Normal View History

2025-07-16 15:34:34 +08:00
export function checkPic(file) {
return new Promise((resolve, reject) => {
// 获取图片的后缀名
const suffix = file.name.split('.').pop().toLowerCase();
const allowedTypes = ['jpg', 'png', 'jpeg'];
const maxSize = 5242880; // 5MB in bytes
// 判断后缀是否符合要求
if (!allowedTypes.includes(suffix)) {
uni.showToast({
title: "不支持" + suffix + "格式的图片",
icon: "none"
});
resolve(false);
} else if (file.size > maxSize) {
uni.showToast({
title: "最大只能上传5MB的图片",
icon: "none"
});
resolve(false);
} else {
resolve(true);
}
});
}
export function isImageUrl(url) {
const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
const extension = url.split('.').pop().toLowerCase();
return imageExtensions.includes(extension);
}