Commit a988988e by 胡悦

修改

1 parent 0ece257b
......@@ -7,8 +7,6 @@ import {
wechatApi
} from './api/api'
import {trackData} from './utils/data'
// //全局分享
// import './utils/share'
import eventbus from './utils/evenbus'
// 实例化对象存储
......
......@@ -108,6 +108,8 @@
}
.product-tip {
display: flex;
align-items: center;
width: 704rpx;
height: 44rpx;
background-image: linear-gradient(133deg, rgba(0, 51, 255, 0.08) 0%, #FFFFFF 100%);
......
/** 分享
* @param {*} shareTitle 分享标题
* @param {*} sharePath 分享页面路径 不传默认当前页
* @param {*} shareImage 分享图片 不传默认当前页面截图
* @param {*} shareQuery 分享页面参数
* @param {*} noPageAuth 分享页面是否需要登录拦截
* @param {*} shareFun 分享页面
* @param {*} shareTrackData 分享埋点数据
* @param {*} onViewTrack 开启浏览埋点
* @returns
*/
// import {
// reportData
// } from '~/api/index.js'
// import USERAPI from '~/api/usersApi/index'
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) {
const onLoad = page.onLoad,
that = this
if (page.onShareAppMessage) {
const that = this
page.onShareAppMessage = function () {
let {
shareTitle,
sharePath,
shareImage,
shareQuery,
noPageAuth,
shareFun,
shareTrackData
} = this,
path = `/${this.route}`
if (sharePath) path = `/${sharePath}`
path += that.setCommonShareQuery()
if (shareQuery) path += `&${shareQuery}`
console.log('===============', path)
if (!noPageAuth) path = `/login/loading/loading?url=${encodeURIComponent(path)}`
if (shareFun) shareFun()
if (shareTrackData) that.reportShareData(shareTrackData)
return {
path,
title: shareTitle,
imageUrl: shareImage
}
}
}
if (page.onShareTimeline) {
page.onShareTimeline = function () {
let {
shareTitle,
shareImage,
shareQuery,
shareFun,
shareTrackData
} = this
if (shareFun) shareFun()
if (shareTrackData) that.reportShareData(shareTrackData)
shareQuery = that.setCommonShareQuery(shareQuery)
console.log(shareQuery)
return {
query: shareQuery,
title: shareTitle,
imageUrl: shareImage
}
}
}
page.onLoad = async function () {
onLoad && onLoad.apply(this, arguments)
if (this.onViewTrack) {
const WXUSERINFO = await USERAPI.getWXUserInfo(),
{
USERINFO
} = that.getCommonData(),
shareInfo = this.options
// if (shareInfo.shareOpenId) reportData({
// openId: WXUSERINFO.openId || '',
// unionId: WXUSERINFO.unionId || '',
// nickName: WXUSERINFO.nickName || '',
// avatar: WXUSERINFO.avatarUrl || '',
// phone: WXUSERINFO.phone || USERINFO.phone || '',
// ...shareInfo
// }, 1)
}
}
}
getCommonData() {
const WXUSERINFO = wx.$storage.get('wx_user_info'),
USERINFO = wx.$storage.get('userInfo')
return {
WXUSERINFO,
USERINFO
}
}
setCommonShareQuery(query) {
const {
WXUSERINFO,
USERINFO
} = this.getCommonData(),
thisPage = wx.$router.getPageInstance().options
query = `${query? `?${query}&`:'?'}merchantId=${thisPage.merchantId || USERINFO.merchantId || ''}&shareOpenId=${thisPage.shareOpenId || WXUSERINFO.openId || ''}&sharePhone=${thisPage.sharePhone || USERINFO.phone || ''}`
return query
}
// reportShareData(shareTrackData) {
// const {
// WXUSERINFO,
// USERINFO
// } = this.getCommonData(),
// thisPage = wx.$router.getPageInstance().options
// // reportData({
// // openId: WXUSERINFO.openId || '',
// // unionId: WXUSERINFO.unionId || '',
// // nickName: WXUSERINFO.nickName || '',
// // avatar: WXUSERINFO.avatarUrl || '',
// // phone: USERINFO.phone || '',
// // merchantId: thisPage.merchantId || USERINFO.merchantId || '',
// // shareOpenId: thisPage.shareOpenId || WXUSERINFO.openId || '',
// // sharePhone: thisPage.sharePhone || USERINFO.phone || '',
// // ...shareTrackData
// // })
// }
}
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!