shareuser.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var downloadNumber = 0;
  5. var shareUrl = "";
  6. Page({
  7. data: {
  8. Containnerheight:0,
  9. ServerImage:"",
  10. },
  11. onLoad: function (options) {
  12. var that=this;
  13. that.setData({
  14. Containnerheight: main.getWindowHeight(),
  15. ServerImage: app.globalData.uploadImageUrl + "web/"
  16. });
  17. that.init();
  18. downloadNumber = 0;
  19. shareUrl = "WebExtend?UserID=" + app.globalData.userInfo.UserID;
  20. shareUrl = app.globalData.serverUrl + common.Encrypt(shareUrl);
  21. },
  22. init: function () {
  23. var that = this;
  24. main.getData('GetMiaoguoShareInfo220?Version=' + app.globalData.Version, function (data) {
  25. wx.hideLoading();
  26. if (data) {
  27. that.setData({
  28. List: data,
  29. });
  30. }
  31. });
  32. main.getData("GetClassList?Flag=0", function (data) {
  33. if (data && data.length > 0) {
  34. that.setData({
  35. StartDate: common.formatDateCHS(data[0].StartDate),
  36. })
  37. }
  38. });
  39. },
  40. buildImage: function (e) {
  41. var that = this;
  42. if (!app.globalData.userInfo) {
  43. app.globalData.userInfo = {};
  44. app.globalData.userInfo.UserID = 1;
  45. }
  46. wx.showLoading({
  47. title: '请稍候',
  48. });
  49. var id = e.currentTarget.dataset.id;
  50. var imageUrl = '../../pages_agent/images/promotion_poster0' + id + '.png';
  51. var timeout = 100;
  52. //如果没有生成过二维码,则生成
  53. if (!app.globalData.userInfo.HasACode) {
  54. var imageQRCode = "BuildMiaoguoQRCode?IsWeb=1&UserID=" + app.globalData.userInfo.UserID;
  55. console.log(imageQRCode);
  56. main.getData(imageQRCode, function (data) {});
  57. timeout = 5000;
  58. app.globalData.userInfo.HasACode=1;
  59. }
  60. var idStr=common.Encrypt(app.globalData.userInfo.UserID);
  61. idStr=idStr.replace("/","___");
  62. idStr=idStr.replace("+","___");
  63. var downloadUrl = app.globalData.uploadImageUrl + "MiaoguoUser" + idStr + ".png";
  64. setTimeout(function () {
  65. var downloadTask = wx.downloadFile({
  66. url: downloadUrl,
  67. success(res) {
  68. if (res.statusCode === 200) {
  69. var downloadTask2 = wx.downloadFile({
  70. url: app.globalData.userInfo.AvatarUrl,
  71. success(res2) {
  72. if (res2.statusCode === 200) {
  73. var canvas = wx.createCanvasContext("shareCanvas", that);
  74. canvas.drawImage(imageUrl, 0, 0, 750, 1110);
  75. canvas.drawImage(res2.tempFilePath, 30, 995, 70, 70);
  76. canvas.drawImage("../../pages/images/promotion_face_circle.png", 30, 995, 70, 70);
  77. canvas.drawImage(res.tempFilePath, 600, 970, 120, 120);
  78. canvas.draw(1, function (n) {
  79. wx.canvasToTempFilePath({
  80. x: 0,
  81. y: 0,
  82. width: 750,
  83. height: 1110,
  84. destWidth: 750,
  85. destHeight: 1110,
  86. canvasId: 'shareCanvas',
  87. success: function (res2) {
  88. console.log(res2.tempFilePath);
  89. wx.hideLoading();
  90. wx.previewImage({
  91. current: res2.tempFilePath, // 当前显示图片的http链接
  92. urls: [res2.tempFilePath] // 需要预览的图片http链接列表
  93. });
  94. },
  95. fail: function (err) {
  96. wx.hideLoading();
  97. }
  98. })
  99. });
  100. }
  101. }
  102. });
  103. }
  104. else if (res.statusCode === 404){
  105. console.log("图片404");
  106. wx.hideLoading();
  107. } else {
  108. wx.hideLoading();
  109. }
  110. },
  111. fail: function (err) {
  112. console.log("err:" + err);
  113. wx.hideLoading();
  114. downloadNumber++;
  115. if (downloadNumber < 3)
  116. that.buildImage();
  117. }
  118. });
  119. downloadTask.onProgressUpdate((res) => {
  120. console.log('下载进度', res.progress)
  121. console.log('已经下载的数据长度', res.totalBytesWritten)
  122. console.log('预期需要下载的数据总长度', res.totalBytesExpectedToWrite)
  123. })
  124. }, timeout);
  125. },
  126. gotoShareIndex:function(){
  127. wx.navigateTo({
  128. url: "../../pages/share/shareindex",
  129. });
  130. },
  131. buildUrl: function () {
  132. wx.setClipboardData({
  133. data: shareUrl,
  134. success(res) {
  135. wx.showToast({
  136. title: '已复制',
  137. });
  138. }
  139. });
  140. },
  141. buildText: function () {
  142. var text = "我家孩子在用「秒过」小程序做复习。它可以解决错别字、背古诗、记单词,还能牢记词语、成语、公式、定理、史地政等一切基础知识,都可以用它来练习。详情体验:" + shareUrl;
  143. wx.setClipboardData({
  144. data: text,
  145. success(res) {
  146. wx.showToast({
  147. title: '已复制',
  148. });
  149. }
  150. });
  151. },
  152. onShareAppMessage: function () {
  153. return {
  154. title: app.globalData.ShareTitle,
  155. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  156. imageUrl: "../../pages/images/program_screenshot_main.png",
  157. }
  158. }
  159. });