share.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. const app = getApp();
  4. var imageIndex = 0;
  5. var arrBuildImageSource = [];
  6. var arrBuildImageTarget = [];
  7. Page({
  8. data: {
  9. },
  10. onLoad: function (options) {
  11. this.setData({
  12. Height: common.getSystemHeight(),
  13. });
  14. },
  15. onUnload: function () {
  16. wx.setStorageSync("IsShare", true);
  17. },
  18. buildShareImage: function () {
  19. imageIndex = 0;
  20. arrBuildImageSource = [];
  21. for (var i = 2; i < 6; i++)
  22. arrBuildImageSource.push("../../images/programsystem_screenshot_pic0" + i + ".png");
  23. arrBuildImageTarget = [];
  24. this.buildImage();
  25. },
  26. buildImage: function () {
  27. var that = this;
  28. var ctx = wx.createCanvasContext("MyCanvas", this);
  29. ctx.drawImage(arrBuildImageSource[imageIndex], 0, 0, 400, 300);
  30. var avatar = wx.getStorageSync("Avatar");
  31. if (avatar) {
  32. ctx.drawImage(avatar, 15, 250, 40, 40);
  33. ctx.drawImage("../../images/universalpic_mask_face_size01.png", 13, 248, 44, 44);
  34. ctx.fillStyle = "#ffffff";
  35. ctx.setFontSize(14);
  36. ctx.fillText(app.globalData.userInfo.NickName, 65, 264);
  37. }
  38. ctx.draw(true, function (n) {
  39. wx.canvasToTempFilePath({
  40. x: 0,
  41. y: 0,
  42. width: 400,
  43. height: 300,
  44. canvasId: 'MyCanvas',
  45. success: function (res2) {
  46. console.log(res2.tempFilePath);
  47. arrBuildImageTarget.push(res2.tempFilePath);
  48. if (arrBuildImageTarget.length < arrBuildImageSource.length) {
  49. imageIndex++;
  50. that.buildImage();
  51. }
  52. else {
  53. wx.previewImage({
  54. current: arrBuildImageTarget[0], // 当前显示图片的http链接
  55. urls: arrBuildImageTarget // 需要预览的图片http链接列表
  56. });
  57. }
  58. }
  59. })
  60. });
  61. },
  62. onShareAppMessage: function () {
  63. return {
  64. title: app.globalData.ShareTitle,
  65. path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
  66. imageUrl: app.globalData.ShareImageUrl,
  67. }
  68. },
  69. });