index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. 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. 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 = async () => {
  46. ctx.drawImage(pl, 29, 756, 170, 170)
  47. let {
  48. tempFilePath
  49. } = await wx.canvasToTempFilePath({
  50. canvas
  51. })
  52. wx.saveImageToPhotosAlbum({
  53. filePath: tempFilePath,
  54. success() {
  55. wx.showToast({
  56. title: '保存成功',
  57. icon: 'none'
  58. })
  59. }
  60. })
  61. }
  62. }
  63. })
  64. }
  65. }
  66. })