d***@yunfanda.com
d***@yunfanda.com
  • 发布:2020-09-07 16:23
  • 更新:2020-09-28 10:37
  • 阅读:726

【报Bug】Android system webview 会导致 uni.canvasToTempFilePath报错!

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10

HBuilderX类型: Alpha

HBuilderX版本号: 2.8.11

手机系统: Android

手机系统版本号: Android 10

手机厂商: 三星

手机机型: 三星note10+ pro

页面类型: vue

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

confirm(event) {
uni.showLoading({
title: '裁剪中...',
})
const _this = this
const ctx = uni.createCanvasContext('myCanvas', _this);
const pixelRatio = _this.pixelRatio
const imgage = _this.src
const imgW = _this.imageWidth _this.scale;
const imgH = _this.imageHeight
_this.scale
const rotate = _this.rotate
let dx = _this.cropOffsertX - _this.x - (_this.imageWidth - imgW) / 2;
let dy = _this.cropOffsertY - _this.y - (_this.imageHeight - imgH) / 2;

            ctx.setFillStyle('white')  
            ctx.fillRect(0, 0, imgW, imgH)  
            ctx.save()  

            ctx.rotate((rotate * 90 * Math.PI) / 180);  
            switch (rotate) {  
                case 1:  
                    dx += (imgH - imgW) / 2  
                    dy -= (imgH - imgW) / 2  
                    ctx.drawImage(imgage, -dy, dx, imgW, -imgH);  
                    break;  
                case 2:  
                    ctx.drawImage(imgage, dx, dy, -imgW, -imgH);  
                    break;  
                case 3:  
                    dx += (imgH - imgW) / 2  
                    dy -= (imgH - imgW) / 2  
                    ctx.drawImage(imgage, dy, -dx, -imgW, imgH);  
                    break;  
                default:  
                    ctx.drawImage(imgage, -dx, -dy, imgW, imgH);  
                    break;  
            }  
            ctx.restore()  
            ctx.draw(false, () => {  
                uni.canvasToTempFilePath({  
                    canvasId: 'myCanvas',  
                    destWidth: _this.cropW * pixelRatio,  
                    destHeight: _this.cropH * pixelRatio,  
                    success: (res) => {  
                        uni.hideLoading()  
                        event.detail.tempFilePath = res.tempFilePath  
                        // _this.show = false  
                        _this.$emit('confirm', event)  
                    },  
                    fail: (e) => {  
                        uni.hideLoading()  
                        uni.showModal({  
                            title: '提示',  
                            content: '裁剪失败'  
                        })  
                    },complete: () => {  
                        console.log('无回调')  
                    }  
                }, _this);  
            })  

        },

操作步骤:

Android system webview 某些版本 会导致 TypeError: Cannot read property 'data' of undefined at view.umd.min.js:1

预期结果:

uni.canvasToTempFilePath 正常使用.

实际结果:

uni.canvasToTempFilePath 在Android system webview 某些版本会报错.

bug描述:

Android system webview 84.0.4147.125版本
会导致 uni.canvasToTempFilePath报错 TypeError: Cannot read property 'data' of undefined at view.umd.min.js:1,
使用图片生成不能使用.
根据 https://ask.dcloud.net.cn/question/103303 的解答 删除之后会好使,但是上线后总不能让出错了用户都这样操作吧,希望官方能解决.

2020-09-07 16:23 负责人:无 分享
已邀请:
DCloud_UNI_GSQ

DCloud_UNI_GSQ

收到,应该是部分API兼容问题
能否提供一个简单的示例工程(可以复现问题的,尤其是使用了图片的情况,图片地址请无忽略),我方模拟你的环境排查一下

DCloud_UNI_GSQ

DCloud_UNI_GSQ

新版webview内核有更严格的跨域限制

HBuilderX alpha 2.9.0+ 已修复

其他版本临时解决方案,本地路径使用插件(比如 https://ext.dcloud.net.cn/plugin?id=123)转换成base64

该问题目前已经被锁定, 无法添加新回复