No Description
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.

Wechat.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { assign, loadJs } from './utils'
  2. import Share from './Share'
  3. export default class Wechat extends Share {
  4. constructor(config) {
  5. super(config)
  6. this.setConfig(config)
  7. }
  8. call(command, options) {
  9. this.setShareData(options)
  10. }
  11. setConfig(config) {
  12. super.setConfig(config)
  13. this.init(this.getConfig().wechatConfig)
  14. }
  15. init(config) {
  16. if (!config) {
  17. return
  18. }
  19. loadJs('https://res.wx.qq.com/open/js/jweixin-1.4.0.js', () => {
  20. wx.config(
  21. assign(
  22. {
  23. debug: false,
  24. jsApiList: [
  25. 'onMenuShareTimeline',
  26. 'onMenuShareAppMessage',
  27. 'onMenuShareQQ',
  28. 'onMenuShareWeibo',
  29. 'onMenuShareQZone',
  30. 'updateAppMessageShareData',
  31. 'updateTimelineShareData',
  32. ],
  33. },
  34. config
  35. )
  36. )
  37. const shareData = this._shareData
  38. const wxShareData = {}
  39. Object.defineProperty(wxShareData, 'trigger', {
  40. get() {
  41. return (...args) => {
  42. assign(wxShareData, {
  43. title: shareData.title,
  44. desc: shareData.desc,
  45. link: shareData.link,
  46. imgUrl: shareData.icon,
  47. success: shareData.success,
  48. fail: shareData.fail,
  49. cancel: shareData.fail,
  50. })
  51. shareData.trigger(...args)
  52. }
  53. },
  54. set(newValue) {
  55. shareData.trigger = newValue
  56. },
  57. enumerable: true,
  58. })
  59. wx.ready(() => {
  60. wx.onMenuShareAppMessage(wxShareData)
  61. wx.onMenuShareQQ(wxShareData)
  62. wx.onMenuShareQZone(wxShareData)
  63. wx.onMenuShareWeibo(wxShareData)
  64. wx.onMenuShareTimeline(wxShareData)
  65. wx.updateAppMessageShareData(wxShareData)
  66. wx.updateTimelineShareData(wxShareData)
  67. })
  68. })
  69. }
  70. }