shareuser.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. main.getData("GetClassList?Flag=0", function (data) {
  26. if (data && data.length > 0) {
  27. that.setData({
  28. StartDate: common.formatDateCHS(data[0].StartDate),
  29. })
  30. }
  31. });
  32. },
  33. buildImage:function(){
  34. if (!app.globalData.userInfo) {
  35. app.globalData.userInfo = {};
  36. app.globalData.userInfo.UserID = 1;
  37. }
  38. var that=this;
  39. wx.showLoading({
  40. title: '请稍候',
  41. });
  42. var imageUrl = '../images/promotion_leaflet_a01.png';
  43. var imageQRCode = app.globalData.serverUrl;
  44. imageQRCode += common.Encrypt("BuildWXServiceQRCode?QRCodeType=0&UserID=" + app.globalData.userInfo.UserID + "&SourceID=" + app.globalData.ProgramID);
  45. console.log(imageQRCode);
  46. var that = this;
  47. var downloadTask = wx.downloadFile({
  48. url: imageQRCode,
  49. success(res) {
  50. if (res.statusCode === 200) {
  51. var canvas = wx.createCanvasContext("shareCanvas", that);
  52. canvas.drawImage(imageUrl, 0, 0, 750, 1256);
  53. canvas.drawImage(res.tempFilePath, 550, 1068, 160, 160);
  54. canvas.fillStyle = "#1e1e1e";
  55. canvas.setFontSize(28);
  56. canvas.fillText("开班时间:"+that.data.StartDate, 50, 1212);
  57. canvas.draw(1, function (n) {
  58. wx.canvasToTempFilePath({
  59. x: 0,
  60. y: 0,
  61. width: 750,
  62. height: 1256,
  63. destWidth: 750,
  64. destHeight: 1256,
  65. canvasId: 'shareCanvas',
  66. success: function (res2) {
  67. console.log(res2.tempFilePath);
  68. wx.hideLoading();
  69. wx.previewImage({
  70. current: res2.tempFilePath, // 当前显示图片的http链接
  71. urls: [res2.tempFilePath] // 需要预览的图片http链接列表
  72. });
  73. },
  74. fail:function(err){
  75. wx.hideLoading();
  76. }
  77. })
  78. });
  79. }
  80. else{
  81. wx.hideLoading();
  82. }
  83. },
  84. fail: function (err) {
  85. console.log("err:"+err);
  86. wx.hideLoading();
  87. downloadNumber++;
  88. if (downloadNumber<3)
  89. that.buildImage();
  90. }
  91. });
  92. downloadTask.onProgressUpdate((res) => {
  93. console.log('下载进度', res.progress)
  94. console.log('已经下载的数据长度', res.totalBytesWritten)
  95. console.log('预期需要下载的数据总长度', res.totalBytesExpectedToWrite)
  96. })
  97. },
  98. onShareAppMessage: function () {
  99. return {
  100. title: app.globalData.ShareTitle,
  101. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  102. imageUrl: "../../pages/images/program_screenshot_main.png",
  103. }
  104. },
  105. });