index.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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: `?uid=${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. let canvas
  29. query
  30. .select('#cavansId')
  31. .fields({
  32. node: true,
  33. size: true
  34. }).exec(async (res) => {
  35. canvas = res[0].node;
  36. const ctx = canvas.getContext('2d');
  37. const dpr = wx.getSystemInfoSync().pixelRatio;
  38. canvas.width = 646;
  39. canvas.height = 959;
  40. let pic = canvas.createImage();
  41. pic.src = 'https://reader-wx.ai160.com/images/reader/pay/shareBg.jpg'
  42. pic.onload = () => {
  43. ctx.drawImage(pic, 0, 0, 646, 959);
  44. let pl = canvas.createImage();
  45. pl.src = this.data.qrCode
  46. pl.onload = async () => {
  47. ctx.drawImage(pl, 29, 756, 170, 170)
  48. let {
  49. tempFilePath
  50. } = await wx.canvasToTempFilePath({
  51. canvas
  52. })
  53. wx.saveImageToPhotosAlbum({
  54. filePath: tempFilePath,
  55. success() {
  56. wx.showToast({
  57. title: '保存成功',
  58. icon: 'none'
  59. })
  60. }
  61. })
  62. }
  63. }
  64. })
  65. }
  66. }
  67. })