poster.js 3.3 KB

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