限制 视频圈 上传内容大小
This commit is contained in:
parent
67e728808d
commit
10c2f5c8ef
|
@ -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();
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue