share.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. export default {
  2. data() {
  3. return {
  4. //设置默认的分享参数
  5. //如果页面不设置share,就触发这个默认的分享
  6. share: {
  7. title: '闽南魂',
  8. path: '',
  9. imageUrl: 'https://huli-app.wenlvti.net/app_static/minnanhun/image/ccbg.png',
  10. desc: '',
  11. content: ''
  12. }
  13. }
  14. },
  15. onShareAppMessage(res) {
  16. console.log(this.share.path);
  17. if (this.share.path == '') {
  18. var pages = getCurrentPages() // 获取栈实例
  19. let currentRoute = pages[pages.length - 1].route; // 获取当前页面路由
  20. let currentPage = pages[pages.length - 1]['$page']['fullPath'] //当前页面路径(带参数)
  21. this.share.path = currentPage;
  22. }
  23. let user = this.$common.userInfo();
  24. if (user) {
  25. if (this.share.path.indexOf('from_userid') < 0) {
  26. if (this.share.path.indexOf('?') > 0) {
  27. this.share.path = this.share.path + '&from_userid=' + user.id
  28. } else {
  29. this.share.path = this.share.path + '?from_userid=' + user.id
  30. }
  31. }
  32. }
  33. return {
  34. title: this.share.title,
  35. path: this.share.path,
  36. imageUrl: this.share.imageUrl,
  37. desc: this.share.desc,
  38. content: this.share.content,
  39. success(res) {
  40. uni.showToast({
  41. title: '分享成功'
  42. })
  43. },
  44. fail(res) {
  45. uni.showToast({
  46. title: '分享失败',
  47. icon: 'none'
  48. })
  49. }
  50. }
  51. },
  52. onShareTimeline(res) {
  53. return {
  54. title: this.share.title,
  55. path: this.share.path,
  56. imageUrl: this.share.imageUrl,
  57. success(res) {
  58. uni.showToast({
  59. title: '分享成功'
  60. })
  61. },
  62. fail(res) {
  63. uni.showToast({
  64. title: '分享失败',
  65. icon: 'none'
  66. })
  67. }
  68. }
  69. }
  70. }