pt-share.js 6.6 KB

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