poster.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // pages/master/poster/poster.js
  2. const util = require("../../../utils/util");
  3. const api = require('../../../api/api.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. showMoments: false,
  10. rid: '',
  11. urlLink:'',
  12. shareQr: '',
  13. shareType: 1,
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad(options) {
  19. if (options.rid) {
  20. this.setData({
  21. rid: options.rid
  22. });
  23. }
  24. wx.showShareMenu({
  25. withShareTicket: true,
  26. menus: ['shareAppMessage', 'shareTimeline']
  27. }),
  28. util.request(api.zzyPoster, {}, "POST").then((res) => {
  29. if (res.errno == 0) {
  30. this.setData({
  31. shareQr: res.data.data.shareQr,
  32. urlLink:res.data.data.urlLink
  33. })
  34. }
  35. })
  36. },
  37. onShareAppMessage() {
  38. let rid = this.data.rid;
  39. const promise = new Promise(resolve => util.request(api.recordZzyShare, {
  40. userId: rid,
  41. shareType:this.data.shareType
  42. }, 'GET').then(res => {
  43. if (res.errno === 0) {
  44. resolve({
  45. title: '鲸致生活,欢迎您的加入!',
  46. path: `/pages/upgrade/joinMaster/joinMaster?rid=${this.data.rid}&shareType=${this.data.shareType}`,
  47. imageUrl: this.data.shareQr
  48. })
  49. }
  50. }));
  51. return {
  52. promise
  53. }
  54. },
  55. showMonents() {
  56. this.setData({
  57. showMoments: true
  58. })
  59. },
  60. noShowMonents() {
  61. this.setData({
  62. showMoments: false
  63. })
  64. },
  65. shareTowx() {},
  66. onShareTimeline: function () {
  67. this.setData({
  68. shareType:2
  69. })
  70. let rid = this.data.rid;
  71. const promise = new Promise(resolve => util.request(api.recordZzyShare, {
  72. userId: rid,
  73. shareType:this.data.shareType
  74. }, 'GET').then(res => {
  75. if (res.errno === 0) {
  76. resolve({
  77. title: '鲸致生活,欢迎您的加入!',
  78. path: `/pages/upgrade/joinMaster/joinMaster?rid=${this.data.rid}&shareType=${this.data.shareType}`,
  79. imageUrl: this.data.shareQr
  80. })
  81. }
  82. }));
  83. return {
  84. promise
  85. }
  86. },
  87. downLoadImg() {
  88. wx.downloadFile({
  89. url: this.data.shareQr, //图片地址
  90. success: function (res) {
  91. //wx.saveImageToPhotosAlbum方法:保存图片到系统相册
  92. wx.saveImageToPhotosAlbum({
  93. filePath: res.tempFilePath, //图片文件路径
  94. success: function (data) {
  95. wx.showToast({
  96. icon: "none",
  97. title: '图片已保存到相册',
  98. })
  99. }
  100. })
  101. }
  102. })
  103. },
  104. copyLink() {
  105. wx.setClipboardData({
  106. //要复制的数据
  107. data:this.data.urlLink,
  108. success: function (res) {
  109. console.log("复制",res);
  110. wx.showToast ({
  111. title: '链接复制成功,请前往浏览器粘贴打开!',
  112. icon: 'none',
  113. duration: 2000,
  114. });
  115. }
  116. });
  117. }
  118. })