share.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. export default function(shareInfo) {
  2. const num = 4
  3. const iconSize = 68
  4. const cancelHeight = 88
  5. const itemSize = 750 / num
  6. const px = plus.screen.resolutionWidth / 750
  7. const height = plus.screen.resolutionHeight
  8. const rpx = num => px * num + 'px'
  9. uni._MASK = new plus.nativeObj.View("MASK", { top: '0px', left: '0px', height: '100%', width: '100%', backgroundColor: 'rgba(0,0,0,0.3)'})
  10. uni._SHARE = new plus.nativeObj.View("SHARE", { bottom: '0px', left: '0px', height: rpx(285.5), width: '100%', backgroundColor: '#FFFFFF' })
  11. uni._MASK.addEventListener("click", e => {
  12. uni._MASK.hide()
  13. uni._SHARE.hide()
  14. })
  15. uni._SHARE.draw([
  16. {
  17. tag:'font',
  18. id:'SHARECANLEL',
  19. text: '取消',
  20. textStyles:{ size: rpx(32), align: 'center', verticalAlign: 'center' },
  21. position:{ bottom: '0px', left: '0px', width: '100%', height: rpx(cancelHeight) },
  22. },
  23. {
  24. tag:'rect',
  25. id:'SHARECANLELLINE',
  26. rectStyles:{ color: '#B2B2B2' },
  27. position:{ bottom: rpx(cancelHeight), left: '0px', width: '100%', height: '1px' },
  28. },
  29. {
  30. tag: 'img',
  31. id: 'sharewx',
  32. src: '/static/icon/sharewx.png',
  33. position: {
  34. left: rpx((itemSize - iconSize) / 2),
  35. width: rpx(iconSize),
  36. height: rpx(iconSize),
  37. bottom: rpx(cancelHeight + 88)
  38. }
  39. },
  40. {
  41. tag: 'img',
  42. id: 'sharepyq',
  43. src: '/static/icon/sharepyq.png',
  44. position: {
  45. left: rpx((itemSize - iconSize) / 2 + itemSize),
  46. width: rpx(iconSize),
  47. height: rpx(iconSize),
  48. bottom: rpx(cancelHeight + 88)
  49. }
  50. },
  51. {
  52. tag: 'img',
  53. id: 'sharemore',
  54. src: '/static/icon/sharemore.png',
  55. position: {
  56. left: rpx((itemSize - iconSize) / 2 + itemSize * 2),
  57. width: rpx(iconSize),
  58. height: rpx(iconSize),
  59. bottom: rpx(cancelHeight + 88)
  60. }
  61. },
  62. {
  63. tag: 'font',
  64. id: 'sharewxtext',
  65. text: '分享好友',
  66. textStyles:{ size: rpx(28), align: 'center', verticalAlign: 'center' },
  67. position:{ bottom: rpx(cancelHeight), left: '0px', width: rpx(itemSize), height: rpx(88) },
  68. },
  69. {
  70. tag: 'font',
  71. id: 'sharepyqtext',
  72. text: '分享朋友圈',
  73. textStyles:{ size: rpx(28), align: 'center', verticalAlign: 'center' },
  74. position:{ bottom: rpx(cancelHeight), left: rpx(itemSize), width: rpx(itemSize), height: rpx(88) },
  75. },
  76. {
  77. tag: 'font',
  78. id: 'sharemoretext',
  79. text: '更多',
  80. textStyles:{ size: rpx(28), align: 'center', verticalAlign: 'center' },
  81. position:{ bottom: rpx(cancelHeight), left: rpx(itemSize * 2), width: rpx(itemSize), height: rpx(88) },
  82. }
  83. ])
  84. uni._SHARE.addEventListener("click", e => {
  85. if (e.screenY > height - cancelHeight * px) { // 点击取消
  86. uni._MASK.hide()
  87. uni._SHARE.hide()
  88. } else {
  89. if (e.clientX <= itemSize * px) { // 分享到微信聊天
  90. plus.nativeUI.showWaiting()
  91. uni.share({ provider: "weixin", scene: "WXSceneSession",
  92. ...shareInfo,
  93. success () {
  94. plus.nativeUI.toast('分享成功')
  95. uni._MASK.hide()
  96. uni._SHARE.hide()
  97. },
  98. fail (err) {
  99. const season = err.errMsg.split(',')[0].split(':')
  100. plus.nativeUI.toast(`分享失败: ${season[season.length - 1]}`)
  101. },
  102. complete() {
  103. plus.nativeUI.closeWaiting()
  104. }
  105. })
  106. } else if (e.clientX > itemSize * px && e.clientX <= (itemSize * 2 * px)) { // 分享到朋友圈
  107. plus.nativeUI.showWaiting()
  108. uni.share({ provider: "weixin", scene: "WXSenceTimeline",
  109. ...shareInfo,
  110. success () {
  111. plus.nativeUI.toast('分享成功')
  112. uni._MASK.hide()
  113. uni._SHARE.hide()
  114. },
  115. fail (err) {
  116. const season = err.errMsg.split(',')[0].split(':')
  117. plus.nativeUI.toast(`分享失败: ${season[season.length - 1]}`)
  118. },
  119. complete() {
  120. plus.nativeUI.closeWaiting()
  121. }
  122. })
  123. } else if (e.clientX > (itemSize * 2 * px) && e.clientX <= (itemSize * 3 * px)) { // 分享到更多
  124. plus.share.sendWithSystem({ content: shareInfo.href })
  125. }
  126. }
  127. })
  128. uni._MASK.show()
  129. uni._SHARE.show()
  130. }