限制 视频圈 上传内容大小

This commit is contained in:
Mr.jiang 2024-08-14 15:49:15 +08:00
parent 67e728808d
commit 10c2f5c8ef
1 changed files with 80 additions and 31 deletions

View File

@ -42,7 +42,7 @@
</view> </view>
</view> </view>
</view> </view>
<view class="margin-top" @click="addImage(4)" v-if="form.headImg.length<=0"> <view class="margin-top" @click="addImage" v-if="form.headImg.length<=0">
<view class="flex justify-center align-center video-img"> <view class="flex justify-center align-center video-img">
<view> <view>
<view class="text-center"> <view class="text-center">
@ -146,46 +146,95 @@
that.videos.push(res.tempFilePath); that.videos.push(res.tempFilePath);
for (let i = 0; i < that.videos.length; i++) { for (let i = 0; i < that.videos.length; i++) {
that.$queue.showLoading("上传中..."); that.$queue.showLoading("上传中...");
uni.uploadFile({ // uni.getFileInfo({
url: websocketUtils.uploadFileUrl(), // filePath: that.videos[i],
filePath: that.videos[i], success: (infoRes) => {
name: 'file', const size = infoRes.size;
success: (uploadFileRes) => { if (size / 1024 / 1024 > 10) {
that.videosList = JSON.parse(uploadFileRes.data).data // 2MB
console.log("that.videosList",that.videosList) uni.showToast({
uni.hideLoading(); icon:'error',
} title:'视频超出10MB限制,请重新选择'
})
} else {
// 2MB
uni.uploadFile({ //
url: websocketUtils.uploadFileUrl(), //
filePath: that.videos[i],
name: 'file',
success: (uploadFileRes) => {
that.videosList = JSON.parse(uploadFileRes.data).data
console.log("that.videosList",that.videosList)
uni.hideLoading();
}
});
}
},
fail: () => {
console.log("上传是被")
// callback(false);
}
}); });
} }
} }
}) })
}, },
addImage(e) { //
checkImageSize(filePath, callback) {
let that = this
uni.getFileInfo({
filePath: filePath,
success: (infoRes) => {
const size = infoRes.size;
if (size / 1024 / 1024 > 2) {
// 2MB
uni.showToast({
icon:'error',
title:'图片超出2MB限制,请重新选择'
})
callback(false);
} else {
// 2MB
this.uploadImage(filePath)
callback(true);
}
},
fail: () => {
callback(false);
}
});
},
//
uploadImage(filePath) {
console.log("filePath",filePath)
let that = this
uni.uploadFile({ //
url: websocketUtils.uploadFileUrl(), //
filePath: filePath,
name: 'file',
success: (uploadFileRes) => {
that.form.headImg = JSON.parse(uploadFileRes.data).data
uni.hideLoading();
}
});
},
addImage() {
let that = this let that = this
uni.chooseImage({ uni.chooseImage({
count: 1, count: 1,
sourceType: ['album', 'camera'], sourceType: ['album', 'camera'],
success: res => { success: res => {
for (let i = 0; i < res.tempFilePaths.length; i++) { that.$queue.showLoading("上传中...");
that.$queue.showLoading("上传中..."); var tempFilePaths=res.tempFilePaths[0]
uni.uploadFile({ // that.checkImageSize(tempFilePaths, (isValid) => {
url: websocketUtils.uploadFileUrl(), // if (isValid) {
filePath: res.tempFilePaths[i], //
name: 'file', console.log('图片校验通过,可以上传');
success: (uploadFileRes) => { } else {
if (e == 1) { console.log('图片超出大小限制,请重新选择');
that.form.front = JSON.parse(uploadFileRes.data).data }
} else if (e == 2) { });
that.form.back = JSON.parse(uploadFileRes.data).data
} else if (e == 4) {
that.form.headImg = JSON.parse(uploadFileRes.data).data
console.log(that.form.headImg)
}
uni.hideLoading();
}
});
}
} }
}) })
}, },