pt-share.js 5.9 KB

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