share.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // component/shar-dialog/shar-dialog.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. shareType: {
  8. type: 'String',
  9. value: ''
  10. }
  11. },
  12. /**
  13. * 组件的初始数据
  14. */
  15. data: {
  16. shareFlag: true,
  17. imgUrls: ''
  18. },
  19. /**
  20. * 组件的方法列表
  21. */
  22. methods: {
  23. poster: function () {
  24. const that = this;
  25. const ctx = wx.createCanvasContext('myCanvas');
  26. ctx.rect(0, 0, 370, 507)
  27. ctx.setFillStyle('#fff')
  28. ctx.fill()
  29. ctx.save()
  30. ctx.beginPath()
  31. ctx.setFillStyle('#fff')
  32. ctx.fill()
  33. ctx.arc(185, 48, 37, 0, 2 * Math.PI, false)
  34. ctx.clip();//画了圆 再剪切 原始画布中剪切任意形状和尺寸。一旦剪切了某个区域,则所有之后的绘图都会被限制在被剪切的区域内
  35. ctx.drawImage('../../../static/groupImg/Bitmap1.png', 148, 8, 100, 100); //插入图片
  36. ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 可以继续绘制
  37. ctx.setFontSize(20)
  38. ctx.setFillStyle('#000')
  39. ctx.fillText('喔喔', 166, 115)
  40. ctx.setFillStyle('#FF4400')
  41. ctx.fillText('郎朗读书声是世上最美的声音', 50, 138)
  42. ctx.drawImage('../../../static/groupImg/Bitmap1.png', 9, 156, 352, 145);
  43. ctx.setFontSize(18)
  44. ctx.setFillStyle('#000')
  45. ctx.fillText('一年级语文上学期', 12, 329)
  46. ctx.drawImage('../../../static/groupImg/Combined Shape.png', 11, 348, 196, 65);
  47. ctx.drawImage('../../../static/groupImg/Rectangle 41.png', 134, 358, 59, 20);
  48. ctx.setFontSize(14)
  49. ctx.setFillStyle('#fff')
  50. ctx.fillText('五人团', 149, 373)
  51. ctx.setFontSize(16)
  52. ctx.setFillStyle('#A95A00')
  53. ctx.fillText('原价', 24, 373)
  54. ctx.setStrokeStyle('red')
  55. ctx.moveTo(64, 368)
  56. ctx.lineTo(114, 368)
  57. ctx.stroke()
  58. ctx.fillText('¥99元', 64, 373)
  59. ctx.setFontSize(18)
  60. ctx.fillText('团购价仅需', 20, 403)
  61. ctx.fillText('元', 144, 403)
  62. ctx.setFontSize(20)
  63. ctx.setFillStyle('red')
  64. ctx.fillText('¥1', 109, 403)
  65. ctx.drawImage('../../../static/groupImg/share_bottom.png', 3, 419, 370, 192);
  66. ctx.setFontSize(20)
  67. ctx.setFillStyle('red')
  68. ctx.fillText('名额有限,售完截止', 9, 467)
  69. ctx.setFontSize(18)
  70. ctx.setFillStyle('#000')
  71. ctx.fillText('长按识别二维码参加团购', 9, 493)
  72. ctx.drawImage('../../../static/groupImg/code.png', 217, 374, 135, 135);
  73. ctx.draw(true, function (res) {
  74. wx.canvasToTempFilePath({
  75. x: 0,
  76. y: 0,
  77. width: 370,
  78. height: 507,
  79. destWidth: 370,
  80. destHeight: 507,
  81. canvasId: 'myCanvas',
  82. success:(res) => {
  83. console.log(res.tempFilePath)
  84. // wx.saveImageToPhotosAlbum({
  85. // filePath: res.path,
  86. // success(res) {
  87. // console.log(res);
  88. // }
  89. // })
  90. that.setData({
  91. imgUrls: res.tempFilePath
  92. })
  93. }
  94. })
  95. })
  96. },
  97. share: function () {
  98. this.setData({
  99. shareFlag: !this.data.shareFlag
  100. })
  101. },
  102. PreservationImg: function () {
  103. wx.saveImageToPhotosAlbum({
  104. filePath: this.data.imgUrls,
  105. success(res) {
  106. console.log('保存成功')
  107. }
  108. })
  109. },
  110. shareFriend: function () {
  111. this.triggerEvent('customevent', {})
  112. }
  113. }
  114. })