index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. Component({
  2. properties: {},
  3. data: {
  4. state: false,
  5. img: ''
  6. },
  7. methods: {
  8. open() {
  9. this.setData({
  10. state: true
  11. })
  12. },
  13. closeMediaBox() {
  14. this.setData({
  15. state: false
  16. })
  17. },
  18. savePoster() {
  19. const query = wx.createSelectorQuery().in(this);
  20. let canvas
  21. query
  22. .select('#cavansId')
  23. .fields({
  24. node: true,
  25. size: true
  26. }).exec(async (res) => {
  27. canvas = res[0].node;
  28. const ctx = canvas.getContext('2d');
  29. const dpr = wx.getSystemInfoSync().pixelRatio;
  30. canvas.width = 646;
  31. canvas.height = 959;
  32. let pic = canvas.createImage();
  33. pic.src = 'https://reader-wx.ai160.com/images/reader/pay/shareBg.jpg'
  34. pic.onload = () => {
  35. ctx.drawImage(pic, 0, 0, 646, 959);
  36. let pl = canvas.createImage();
  37. pl.src = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQEs8TwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyZzR0ZTE2T2M5N1UxYURaYU5CY1QAAgSHoQplAwQgHAAA'
  38. pl.onload = async () => {
  39. ctx.drawImage(pl, 29, 756, 170, 170)
  40. let {
  41. tempFilePath
  42. } = await wx.canvasToTempFilePath({
  43. canvas
  44. })
  45. wx.saveImageToPhotosAlbum({
  46. filePath: tempFilePath,
  47. success() {
  48. wx.showToast({
  49. title: '保存成功',
  50. icon: 'none'
  51. })
  52. }
  53. })
  54. }
  55. }
  56. })
  57. }
  58. }
  59. })