123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- // pages/downloadPage/index.ts
- const app = getApp<IAppOption>();
- 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
- })
- console.log('btn')
- res.PAY ? this.downloadVideo() : this.toPAY();
- },
- })
- }, 1000);
- },
- downloadVideo() {
- wx.showLoading({
- title: ""
- })
- app.getUser({
- noloading: true,
- 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() {
- // 如果支付成功则下载视频
- console.log('show')
- if (apiPay) this.downloadVideo();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
- export { }
|