// pages/master/poster/poster.js const util = require("../../../utils/util"); const api = require('../../../api/api.js'); Page({ /** * 页面的初始数据 */ data: { showMoments: false, rid: '', urlLink:'', shareQr: '', shareType: 1, }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { if (options.rid) { this.setData({ rid: options.rid }); } wx.showShareMenu({ withShareTicket: true, menus: ['shareAppMessage', 'shareTimeline'] }), util.request(api.zzyPoster, {}, "POST").then((res) => { if (res.errno == 0) { this.setData({ shareQr: res.data.data.shareQr, urlLink:res.data.data.urlLink }) } }) }, onShareAppMessage() { let rid = this.data.rid; const promise = new Promise(resolve => util.request(api.recordZzyShare, { userId: rid, shareType:this.data.shareType }, 'GET').then(res => { if (res.errno === 0) { resolve({ title: '鲸致生活,欢迎您的加入!', path: `/pages/upgrade/joinMaster/joinMaster?rid=${this.data.rid}&shareType=${this.data.shareType}`, imageUrl: this.data.shareQr }) } })); return { promise } }, showMonents() { this.setData({ showMoments: true }) }, noShowMonents() { this.setData({ showMoments: false }) }, shareTowx() {}, onShareTimeline: function () { this.setData({ shareType:2 }) let rid = this.data.rid; const promise = new Promise(resolve => util.request(api.recordZzyShare, { userId: rid, shareType:this.data.shareType }, 'GET').then(res => { if (res.errno === 0) { resolve({ title: '鲸致生活,欢迎您的加入!', path: `/pages/upgrade/joinMaster/joinMaster?rid=${this.data.rid}&shareType=${this.data.shareType}`, imageUrl: this.data.shareQr }) } })); return { promise } }, downLoadImg() { wx.downloadFile({ url: this.data.shareQr, //图片地址 success: function (res) { //wx.saveImageToPhotosAlbum方法:保存图片到系统相册 wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, //图片文件路径 success: function (data) { wx.showToast({ icon: "none", title: '图片已保存到相册', }) } }) } }) }, copyLink() { wx.setClipboardData({ //要复制的数据 data:this.data.urlLink, success: function (res) { console.log("复制",res); wx.showToast ({ title: '链接复制成功,请前往浏览器粘贴打开!', icon: 'none', duration: 2000, }); } }); } })