推拿小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.2 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. import { mapState } from 'vuex'
  2. export default {
  3. data() {
  4. return {
  5. // 默认的全局分享内容
  6. Gshare: {
  7. // title: '三只青蛙',
  8. path: '/pages/index/index', // 全局分享的路径,比如 首页
  9. // imageUrl: '/static/image/login/logo.png', // 全局分享的图片(可本地可网络)
  10. }
  11. }
  12. },
  13. computed: {
  14. ...mapState(['configList', 'userInfo', 'riceInfo']),
  15. },
  16. onLoad(query) {
  17. if (query.shareId) {
  18. uni.setStorageSync('shareId', query.shareId)
  19. }
  20. },
  21. // 定义全局分享
  22. // 1.发送给朋友
  23. onShareAppMessage(res) {
  24. let o = {
  25. title : this.configList.logo_name,
  26. ...this.Gshare,
  27. }
  28. if(this.userInfo.id){
  29. if(this.Gshare.path.includes('?')){
  30. o.path += '&shareId=' + this.userInfo.id
  31. }else{
  32. o.path += '?shareId=' + this.userInfo.id
  33. }
  34. }
  35. return o
  36. },
  37. //2.分享到朋友圈
  38. onShareTimeline(res) {
  39. let o = {
  40. ...this.Gshare,
  41. title : this.configList.logo_name,
  42. }
  43. if(this.userInfo.id){
  44. o.path = this.Gshare.path + '?shareId=' + this.userInfo.id
  45. }
  46. return o
  47. },
  48. onLoad(query) {
  49. if (query.shareId) {
  50. uni.setStorageSync('shareId', query.shareId)
  51. }
  52. },
  53. onShow() {
  54. this.setupWeixinShare()
  55. },
  56. methods: {
  57. // 设置微信分享内容
  58. setupWeixinShare() {
  59. if (!this.$jWeixin) return
  60. this.$jWeixin.ready(() => {
  61. const shareData = {
  62. title: this.Gshare.title || '愈然工坊',
  63. desc: this.Gshare.desc || '愈然工坊,温柔呵护每一刻!',
  64. link: this.Gshare.path || location.href.split('#')[0],
  65. imgUrl: this.Gshare.imageUrl || '',
  66. success: () => {
  67. },
  68. cancel: () => {
  69. }
  70. }
  71. // 分享给朋友
  72. this.$jWeixin.updateAppMessageShareData(shareData)
  73. // 分享到朋友圈
  74. this.$jWeixin.updateTimelineShareData(shareData)
  75. // 分享到微博
  76. this.$jWeixin.onMenuShareWeibo(shareData)
  77. })
  78. },
  79. }
  80. }