index.ts 4.5 KB

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