pt-share.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. import {
  2. imgServerUrl
  3. } from '../../config/config.js'
  4. import {
  5. showToast
  6. } from '../../utils/tips.js'
  7. import Poster from '../../components/wxa-plugin-canvas/poster/poster';
  8. import {
  9. shareQrCodeB,
  10. getGroupDetail
  11. } from '../../services/index.js'
  12. import {
  13. updataStorageData
  14. } from '../../utils/storage.js'
  15. var app = getApp()
  16. Page({
  17. data: {
  18. hasShare:true,
  19. imgServerUrl: imgServerUrl,
  20. qrCode: '',
  21. hasAuth: true,
  22. posterConfig: '',
  23. userInfo: '',
  24. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  25. },
  26. onLoad: function(options) {
  27. this.setData({
  28. hpPositionGroupId: options.hpPositionGroupId,
  29. positionCategory: options.positionCategory,
  30. positionId: options.positionId
  31. })
  32. },
  33. onShow: function() {
  34. if (app.globalData.userInfo) {
  35. console.log('有info===', app.globalData)
  36. this.setData({
  37. userInfo: app.globalData.userInfo
  38. })
  39. this.start()
  40. }
  41. this.setData({
  42. hasAuth: true
  43. })
  44. },
  45. start() {
  46. Promise.all([this.fetchData()]).then(data => {
  47. let posterConfig = {
  48. width: 700,
  49. height: 950,
  50. debug: false,
  51. texts: [{
  52. x: 54,
  53. y: 260,
  54. baseLine: 'middle',
  55. text: this.data.userInfo.nickName,
  56. fontSize: 38,
  57. color: '#ffffff',
  58. lineHeight: 30,
  59. zIndex: 2,
  60. },
  61. {
  62. x: 54,
  63. y: 316,
  64. baseLine: 'middle',
  65. text: '“我在找好友一起上班!”',
  66. fontSize: 26,
  67. color: '#ffffff',
  68. zIndex: 2,
  69. },
  70. {
  71. x: 350,
  72. y: 446,
  73. baseLine: 'middle',
  74. textAlign: "center",
  75. width: 700,
  76. text: this.data.postitionDetail.position.positionName,
  77. fontSize: 38,
  78. color: '#ffffff',
  79. lineHeight: 38,
  80. zIndex: 2
  81. },
  82. {
  83. x: 350,
  84. y: 494,
  85. baseLine: 'middle',
  86. textAlign: "center",
  87. width: 700,
  88. text: this.data.postitionDetail.position.hpCompany.companyName,
  89. fontSize: 20,
  90. color: '#ffffff',
  91. zIndex: 2,
  92. },
  93. {
  94. x: 350,
  95. y: 542,
  96. baseLine: 'middle',
  97. textAlign: "center",
  98. width: 700,
  99. text: this.data.postitionDetail.position.totalSalary ? this.data.postitionDetail.position.totalSalary : this.data.postitionDetail.position.basicSalary,
  100. fontSize: 50,
  101. color: '#ffffff',
  102. zIndex: 2,
  103. },
  104. {
  105. x: 62,
  106. y: 828,
  107. baseLine: 'middle',
  108. text: '专属客服,全程服务',
  109. fontSize: 20,
  110. color: '#ffffff',
  111. zIndex: 2,
  112. },
  113. {
  114. x: 464,
  115. y: 786,
  116. baseLine: 'middle',
  117. text: '识别右侧二维码,',
  118. fontSize: 20,
  119. color: '#ffffff',
  120. zIndex: 2,
  121. },
  122. {
  123. x: 464,
  124. y: 812,
  125. baseLine: 'middle',
  126. text: '即可参与我发起的拼工!',
  127. fontSize: 20,
  128. color: '#ffffff',
  129. zIndex: 2,
  130. }
  131. ],
  132. images: [{
  133. width: 700,
  134. height: 950,
  135. x: 0,
  136. y: 0,
  137. url: '/images/happyjob/bg.png',
  138. zIndex: 1,
  139. },
  140. {
  141. width: 218,
  142. height: 218,
  143. x: 400,
  144. y: 160,
  145. url: app.globalData.userInfo.avatarUrl,
  146. borderRadius: 222,
  147. zIndex: 2,
  148. borderWidth: 12,
  149. borderColor: '#fff',
  150. },
  151. {
  152. width: 196,
  153. height: 40,
  154. x: 50,
  155. y: 772,
  156. url: '/images/happyjob/logo.png',
  157. zIndex: 2,
  158. },
  159. {
  160. width: 180,
  161. height: 180,
  162. x: 270,
  163. y: 700,
  164. url: this.data.qrcode, //二维码
  165. zIndex: 2,
  166. borderRadius: 6,
  167. borderWidth: 14,
  168. borderColor: '#fff',
  169. },
  170. ],
  171. }
  172. console.log("sd", posterConfig)
  173. this.setData({
  174. posterConfig
  175. })
  176. })
  177. },
  178. //获取历史记录
  179. fetchData() {
  180. wx.showLoading({
  181. title: 'loading',
  182. mask: true
  183. });
  184. var that = this
  185. return new Promise(function(resolve, reject) {
  186. try {
  187. var value = wx.getStorageSync('groupDetail')
  188. if (value) {
  189. // Do something with return value
  190. wx.hideLoading()
  191. that.setData({
  192. postitionDetail: value,
  193. qrcode: value.qrcodeUrl,
  194. })
  195. resolve(true)
  196. }
  197. } catch (e) {
  198. // Do something when catch error
  199. console.log(data)
  200. wx.hideLoading()
  201. reject(data)
  202. }
  203. })
  204. },
  205. onPosterSuccess(e) {
  206. console.log("dddf", e)
  207. var detail = e.detail;
  208. console.log("df", detail)
  209. var that = this
  210. wx.saveImageToPhotosAlbum({
  211. filePath: detail,
  212. success(res) {
  213. console.log(res)
  214. wx.hideLoading();
  215. showToast('已保存到相册,快去分享吧!')
  216. },
  217. fail(err) {
  218. wx.hideLoading();
  219. showToast('请授权保存到相册')
  220. that.setData({
  221. hasAuth: false
  222. })
  223. }
  224. })
  225. wx.hideLoading()
  226. },
  227. onPosterFail(err) {
  228. wx.hideLoading()
  229. console.error(err);
  230. },
  231. /**
  232. * 异步生成海报
  233. */
  234. onCreatePoster() {
  235. Poster.create();
  236. },
  237. qrcodeLoad(e) {
  238. wx.hideLoading()
  239. },
  240. onShareAppMessage: function() {
  241. return {
  242. title: '开心工作参团有奖',
  243. path: '/pages/pt-detail/index?gd=' + this.data.hpPositionGroupId + '&pc=' + this.data.positionCategory + '&pd=' + this.data.positionId,
  244. imageUrl: ''
  245. }
  246. },
  247. onError(err) {
  248. app.aldstat.sendEvent('报错', {
  249. 'err': err
  250. });
  251. },
  252. })