Commit d065a67c by 李伟康

增加全局分享

1 parent f9dfabb8
......@@ -25,6 +25,7 @@ promisifyAll()
import { Storage } from './utils/cache/storage'
const $Storage = new Storage()
import './utils/share'
App({
onLaunch(options) {
/**挂载到wx对象 */
......
......@@ -56,9 +56,7 @@ Page({
/**
* 用户点击右上角分享
*/
// onShareAppMessage() {
// },
// onShareAppMessage() {},
checkLoginBtn(disabled = false) {
const {
loginType
......@@ -76,5 +74,5 @@ Page({
this.setData({
disabled: !disabled
})
},
}
})
\ No newline at end of file
class Share {
constructor() {
console.log('---------------- 分享初始化 ----------------')
this.initPageProxy()
}
/**全局注册事件 */
initPageProxy() {
let thisPage = Page
let _this = this
Page = function (el) {
try {
el || (el = {}), _this.pageLeaveProxy(el), thisPage.apply(this, arguments)
} catch (el) {
thisPage.apply(this, arguments)
}
}
}
/**设置全局分享 */
pageLeaveProxy(page) {
if (page.onShareAppMessage) {
page.onShareAppMessage = function () {
let {
shareTitle,
sharePath,
shareImage,
shareQuery
} = this
if (!sharePath) {
let url = `/${this.route}`
if (shareQuery) url += `?${shareQuery}`
sharePath = `login/loading/loading?url=${encodeURIComponent(url)}`
}
return {
title: shareTitle,
path: `/${sharePath}`,
imageUrl: shareImage
}
}
}
}
}
wx.$share = new Share()
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!