pt-share.js 6.7 KB

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