uni-app中uni.chooseVideo取消后没有回调
uni-app中uni.chooseVideo取消后没有回调
类别 | 信息 |
---|---|
产品分类 | uniapp/H5 |
操作系统 | Windows |
操作系统版本 | win10 |
开发工具 | HBuilderX |
工具版本 | 3.1.4 |
浏览器 | Chrome |
示例代码:
// 上传视频
uploading_video() {
let that = this;
let time = new Date().toISOString().slice(0, 10).replace(/-/g, "");
uni.showLoading({
title: '上传中'
});
uni.chooseVideo({
count: 1,
sourceType: ['album'],
success: function(res) {
let video_src = res.tempFilePath;
console.log(video_src)
uni.uploadFile({
url: that.$Url + '/v1/Agencyplatform/uploadVideo',
fileType: 'video',
header: {
'tokens': uni.getStorageSync('TOKENS'),
},
filePath: video_src,
name: 'file',
success: (uploadFileRes) => {
let unpData = JSON.parse(uploadFileRes.data)
that.$pop(unpData.msg)
if (unpData.code == 200) {
// that.video_name = unpData.data
// that.video_arr.push(unpData.data)
// console.log(that.video_arr)
}
uni.hideLoading();
},
fail: () => {
that.$pop("上传失败" + video_src);
uni.hideLoading();
}
});
},
});
}
操作步骤:
目前的问题:如果点击取消 就会一直有Loading动画 监听不到取消事件
预期结果:
点击取消后 执行uni.hideLoading();
实际结果:
如果点击取消 就会一直有Loading动画 监听不到取消事件
更多关于uni-app中uni.chooseVideo取消后没有回调的实战教程也可以访问 https://www.itying.com/category-93-b0.html
2 回复
H5 不支持,浏览器未提供相关回调
可以通过自行监听触摸等事件隐藏 loading
更多关于uni-app中uni.chooseVideo取消后没有回调的实战教程也可以访问 https://www.itying.com/category-93-b0.html
在uni-app中,uni.chooseVideo
API确实没有提供专门的取消回调函数。当用户取消选择视频时,success
回调不会触发,但也没有对应的fail
或cancel
回调可用。
解决这个问题的最佳实践是使用setTimeout
设置一个超时机制,在合理的时间后自动隐藏loading。根据实际测试,一般可以将超时时间设置为5-8秒:
uploading_video() {
let that = this;
let time = new Date().toISOString().slice(0, 10).replace(/-/g, "");
uni.showLoading({
title: '上传中'
});
// 设置超时隐藏loading
const loadingTimer = setTimeout(() => {
uni.hideLoading();
}, 5000);
uni.chooseVideo({
count: 1,
sourceType: ['album'],
success: function(res) {
clearTimeout(loadingTimer); // 成功选择时清除定时器
let video_src = res.tempFilePath;
console.log(video_src)
uni.uploadFile({
url: that.$Url + '/v1/Agencyplatform/uploadVideo',
fileType: 'video',
header: {
'tokens': uni.getStorageSync('TOKENS'),
},
filePath: video_src,
name: 'file',
success: (uploadFileRes) => {
let unpData = JSON.parse(uploadFileRes.data)
that.$pop(unpData.msg)
if (unpData.code == 200) {
// 成功处理
}
uni.hideLoading();
},
fail: () => {
that.$pop("上传失败" + video_src);
uni.hideLoading();
}
});
},
});
}