Commit f789151d by 李伟康

设置分享

1 parent 60951ca6
...@@ -9,6 +9,8 @@ import { getUpdateManager } from "./lib/index"; ...@@ -9,6 +9,8 @@ import { getUpdateManager } from "./lib/index";
import utils from "./utils/index"; import utils from "./utils/index";
// 埋点 有需要再引入 // 埋点 有需要再引入
// import './utils/track/Track' // import './utils/track/Track'
/**分享 */
import './utils/share'
App({ App({
onLaunch(options) { onLaunch(options) {
getUpdateManager(); getUpdateManager();
......
...@@ -263,16 +263,11 @@ Page({ ...@@ -263,16 +263,11 @@ Page({
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad: function (options) {
if (this.data.id) {
this.getGoodsDetail(this.data.id)
} else {
/**扫码、分享、直播间 */
if (options && options.id) { if (options && options.id) {
this.setData(options) this.setData(options)
this.getGoodsDetail(options.id) this.getGoodsDetail(options.id)
if (!options.isActivity) this.getGoodscouponList(options.id) if (!options.isActivity) this.getGoodscouponList(options.id)
} }
}
// 推荐人+推荐人埋点 // 推荐人+推荐人埋点
if (options.shareStaffUuid) { if (options.shareStaffUuid) {
let shareStaff = { let shareStaff = {
...@@ -313,6 +308,20 @@ Page({ ...@@ -313,6 +308,20 @@ Page({
goodsId: data.id goodsId: data.id
} }
// wx.$Track.setTrack(trackobj, 6) // wx.$Track.setTrack(trackobj, 6)
//设置分享
let shareQuery = `id=${data.id}`,
shareTitle = data.goodsName,
shareImage = ''
data.goodsDetailImageList.map(e => {
if (e.resType == 1) shareImage = e.content
})
if (isActivity) {
shareTitle = data.activityName
shareQuery += '&isActivity=true'
}
this.shareQuery = shareQuery
this.shareTitle = shareTitle
this.shareImage = shareImage
let activeSku = null let activeSku = null
if (data.expressFee != null) data.expressFee = centsToyuan(data.expressFee) if (data.expressFee != null) data.expressFee = centsToyuan(data.expressFee)
if (isActivity) { if (isActivity) {
...@@ -507,37 +516,10 @@ Page({ ...@@ -507,37 +516,10 @@ Page({
* 页面上拉触底事件的处理函数 * 页面上拉触底事件的处理函数
*/ */
onReachBottom: function () {}, onReachBottom: function () {},
/** /**
* 用户点击右上角分享 * 用户点击右上角分享
*/ */
onShareAppMessage: function () { onShareAppMessage: function () {},
const {
merchantId
} = wx.p.storage.get('merchant_info')
let {
isActivity,
isLive,
goodsInfo
} = this.data
let title = goodsInfo.goodsName
let path = `${this.route}?id=${goodsInfo.id}`
let imageUrl = ''
goodsInfo.goodsDetailImageList.map(e => {
if (e.resType == 1 && !imageUrl) imageUrl = e.content
})
if (isActivity) {
title = goodsInfo.activityName
path = `${path}&isActivity=true`
}
if (isLive) path = `${path}&isLive=true`
if (merchantId) path = `${path}&merchantId=${merchantId}`
return {
imageUrl,
title,
path
}
},
countDown(params) { countDown(params) {
let { let {
activityStatus activityStatus
......
...@@ -91,7 +91,7 @@ Page({ ...@@ -91,7 +91,7 @@ Page({
let para = { let para = {
merchantId merchantId
} }
wx.p.wxApi.equityApi.memberCard(para).then(res => { wx.p.api.equityApi.memberCard(para).then(res => {
this.setData({ this.setData({
memberInfo: res memberInfo: res
}) })
......
...@@ -10,7 +10,8 @@ export const STORAGE_OBJECTkEY = { ...@@ -10,7 +10,8 @@ export const STORAGE_OBJECTkEY = {
userInfo: 'userInfo', userInfo: 'userInfo',
sessionId: 'sessionId', sessionId: 'sessionId',
bindInfo:'bindInfo', bindInfo:'bindInfo',
unauthorized:'unauthorized' unauthorized:'unauthorized',
wx_user_info:'wx_user_info'
} }
export default{ export default{
......
...@@ -9,12 +9,11 @@ ...@@ -9,12 +9,11 @@
* @param {*} onViewTrack 开启浏览埋点 * @param {*} onViewTrack 开启浏览埋点
* @returns * @returns
*/ */
import { reportData } from '~/api/index.js' // import { reportData } from '~/api/index.js'
import USERAPI from '~/api/usersApi/index'
class Share { class Share {
constructor() { constructor() {
// console.log('---------------- 分享初始化 ----------------') console.log('---------------- 分享初始化 ----------------')
this.initPageProxy() this.initPageProxy()
} }
/**全局注册事件 */ /**全局注册事件 */
...@@ -43,9 +42,14 @@ class Share { ...@@ -43,9 +42,14 @@ class Share {
path += that.setCommonShareQuery() path += that.setCommonShareQuery()
if (shareQuery) path += `&${shareQuery}` if (shareQuery) path += `&${shareQuery}`
console.log('===============', path) console.log('===============', path)
if (!noPageAuth) path = `/login/loading/loading?url=${encodeURIComponent(path)}` if (!noPageAuth) path = `/pages/loading/loading?url=${encodeURIComponent(path)}`
if (shareFun) shareFun() if (shareFun) shareFun()
if (shareTrackData) that.reportShareData(shareTrackData) // if (shareTrackData) that.reportShareData(shareTrackData)
console.table( {
path,
title: shareTitle,
imageUrl: shareImage
})
return { return {
path, path,
title: shareTitle, title: shareTitle,
...@@ -57,7 +61,7 @@ class Share { ...@@ -57,7 +61,7 @@ class Share {
page.onShareTimeline = function () { page.onShareTimeline = function () {
let { shareTitle, shareImage, shareQuery, shareFun, shareTrackData } = this let { shareTitle, shareImage, shareQuery, shareFun, shareTrackData } = this
if (shareFun) shareFun() if (shareFun) shareFun()
if (shareTrackData) that.reportShareData(shareTrackData) // if (shareTrackData) that.reportShareData(shareTrackData)
shareQuery = that.setCommonShareQuery(shareQuery) shareQuery = that.setCommonShareQuery(shareQuery)
console.log(shareQuery) console.log(shareQuery)
return { return {
...@@ -70,21 +74,21 @@ class Share { ...@@ -70,21 +74,21 @@ class Share {
page.onLoad = async function () { page.onLoad = async function () {
onLoad && onLoad.apply(this, arguments) onLoad && onLoad.apply(this, arguments)
if (this.onViewTrack) { if (this.onViewTrack) {
const WXUSERINFO = await USERAPI.getWXUserInfo(), // const WXUSERINFO = await USERAPI.getWXUserInfo(),
{ USERINFO } = that.getCommonData(), // { USERINFO } = that.getCommonData(),
shareInfo = this.options // shareInfo = this.options
if (shareInfo.shareOpenId) // if (shareInfo.shareOpenId)
reportData( // reportData(
{ // {
openId: WXUSERINFO.openId || '', // openId: WXUSERINFO.openId || '',
unionId: WXUSERINFO.unionId || '', // unionId: WXUSERINFO.unionId || '',
nickName: WXUSERINFO.nickName || '', // nickName: WXUSERINFO.nickName || '',
avatar: WXUSERINFO.avatarUrl || '', // avatar: WXUSERINFO.avatarUrl || '',
phone: WXUSERINFO.phone || USERINFO.phone || '', // phone: WXUSERINFO.phone || USERINFO.phone || '',
...shareInfo // ...shareInfo
}, // },
1 // 1
) // )
} }
} }
} }
...@@ -118,4 +122,4 @@ class Share { ...@@ -118,4 +122,4 @@ class Share {
}) })
} }
} }
new Share() export default new Share()
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!