index.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import {
  2. createWxCode
  3. } from '~/api/global'
  4. Component({
  5. properties: {},
  6. data: {
  7. state: false,
  8. qrCode: ''
  9. },
  10. methods: {
  11. async open() {
  12. let qrCode = await createWxCode({
  13. page: "pages/index/index",
  14. scene: wx.getStorageSync('uid')
  15. })
  16. this.setData({
  17. state: true,
  18. qrCode
  19. })
  20. },
  21. closeMediaBox() {
  22. this.setData({
  23. state: false
  24. })
  25. },
  26. savePoster() {
  27. const query = wx.createSelectorQuery().in(this);
  28. query
  29. .select('#cavansId')
  30. .fields({
  31. node: true,
  32. size: true
  33. }).exec(async (res) => {
  34. console.log(res, 'rrr');
  35. let canvas = res[0].node;
  36. const ctx = canvas.getContext('2d');
  37. canvas.width = 646;
  38. canvas.height = 959;
  39. let pic = canvas.createImage();
  40. pic.src = 'https://reader-wx.ai160.com/images/reader/pay/shareBg.jpg'
  41. pic.onload = () => {
  42. ctx.drawImage(pic, 0, 0, 646, 959);
  43. let pl = canvas.createImage();
  44. pl.src = this.data.qrCode
  45. pl.onload = () => {
  46. ctx.drawImage(pl, 29, 756, 170, 170)
  47. console.log(canvas, 'canvas');
  48. wx.canvasToTempFilePath({
  49. canvas: canvas,
  50. success(imgRes) {
  51. wx.saveImageToPhotosAlbum({
  52. filePath: imgRes.tempFilePath,
  53. success() {
  54. wx.showToast({
  55. title: '保存成功',
  56. icon: 'none'
  57. })
  58. },
  59. fail(rrr) {
  60. console.log(rrr, 'rrr');
  61. }
  62. })
  63. },
  64. fail(failMsg) {
  65. console.log(failMsg, 'eqweqwe');
  66. }
  67. })
  68. }
  69. }
  70. })
  71. }
  72. }
  73. })