收藏
回答

canvas draw()不能用了? 之前都是好好的 你们干了什么

async savePageAsImage() {
                let text = "正在生成支付码";
                uni.showLoading({
                    mask:true,
                    title: text,
                });
                let _this = this;
                let qr = new UQRCode();
                // 设置二维码内容
                        // qr是第三方的依赖,用于生成二维码内容
                qr.data = "https://uijfm.shushiyunqiao.com/#/?store_id=" + this.dataInfo.id;
                qr.size = 300;
                qr.make();
// 从这里就不生效了 报错信息也没有 想不通 你们这般人在干嘛  现在只能打开调试的时候才能往下进行
                qr.canvasContext = uni.createCanvasContext('playqrcode', this);
                qr.drawCanvas().then(()=>{
                    uni.canvasToTempFilePath({
                        canvasId: 'playqrcode',
                        success: (rqTempFile) => {
                            text="二维码生成成功了"
                            let rqPath = rqTempFile.tempFilePath;
                            alert(rqPath);
                            uni.downloadFile({
                                url: "https://qny.shushiyunqiao.com/uploads/20250309/9aba52dc4ce9ece0c81a06c43697fd78.png",
                                success: function (bgRes) {
                                    text="背景图片生成成功了"
                                    let bgPathValue = bgRes.tempFilePath;
                                    wx.createSelectorQuery().select("#inviteCanvas").fields({ node: true, size: true }).exec((canvasObj) => {
                                        text="获得了cnaves"
                                        let canvas = canvasObj[0].node;
                                        let ctx = canvas.getContext('2d')
                                        let bgImage = canvas.createImage();
                                        let rqImage = canvas.createImage();
                                        bgImage.onload = ()=>{
                                            ctx.drawImage(bgImage,0, 0, 740, 1087);
                                        }
                                        rqImage.onload = ()=>{
                                            setTimeout(()=>{
                                                ctx.drawImage(rqImage,220, 393.5, 300, 300);
                                            },500);
                                        }
                                        bgImage.src = bgPathValue;
                                        rqImage.src = rqPath;
                                        // Canvas 画布的实际绘制宽高
                                        let width = canvasObj[0].width
                                        let height = canvasObj[0].height
                                        // 初始化画布大小
                                        let dpr = wx.getWindowInfo().pixelRatio
                                        canvas.width = width * dpr
                                        canvas.height = height * dpr
                                        ctx.scale(dpr, dpr)
                                        text="组合完了 开始保存"
                                        setTimeout(()=>{
                                            // 生成图片
                                            wx.canvasToTempFilePath({
                                                canvasId: 'inviteCanvas',
                                                canvas,
                                                success: res => {
                                                    // 生成的图片临时文件路径
                                                    let createTempFilePath = res.tempFilePath;
                                                    uni.showModal({
                                                        title: "生成的图片",
                                                        content: createTempFilePath
                                                    });
                                                    // wx.saveImageToPhotosAlbum({
                                                    //     filePath: createTempFilePath,
                                                    //     success: function (res) {
                                                    //         uni.hideLoading();
                                                    //         _this.$toast("保存成功","success");
                                                    //     },
                                                    //     fail: function (res) {
                                                    //         uni.hideLoading();
                                                    //         _this.$toast("保存失败","none");
                                                    //     }
                                                    // });
                                                },
                                                fail: erro =>{
                                                    uni.showModal({
                                                        title: "失败",
                                                        content: '12331'
                                                    });
                                                }
                                            })
                                        },2700);
                                    });
                                },
                            });
                        },
                        fail: (err) => {
                            uni.hideLoading();
                            _this.$toast('生成失败',"none");
                        }
                    }, _this);
                }).catch(()=>{
                    uni.hideLoading();
                    _this.$toast('生成失败',"none");
                });
            },
            
回答关注问题邀请回答
收藏
登录 后发表内容