index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import { imgServerUrl } from '../../config/config.js'
  2. import { showToast } from '../../utils/tips.js'
  3. import Poster from '../../components/wxa-plugin-canvas/poster/poster'
  4. import { shareQrCodeA } from '../../services/index.js'
  5. import { updataStorageData } from '../../utils/storage.js'
  6. var app = getApp()
  7. Page({
  8. data: {
  9. imgServerUrl: imgServerUrl,
  10. qrCode:'',
  11. hasAuth:'',
  12. posterConfig: {
  13. width: 750,
  14. height: 1200,
  15. backgroundColor: '#1d449a',
  16. debug: false,
  17. blocks: [
  18. {
  19. x: 0,
  20. y: 330,
  21. width: 750,
  22. height: 8,
  23. backgroundColor: '#3f6dd3',
  24. zIndex: 2,
  25. },
  26. {
  27. x: 15,
  28. y: 370,
  29. width: 720,
  30. height: 800,
  31. backgroundColor: '#fffcf7',
  32. borderRadius: 10,
  33. paddingLeft: 50,
  34. paddingRight: 50,
  35. zIndex: 2,
  36. },
  37. {
  38. x: 207,
  39. y: 825,
  40. width: 338,
  41. height: 175,
  42. borderColor: '#1d449a',
  43. borderWidth: 1,
  44. zIndex: 4,
  45. }
  46. ],
  47. texts: [
  48. // {
  49. // x: 220,
  50. // y: 240,
  51. // baseLine: 'middle',
  52. // text: '每邀请1位新用户注册',
  53. // fontSize: 33,
  54. // color: '#ffffff',
  55. // lineHeight: 40,
  56. // zIndex: 2,
  57. // },
  58. // {
  59. // x: 220,
  60. // y: 290,
  61. // baseLine: 'middle',
  62. // text: '即可得5元现金红包',
  63. // fontSize: 33,
  64. // lineHeight: 40,
  65. // color: '#ffffff',
  66. // zIndex: 4,
  67. // },
  68. {
  69. x: 230,
  70. y: 880,
  71. baseLine: 'middle',
  72. text: '我在【开心工作】',
  73. fontSize: 18,
  74. lineHeight: 40,
  75. color: '#2a2a2a',
  76. zIndex: 4,
  77. },
  78. {
  79. x: 230,
  80. y: 912,
  81. baseLine: 'middle',
  82. text: '赚了5块钱',
  83. fontSize: 18,
  84. lineHeight: 40,
  85. color: '#2a2a2a',
  86. zIndex: 4,
  87. },
  88. {
  89. x: 230,
  90. y: 940,
  91. baseLine: 'middle',
  92. text: '扫码分享给你',
  93. fontSize: 18,
  94. lineHeight: 40,
  95. color: '#2a2a2a',
  96. zIndex: 4,
  97. },
  98. ],
  99. images: [
  100. {
  101. width: 750,
  102. height: 325,
  103. x: 0,
  104. y: 0,
  105. url: `${imgServerUrl}/images/recommend/awardBg.png`,
  106. zIndex: 1,
  107. },
  108. // {
  109. // width: 750,
  110. // height: 330,
  111. // x: 0,
  112. // y: 0,
  113. // url: `${imgServerUrl}/images/recommend/tuijian-bg.png`,
  114. // zIndex: 1,
  115. // },
  116. // {
  117. // x: 80,
  118. // y: 30,
  119. // width: 593,
  120. // height: 172,
  121. // url: `${imgServerUrl}/images/recommend/title.png`,
  122. // zIndex: 2,
  123. // },
  124. {
  125. x: 65,
  126. y: 400,
  127. width: 623,
  128. height: 372,
  129. url: `${imgServerUrl}/images/recommend/step.png`,
  130. zIndex: 4,
  131. },
  132. {
  133. x: 374,
  134. y: 835,
  135. width: 155,
  136. height: 155,
  137. url: '',
  138. zIndex: 4,
  139. }
  140. ],
  141. }
  142. },
  143. onLoad: function (options) {
  144. this.getCode()
  145. },
  146. onShow(){
  147. this.setData({
  148. hasAuth:true
  149. })
  150. },
  151. getCode(){
  152. let targetUrl = 'pages/recommend-iphone/index?shareToken=' + updataStorageData('shareToken')
  153. shareQrCodeA(targetUrl).then(data=>{
  154. this.setData({
  155. qrCode:data.data.imgUrl
  156. })
  157. })
  158. },
  159. onPosterSuccess(e) {
  160. const { detail } = e;
  161. var that = this
  162. wx.saveImageToPhotosAlbum({
  163. filePath: detail,
  164. success(res) {
  165. wx.hideLoading();
  166. showToast('已保存到相册!','success',3000)
  167. },
  168. fail(err){
  169. wx.hideLoading();
  170. showToast('请授权保存到相册')
  171. that.setData({
  172. hasAuth: false
  173. })
  174. }
  175. })
  176. },
  177. onPosterFail(err) {
  178. console.error(err);
  179. },
  180. /**
  181. * 异步生成海报
  182. */
  183. onCreatePoster() {
  184. // `/images/recommend/qrcode.jpg`
  185. wx.showLoading({ title: 'loading', mask: true });
  186. this.data.posterConfig.images[this.data.posterConfig.images.length - 1].url = this.data.qrCode
  187. this.setData({
  188. posterConfig:this.data.posterConfig
  189. }, () => {
  190. Poster.create();
  191. });
  192. },
  193. onError(err) {
  194. app.aldstat.sendEvent('报错',{
  195. 'err': err
  196. });
  197. },
  198. })