移动端V1.0
This commit is contained in:
30
utils/checkPic.js
Normal file
30
utils/checkPic.js
Normal file
@@ -0,0 +1,30 @@
|
||||
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);
|
||||
}
|
Reference in New Issue
Block a user