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C;;IAlHc,+BAAS,GAA0B,IAAI,qBAAqB,EAAE,CAAC;IAmHlF,4BAAC;KAAA;kBArHoB,qBAAqB","file":"","sourceRoot":"/","sourcesContent":["\nexport default class CCWechatScreenShotMgr {\n\n    private static _instance: CCWechatScreenShotMgr = new CCWechatScreenShotMgr();\n\n    public static getInstance (): CCWechatScreenShotMgr {\n        return CCWechatScreenShotMgr._instance;\n    }\n\n    /**\n     * \n     * @param worldPos 节点的世界坐标\n     * @param width 节点的宽度\n     * @param height 节点的高度\n     */\n    doShot (worldPos: cc.Vec2 | cc.Vec3, width: number, height: number, \n        successCallback: Function = () => {},\n        successCheckCallback: () => boolean = () => false ,\n        shareFailCallback: Function = () => {},\n        failCallback: Function = () => {},\n        completeCallback: Function = () => {}) {\n        if (cc.sys.platform === cc.sys.WECHAT_GAME) {\n            if (!wx.showShareImageMenu) {\n                console.log(\"截图失败\");\n                shareFailCallback();\n                return;\n            }\n            const ccCanvas = cc.find(\"Canvas\");\n            const xscale = (worldPos.x - width / 2) / ccCanvas.width;\n            const yscale = 1 - (worldPos.y + height / 2) / ccCanvas.height;\n            let x = canvas.width * xscale;\n            let y = canvas.height * yscale;\n            const w = width / ccCanvas.width * canvas.width;\n            const h = height / ccCanvas.height * canvas.height;\n            let data = {\n                x: x,\n                y: y,\n                width: w,\n                height: h,\n                destWidth: w,\n                destHeight: h,\n                fileType: 'png',\n                quality: 1,\n                success: (res) => {\n                    if (successCheckCallback() === false) {\n                        console.log(\"截图界面被关闭\");\n                        return;\n                    }\n                    console.log(\"截图成功\");\n                    console.log(\"res: \", res);\n                    console.log(\"res.tempFilePath: \", res.tempFilePath);\n                    wx.showShareImageMenu({\n                        path: res.tempFilePath\n                    })\n                    //     //分享卡片\n                    //     wx.shareAppMessage({\n                    //         imageUrl: res.tempFilePath\n                    //    })\n                    successCallback();\n                },\n                fail: (e) => {\n                    console.log(\"截图失败\");\n                    console.log(e);\n                    failCallback();\n                },\n                complete: () => {\n                    console.log(\"截图完成\");\n                    completeCallback();\n                }\n            }\n            let _tempFilePath = canvas.toTempFilePath(data);\n            cc.log(`Capture file success!${_tempFilePath}`);\n        }\n    }\n\n    shotFullScreen (\n        successCallback: Function = () => {},\n        successCheckCallback: () => boolean = () => false ,\n        shareFailCallback: Function = () => {},\n        failCallback: Function = () => {},\n        completeCallback: Function = () => {}) {\n\n        if (cc.sys.platform === cc.sys.WECHAT_GAME) {\n            //canvas 是微信的,报错不用管\n            //单纯的分享一张图\n            if (!wx.showShareImageMenu) {\n                console.log(\"截图失败\");\n                shareFailCallback();\n                return;\n            }\n            canvas.toTempFilePath({\n                success: (res) => {\n                    if (successCheckCallback() === false) {\n                        console.log(\"截图界面被关闭\");\n                        return;\n                    }\n                    console.log(\"截图成功\");\n                    wx.showShareImageMenu({\n                        path: res.tempFilePath\n                    })\n                    //     //分享卡片\n                    //     wx.shareAppMessage({\n                    //         imageUrl: res.tempFilePath\n                    //    })\n                    successCallback();\n                },\n                fail: (e) => {\n                    console.log(\"截图失败\");\n                    console.log(e);\n                    failCallback();\n                },\n                complete: () => {\n                    console.log(\"截图完成\");\n                    completeCallback();\n                }\n            })\n        }\n    }\n}\n"]}