- 发布:2022-08-18 21:29
- 更新:2022-08-19 09:55
- 阅读:341
产品分类: uniapp/App
PC开发环境操作系统: Mac
PC开发环境操作系统版本号: macOS 12.5.1
HBuilderX类型: 正式
HBuilderX版本号: 3.5.3
手机系统: 全部
手机厂商: 华为
页面类型: vue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
测试过的手机:
示例代码:
//上传图片
async chooseFile() {
let that = this;
uni.chooseImage({
count: that.maxCount - that.imageList.length, //图片大于1可以多选,这样可以不超出最大上传值
sourceType: ['camera'],
sizeType: ['original'],
success: res => {
uni.showLoading({
title: '正在上传'
});
res.tempFilePaths.forEach(item => {
that.uploadFile(item);
});
},
fail: err => {
that.$emit('uploadFail', err);
},
complete: () => {}
});
},
//图片数据上传后端
uploadFile(path) {
let that = this;
uni.uploadFile({
url: `${that.$config.uploadUrl}`,
filePath: path,
formData: that.formData,
header: {
'X-Access-Token': that.$store.getters.token
},
name: 'file',
success: res => {
let data = JSON.parse(res.data);
if (data.success) {
that['value'].push(data.message);
that.$emit('list', that.value); //通知父组件有图片更新
} else {
uni.showToast({
icon: 'none',
title: data.message
});
}
},
fail: err => {
that.$emit('uploadFail', err);
},
complete: () => {
uni.hideLoading();
}
});
},
//删除图片
delectImg(i) {
let that = this;
uni.showModal({
title: '提示',
content: '确定要删除照片吗?',
cancelText: '取消',
confirmText: '确定',
success: res => {
if (res.confirm) {
that.imageList.splice(i, 1);
that.$emit('input', this.imageList);
that.$emit('list', that.imageList); //通知父组件删除了数据
}
}
});
},
//点击预览图片
doPreviewImage(current) {
let that = this;
uni.previewImage({
current,
urls: that.imageList, //存放图片的数组
loop: true,
indicator: 'default'
});
}
//上传图片
async chooseFile() {
let that = this;
uni.chooseImage({
count: that.maxCount - that.imageList.length, //图片大于1可以多选,这样可以不超出最大上传值
sourceType: ['camera'],
sizeType: ['original'],
success: res => {
uni.showLoading({
title: '正在上传'
});
res.tempFilePaths.forEach(item => {
that.uploadFile(item);
});
},
fail: err => {
that.$emit('uploadFail', err);
},
complete: () => {}
});
},
//图片数据上传后端
uploadFile(path) {
let that = this;
uni.uploadFile({
url: `${that.$config.uploadUrl}`,
filePath: path,
formData: that.formData,
header: {
'X-Access-Token': that.$store.getters.token
},
name: 'file',
success: res => {
let data = JSON.parse(res.data);
if (data.success) {
that['value'].push(data.message);
that.$emit('list', that.value); //通知父组件有图片更新
} else {
uni.showToast({
icon: 'none',
title: data.message
});
}
},
fail: err => {
that.$emit('uploadFail', err);
},
complete: () => {
uni.hideLoading();
}
});
},
//删除图片
delectImg(i) {
let that = this;
uni.showModal({
title: '提示',
content: '确定要删除照片吗?',
cancelText: '取消',
confirmText: '确定',
success: res => {
if (res.confirm) {
that.imageList.splice(i, 1);
that.$emit('input', this.imageList);
that.$emit('list', that.imageList); //通知父组件删除了数据
}
}
});
},
//点击预览图片
doPreviewImage(current) {
let that = this;
uni.previewImage({
current,
urls: that.imageList, //存放图片的数组
loop: true,
indicator: 'default'
});
}
操作步骤:
部分机型拍照选择的时候,出现app闪退,跳回到app主页。
部分机型拍照选择的时候,出现app闪退,跳回到app主页。
预期结果:
无
无
实际结果:
无
无
bug描述:
我这个拍照上传文件服务的功能,小米 pro12拍照之后会闪退,不知道是什么原因??