pt-share.js 5.4 KB

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