index.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // pages/downloadPage/index.ts
  2. const app = getApp<IAppOption>();
  3. let apiPay = false;// 是否调用支付成功
  4. let t: any = undefined;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. videoSrc: "",
  11. assetsSrc: "",
  12. paragraphName: "马拉松简介",
  13. showImage: true
  14. },
  15. autoplay() {
  16. if (!this.data.showImage) return;
  17. this.setData({
  18. showImage: false,
  19. })
  20. },
  21. toDownload() {
  22. if (t) t = clearTimeout(t);
  23. t = setTimeout(() => {
  24. app.getUser({
  25. data: {},
  26. success: (res: any) => {
  27. if (!res.RESULT) return wx.showToast({
  28. "title": "视频正在生成中,请耐心等待",
  29. icon: "none",
  30. duration: 2000
  31. })
  32. res.PAY ? this.downloadVideo() : this.toPAY();
  33. },
  34. })
  35. }, 200);
  36. },
  37. downloadVideo() {
  38. app.getUser({
  39. data: {},
  40. success: (rule: any) => {
  41. if(!rule.PAY) return
  42. if (t) t = clearTimeout(t);
  43. t = setTimeout(() => {
  44. wx.showLoading({
  45. title: ""
  46. })
  47. app.getVideo({
  48. success: (r: any) => {
  49. wx.downloadFile({
  50. url: r.url,
  51. success: (res) => {
  52. wx.showLoading({
  53. title: ""
  54. })
  55. this.setData({
  56. videoSrc: r.url
  57. })
  58. wx.saveVideoToPhotosAlbum({
  59. filePath: res.tempFilePath,
  60. success: () => {
  61. wx.hideLoading();
  62. wx.showToast({
  63. title: "保存成功",
  64. icon: "none",
  65. duration: 2000
  66. })
  67. },
  68. fail: () => {
  69. wx.hideLoading();
  70. },
  71. complete: () => {
  72. apiPay = false;
  73. }
  74. })
  75. },
  76. fail: () => {
  77. wx.hideLoading();
  78. },
  79. complete: () => { }
  80. })
  81. },
  82. })
  83. }, 200);
  84. }
  85. })
  86. },
  87. toPAY() {
  88. app.createOrder({
  89. success: (res: any) => {
  90. wx.requestPayment({
  91. timeStamp: res.timeStamp,
  92. nonceStr: res.nonceStr,
  93. package: res.package,
  94. paySign: res.paySign,
  95. signType: res.signType,
  96. success() {
  97. apiPay = true;
  98. },
  99. failL: () => {
  100. wx.showToast({
  101. icon: "none",
  102. title: "支付调用失败",
  103. duration: 2000
  104. })
  105. apiPay = false;
  106. }
  107. })
  108. }
  109. })
  110. },
  111. inited(res: any) {
  112. app.getUser({
  113. data: {},
  114. success: (rule: any) => {
  115. if (!rule.SAVE_USER_INFO || !rule.UPLOAD_FACE) {
  116. wx.reLaunch({
  117. url: "/pages/home/index"
  118. })
  119. return
  120. }
  121. if (!rule.PAY || !rule.RESULT) {
  122. this.setData({
  123. videoSrc: res.videoSrc || "",
  124. assetsSrc: res.assetsSrc || "",
  125. paragraph: res.paragraph || [],
  126. paragraphName: res.paragraphName
  127. })
  128. return;
  129. }
  130. app.getVideo({
  131. success: (r: any) => {
  132. console.log(r);
  133. this.setData({
  134. videoSrc: r.url,
  135. paragraph: res.paragraph || [],
  136. paragraphName: res.paragraphName
  137. })
  138. }
  139. })
  140. },
  141. })
  142. },
  143. /**
  144. * 生命周期函数--监听页面加载
  145. */
  146. onLoad() {
  147. wx.hideHomeButton({});
  148. if (!app.globalData.configPage) app.getPageInfo({
  149. success: (res: any) => {
  150. app.globalData.configPage = res || {};
  151. this.inited(app.globalData.configPage);
  152. }
  153. })
  154. else this.inited(app.globalData.configPage);
  155. },
  156. /**
  157. * 生命周期函数--监听页面初次渲染完成
  158. */
  159. onReady() {
  160. },
  161. /**
  162. * 生命周期函数--监听页面显示
  163. */
  164. onShow() {
  165. // 如果支付成功则下载视频
  166. if (apiPay) this.downloadVideo();
  167. },
  168. /**
  169. * 生命周期函数--监听页面隐藏
  170. */
  171. onHide() {
  172. },
  173. /**
  174. * 生命周期函数--监听页面卸载
  175. */
  176. onUnload() {
  177. },
  178. /**
  179. * 页面相关事件处理函数--监听用户下拉动作
  180. */
  181. onPullDownRefresh() {
  182. },
  183. /**
  184. * 页面上拉触底事件的处理函数
  185. */
  186. onReachBottom() {
  187. },
  188. /**
  189. * 用户点击右上角分享
  190. */
  191. onShareAppMessage() {
  192. }
  193. })
  194. export { }