index.ts 4.6 KB

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