index.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import {
  2. getVipInfo,
  3. } from '~/api/user'
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. },
  10. /**
  11. * 组件的初始数据
  12. */
  13. data: {
  14. show: false,
  15. type: '',
  16. vipTime:''
  17. },
  18. methods: {
  19. open({
  20. type
  21. }) {
  22. if (typeof this.getTabBar === 'function') {
  23. this.getTabBar().setData({
  24. mask: true
  25. })
  26. }
  27. this.getVipInfo()
  28. this.setData({
  29. type,
  30. show: true
  31. })
  32. },
  33. closeModal() {
  34. this.setData({
  35. show: false
  36. })
  37. if (typeof this.getTabBar === 'function') {
  38. this.getTabBar().setData({
  39. mask: false
  40. })
  41. }
  42. },
  43. async getVipInfo() {
  44. let vipTime = await getVipInfo()
  45. console.log(vipTime);
  46. this.setData({
  47. vipTime
  48. })
  49. },
  50. creatShare() {
  51. let context = wx.createSelectorQuery();
  52. context
  53. .select('#vip')
  54. .fields({
  55. node: true,
  56. size: true
  57. }).exec((res) => {
  58. const canvas = res[0].node;
  59. const ctx = canvas.getContext('2d');
  60. const dpr = wx.getSystemInfoSync().pixelRatio;
  61. canvas.width = res[0].width * dpr;
  62. canvas.height = res[0].height * dpr;
  63. ctx.scale(dpr, dpr);
  64. ctx.font = '20px PingFang';
  65. let pic = canvas.createImage();
  66. pic.src = 'http://reader-wx.ai160.com/images/reader/v3/learn/vip1.png'
  67. pic.onload = () => {
  68. ctx.drawImage(pic, 0, 0, 375, 201);
  69. ctx.fillText('终身使用', 144, 135)
  70. ctx.fillStyle = 'red'
  71. setTimeout(() => {
  72. wx.canvasToTempFilePath({
  73. canvas: canvas,
  74. success(res) {
  75. wx.saveImageToPhotosAlbum({
  76. filePath: res.tempFilePath,
  77. success(res) {}
  78. })
  79. },
  80. fail(res) {
  81. console.log('fail', res);
  82. }
  83. }, this)
  84. }, 500)
  85. }
  86. })
  87. },
  88. }
  89. })