// pages/downloadPage/index.ts const app = getApp(); let apiPay = false;// 是否调用支付成功 let t: any = undefined; Page({ /** * 页面的初始数据 */ data: { videoSrc: "", assetsSrc: "", paragraphName: "马拉松简介", showImage: true }, autoplay() { if (!this.data.showImage) return; this.setData({ showImage: false, }) }, toDownload() { if (t) t = clearTimeout(t); t = setTimeout(() => { app.getUser({ data: {}, success: (res: any) => { if (!res.RESULT) return wx.showToast({ "title": "视频正在生成中,请耐心等待", icon: "none", duration: 2000 }) res.PAY ? this.downloadVideo() : this.toPAY(); }, }) }, 200); }, downloadVideo() { wx.showLoading({ title: "" }) app.getUser({ data: {}, success: (rule: any) => { if (!rule.PAY) return if (t) t = clearTimeout(t); t = setTimeout(() => { app.getVideo({ success: (r: any) => { wx.downloadFile({ url: r.url, success: (res) => { this.setData({ videoSrc: r.url }) wx.saveVideoToPhotosAlbum({ filePath: res.tempFilePath, success: () => { wx.hideLoading(); wx.showToast({ title: "保存成功", icon: "none", duration: 2000 }) }, fail: () => { wx.hideLoading(); }, complete: () => { apiPay = false; } }) }, fail: () => { wx.hideLoading(); }, complete: () => { } }) }, fail: () => { wx.hideLoading(); } }) }, 200); }, fail: () => { wx.hideLoading(); } }) }, toPAY() { app.createOrder({ success: (res: any) => { wx.requestPayment({ timeStamp: res.timeStamp, nonceStr: res.nonceStr, package: res.package, paySign: res.paySign, signType: res.signType, success() { apiPay = true; }, failL: () => { wx.showToast({ icon: "none", title: "支付调用失败", duration: 2000 }) apiPay = false; } }) } }) }, inited(res: any) { app.getUser({ data: {}, success: (rule: any) => { if (!rule.SAVE_USER_INFO || !rule.UPLOAD_FACE) { wx.reLaunch({ url: "/pages/home/index" }) return } if (!rule.PAY || !rule.RESULT) { this.setData({ videoSrc: res.videoSrc || "", assetsSrc: res.assetsSrc || "", paragraph: res.paragraph || [], paragraphName: res.paragraphName }) return; } app.getVideo({ success: (r: any) => { this.setData({ videoSrc: r.url, paragraph: res.paragraph || [], paragraphName: res.paragraphName }) } }) }, }) }, /** * 生命周期函数--监听页面加载 */ onLoad() { wx.hideHomeButton({}); if (!app.globalData.configPage) app.getPageInfo({ success: (res: any) => { app.globalData.configPage = res || {}; this.inited(app.globalData.configPage); } }) else this.inited(app.globalData.configPage); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { // 如果支付成功则下载视频 if (apiPay) this.downloadVideo(); }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } }) export { }