share.js 3.4 KB

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