web.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. var _request = require('../../utils/request.js')
  2. Page({
  3. data: {
  4. url: '',
  5. shareTitle: '凤凰菁选商城',
  6. sharePath: '',
  7. shareImageUrl: ''
  8. },
  9. onLoad: function (options) {
  10. console.log(options)
  11. var url = options.id;
  12. let links = decodeURIComponent(url);
  13. if(!links){
  14. links = url;
  15. }
  16. this.setData({
  17. url: links,
  18. sharePath: links
  19. })
  20. // wx.setNavigationBarTitle({
  21. // title: 'sdsd'
  22. // })
  23. },
  24. onWebMessage: function (event) {
  25. var list = event && event.detail && event.detail.data
  26. if (!Array.isArray(list) || !list.length) {
  27. return
  28. }
  29. var data = list[list.length - 1] || {}
  30. if (data.shareSource !== 'tcm_constitution') {
  31. return
  32. }
  33. var next = {}
  34. if (data.shareTitle) {
  35. next.shareTitle = data.shareTitle
  36. }
  37. if (data.shareUrl) {
  38. next.sharePath = data.shareUrl
  39. }
  40. if (data.shareImageUrl) {
  41. next.shareImageUrl = data.shareImageUrl
  42. }
  43. if (Object.keys(next).length) {
  44. this.setData(next)
  45. }
  46. },
  47. onShareAppMessage: function (val) {
  48. var shareUrl = this.data.sharePath || this.data.url
  49. return _request.share({
  50. title: this.data.shareTitle || '凤凰菁选商城',
  51. path: '/pages/start/start?url=pages/web/web&id=' + encodeURIComponent(shareUrl),
  52. imageUrl: this.data.shareImageUrl || '',
  53. sc: this.data.shareTitle === '九型体质评测' ? 'tcm_constitution_share' : 'cxc_web'
  54. })
  55. }
  56. })