export default{ data(){ return { //设置默认的分享参数 share:{ title:'省的多,赚得多', path:'/pages/home/home', imageUrl:'http://imgs.726p.com/tbk/upload/inviteImg2018-12-06/150716/kx-5c08caa4746e8.png', desc:'省的多,赚得多', content:'' }, is_clipbpard: false, clipboardPage: [ // 允许获取剪切板的页面路径 'pages/home/home', 'pages/optimization/optimization', 'pages/my/my' ], } }, onShow() { let pages = getCurrentPages() let currentPage = pages[pages.length-1] if (!currentPage || this.clipboardPage.indexOf(currentPage.route) != -1) { this.allPageClipboard() } }, onHide() { this.clipbpardClose() }, methods:{ // 获取剪切板内容 根据is_clipbpard判断弹框的显示隐藏 allPageClipboard(){ // 剪切板内容已经重新获取 if (uni.getStorageSync('clipboard') == 'no') { this.is_clipbpard = false return; }; uni.getClipboardData({ success: (res) => { uni.hideToast(); uni.setStorageSync('clipboard', 'no') if ( res.data.trim() && res.data.trim() != '') { this.is_clipbpard = true; uni.setStorageSync('clipbpard_con', res.data.trim()) //clipbpard_con剪切板内容 } else { this.is_clipbpard = false } }, }); }, clipbpardClose(){ this.is_clipbpard = false; }, }, onShareAppMessage(res) { if(res.from === 'button'){ // 来自页面内分享按钮 let userInfo = uni.getStorageSync('userInfo') || ''; if(res.target.dataset.source == 'inviteFriend'){//邀请好友按钮 this.share.imageUrl = 'http://imgs.726p.com/tbk/upload/inviteImg2019-07-05/103311/kx-5d1eb6e7ba663.png' this.share.path = `/pages/home/home?invite_code=${userInfo.invite_code}` } }else{ this.share.imageUrl = 'http://imgs.726p.com/tbk/upload/inviteImg2018-12-06/150716/kx-5c08caa4746e8.png' this.share.path = '/pages/home/home' } return { title:this.share.title, path:this.share.path, imageUrl:this.share.imageUrl, desc:this.share.desc, content:this.share.content, success(res){ uni.showToast({ title:'分享成功' }) }, fail(res){ uni.showToast({ title:'分享失败', icon:'none' }) } } } }