猎豆优选小程序

mixin.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. export default{
  2. data(){
  3. return { //设置默认的分享参数
  4. share:{
  5. title:'省的多,赚得多',
  6. path:'/pages/home/home',
  7. imageUrl:'http://imgs.726p.com/tbk/upload/inviteImg2018-12-06/150716/kx-5c08caa4746e8.png',
  8. desc:'省的多,赚得多',
  9. content:''
  10. },
  11. is_clipbpard: false,
  12. clipboardPage: [ // 允许获取剪切板的页面路径
  13. 'pages/home/home',
  14. 'pages/optimization/optimization',
  15. 'pages/my/my'
  16. ],
  17. }
  18. },
  19. onShow() {
  20. let pages = getCurrentPages()
  21. let currentPage = pages[pages.length-1]
  22. if (!currentPage || this.clipboardPage.indexOf(currentPage.route) != -1) {
  23. this.allPageClipboard()
  24. }
  25. },
  26. onHide() {
  27. this.clipbpardClose()
  28. },
  29. methods:{
  30. // 获取剪切板内容 根据is_clipbpard判断弹框的显示隐藏
  31. allPageClipboard(){
  32. // 剪切板内容已经重新获取
  33. if (uni.getStorageSync('clipboard') == 'no') {
  34. this.is_clipbpard = false
  35. return;
  36. };
  37. uni.getClipboardData({
  38. success: (res) => {
  39. uni.hideToast();
  40. uni.setStorageSync('clipboard', 'no')
  41. if ( res.data.trim() && res.data.trim() != '') {
  42. this.is_clipbpard = true;
  43. uni.setStorageSync('clipbpard_con', res.data.trim()) //clipbpard_con剪切板内容
  44. } else {
  45. this.is_clipbpard = false
  46. }
  47. },
  48. });
  49. },
  50. clipbpardClose(){
  51. this.is_clipbpard = false;
  52. },
  53. },
  54. onShareAppMessage(res) {
  55. if(res.from === 'button'){ // 来自页面内分享按钮
  56. let userInfo = uni.getStorageSync('userInfo') || '';
  57. if(res.target.dataset.source == 'inviteFriend'){//邀请好友按钮
  58. this.share.imageUrl = 'http://imgs.726p.com/tbk/upload/inviteImg2019-07-05/103311/kx-5d1eb6e7ba663.png'
  59. this.share.path = `/pages/home/home?invite_code=${userInfo.invite_code}`
  60. }
  61. }else{
  62. this.share.imageUrl = 'http://imgs.726p.com/tbk/upload/inviteImg2018-12-06/150716/kx-5c08caa4746e8.png'
  63. this.share.path = '/pages/home/home'
  64. }
  65. return {
  66. title:this.share.title,
  67. path:this.share.path,
  68. imageUrl:this.share.imageUrl,
  69. desc:this.share.desc,
  70. content:this.share.content,
  71. success(res){
  72. uni.showToast({
  73. title:'分享成功'
  74. })
  75. },
  76. fail(res){
  77. uni.showToast({
  78. title:'分享失败',
  79. icon:'none'
  80. })
  81. }
  82. }
  83. }
  84. }