1***@qq.com
1***@qq.com
  • 发布:2023-07-11 14:56
  • 更新:2024-07-11 14:09
  • 阅读:232

app端 uni.canvasToTempFilePath不执行,小程序可以正常执行

分类:uni-app

uni.canvasToTempFilePath({
canvasId: 'canvas',
fileType:'jpg',
success: res => {
var tempFilePath = res.tempFilePath;
console.log(111111,res.tempFilePath)
uni.saveImageToPhotosAlbum({
filePath: tempFilePath,
success: res => {
uni.hideLoading();
this.form.shareResult.is_success = true;;
this.shareresult(this.form);

                            let data = {  
                                mId: uni.getStorageSync('mId'),  
                                uId: uni.getStorageSync('uid'),  
                                commonId: this.tabact.packageId,  
                                shareChannel: 2,  
                                type: this.type,  
                                lId:this.lId,  
                                posterUrl:this.posterUrl,  
                                // 3、会员卡 4、储值卡套餐  
                                productName: this.tabact.cardName,  
                                appletUrl: this.type == 3 ?'otherPages/member/index':'otherPages/member/cardDetail'  
                            }  
                            this.$api.adduserShareLog(data).then(res => {})  

                            uni.showToast({  
                                title: "保存成功,请到相册中查看",  
                                duration: 1500,  
                                icon: "none",  
                            });  
                        },  
                        fail: res => {  
                            uni.hideLoading();  
                            uni.showToast({  
                                title: "保存失败,请稍后再试",  
                                duration: 1500,  
                                icon: "none",  
                            });  
                        },  
                    });  
                },  
                complete(res){  
                    console.log(res)  
                },  
                fail: function(res) {  
                    console.log(res)  
                },  
            })
2023-07-11 14:56 负责人:无 分享
已邀请:
爱豆豆

爱豆豆 - 办法总比困难多

不清楚你的逻辑 但是你可以试试下面这段代码(app端正常导出) 对比一下找出你的bug

<template>  
    <view class="test-canvas">  
        <canvas style="width: 300px; height: 200px;" canvas-id="myCanvas" ></canvas>  
        <button @tap="getCanvasToTempFilePath">导出</button>  
    </view>  
</template>  
<script>  
    export default {  
        methods: {  
            getCanvasToTempFilePath() {  
                uni.canvasToTempFilePath({  
                    x: 100,  
                    y: 200,  
                    width: 50,  
                    height: 50,  
                    destWidth: 100,  
                    destHeight: 100,  
                    canvasId: 'myCanvas',  
                    success: (res) => {  
                        console.log(res.tempFilePath,"res--------------");  
                    },  
                    fail: (err) => {  
                        console.log('fail', err);  
                    },  
                    complete: () => {  
                        console.log('complete');  
                    }  
                });  
            }  
        },  
        mounted() {  

        }  
    }  
</script>
  • 1***@qq.com (作者)

    大佬,canvasToTempFilePath这个方法回调不执行success、fail、complete都不执行

    2024-07-11 13:40

  • 爱豆豆

    回复 1***@qq.com: 你这回复 刚好时隔一年整 哈哈哈

    2024-07-11 13:48

  • 爱豆豆

    回复 1***@qq.com: 不会是你手机的问题吧?你用其他机型试试 你测试用的什么手机?

    2024-07-11 13:49

Diligent_UI

Diligent_UI - 【插件开发】【专治疑难杂症】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=193663(微信搜索飘逸科技UI小程序直接体验)】【骗子请绕道】问题咨询请加QQ群:120594820,代表作灵感实用工具小程序

检查代码有没有问题

1***@qq.com

1***@qq.com (作者)

//组件内
<canvas :class="className" :canvas-id="canvasId" :width="higtCanvasSize" :height="higtCanvasSize" :style="{
width: higtCanvasSize + 'px',
height: higtCanvasSize + 'px'
}" />
//props接收
canvasId: {
type: String,
default: 'almostLottery'
},

const ctx = uni.createCanvasContext(canvasId, this)

// 保存绘图并导出图片
ctx.draw(true, (() => {
let drawTimer = setTimeout(() => {
clearTimeout(drawTimer)
drawTimer = null
console.log(this.canvasId)
// #ifndef MP-ALIPAY
uni.canvasToTempFilePath({ //不执行```javascript


                            canvasId: this.canvasId,  
                            destWidth: this.higtCanvasSize,  
                            destHeight: this.higtCanvasSize,  
                            success: (res) => {  
                                // 在 H5 平台下,tempFilePath 为 base64  
                                console.log(res.tempFilePath)  
                                this.handlePrizeImg({  
                                    ok: true,  
                                    data: res.tempFilePath,  
                                    msg: '画布导出生成图片成功'  
                                })  
                            },  
                            fail: (err) => {  
                                this.handlePrizeImg({  
                                    ok: false,  
                                    data: err,  
                                    msg: '画布导出生成图片失败'  
                                })  
                            }  
                        }, this)  
                        // #endif  
                    }, 500)  
                })())
7***@qq.com

7***@qq.com

https://ask.dcloud.net.cn/question/192496 确实有这个问题

要回复问题请先登录注册