限制 视频圈 上传内容大小
This commit is contained in:
parent
67e728808d
commit
10c2f5c8ef
|
@ -42,7 +42,7 @@
|
|||
</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>
|
||||
<view class="text-center">
|
||||
|
@ -146,46 +146,95 @@
|
|||
that.videos.push(res.tempFilePath);
|
||||
for (let i = 0; i < that.videos.length; i++) {
|
||||
that.$queue.showLoading("上传中...");
|
||||
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();
|
||||
}
|
||||
uni.getFileInfo({
|
||||
filePath: that.videos[i],
|
||||
success: (infoRes) => {
|
||||
const size = infoRes.size;
|
||||
if (size / 1024 / 1024 > 10) {
|
||||
// 图片大于2MB
|
||||
uni.showToast({
|
||||
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
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
sourceType: ['album', 'camera'],
|
||||
success: res => {
|
||||
for (let i = 0; i < res.tempFilePaths.length; i++) {
|
||||
that.$queue.showLoading("上传中...");
|
||||
uni.uploadFile({ // 上传接口
|
||||
url: websocketUtils.uploadFileUrl(), //真实的接口地址
|
||||
filePath: res.tempFilePaths[i],
|
||||
name: 'file',
|
||||
success: (uploadFileRes) => {
|
||||
if (e == 1) {
|
||||
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();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
that.$queue.showLoading("上传中...");
|
||||
var tempFilePaths=res.tempFilePaths[0]
|
||||
that.checkImageSize(tempFilePaths, (isValid) => {
|
||||
if (isValid) {
|
||||
// 图片校验通过后的逻辑
|
||||
console.log('图片校验通过,可以上传');
|
||||
} else {
|
||||
console.log('图片超出大小限制,请重新选择');
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue