shareuser.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var downloadNumber=0;
  5. Page({
  6. data: {
  7. },
  8. onLoad: function (options) {
  9. this.setData({
  10. Containnerheight: main.getWindowHeight(),
  11. });
  12. this.init();
  13. downloadNumber=0;
  14. },
  15. init:function(){
  16. var that = this;
  17. main.getData('GetMiaoguoShareInfo?Version=' + app.globalData.Version, function (data) {
  18. wx.hideLoading();
  19. if (data) {
  20. that.setData({
  21. List: data,
  22. });
  23. }
  24. });
  25. },
  26. buildImage:function(){
  27. if (!app.globalData.userInfo) {
  28. app.globalData.userInfo = {};
  29. app.globalData.userInfo.UserID = 1;
  30. }
  31. var that=this;
  32. wx.showLoading({
  33. title: '请稍候',
  34. });
  35. var imageUrl = '../images/promotion_leaflet_a01.png';
  36. var imageQRCode = app.globalData.serverUrl;
  37. imageQRCode += common.Encrypt("BuildWXServiceQRCode?QRCodeType=0&UserID=" + app.globalData.userInfo.UserID + "&SourceID=" + app.globalData.ProgramID);
  38. var that = this;
  39. var downloadTask = wx.downloadFile({
  40. url: imageQRCode,
  41. success(res) {
  42. if (res.statusCode === 200) {
  43. var canvas = wx.createCanvasContext("shareCanvas", that);
  44. canvas.drawImage(imageUrl, 0, 0, 750, 1256);
  45. canvas.drawImage(res.tempFilePath, 550, 1068, 160, 160);
  46. canvas.fillStyle = "#1e1e1e";
  47. canvas.setFontSize(28);
  48. canvas.fillText("开班时间:2019-09-01", 50, 1212);
  49. canvas.draw(1, function (n) {
  50. wx.canvasToTempFilePath({
  51. x: 0,
  52. y: 0,
  53. width: 750,
  54. height: 1256,
  55. destWidth: 750,
  56. destHeight: 1256,
  57. canvasId: 'shareCanvas',
  58. success: function (res2) {
  59. console.log(res2.tempFilePath);
  60. wx.hideLoading();
  61. wx.previewImage({
  62. current: res2.tempFilePath, // 当前显示图片的http链接
  63. urls: [res2.tempFilePath] // 需要预览的图片http链接列表
  64. });
  65. },
  66. fail:function(err){
  67. wx.hideLoading();
  68. }
  69. })
  70. });
  71. }
  72. else{
  73. wx.hideLoading();
  74. }
  75. },
  76. fail: function (err) {
  77. wx.hideLoading();
  78. downloadNumber++;
  79. if (downloadNumber<3)
  80. that.buildImage();
  81. }
  82. });
  83. downloadTask.onProgressUpdate((res) => {
  84. console.log('下载进度', res.progress)
  85. console.log('已经下载的数据长度', res.totalBytesWritten)
  86. console.log('预期需要下载的数据总长度', res.totalBytesExpectedToWrite)
  87. })
  88. },
  89. onShareAppMessage: function () {
  90. return {
  91. title: app.globalData.ShareTitle,
  92. path: app.globalData.SharePath + '?Marketing=1&UserID=' + app.globalData.userInfo.UserID,
  93. imageUrl: "../../pages/images/program_screenshot_main.png",
  94. }
  95. },
  96. });