Commit fec7ae10 by zhangquan

添加埋点

1 parent c67c6b01
......@@ -124,5 +124,32 @@ class UsersApi {
true
)
}
/**获取微信用户信息 */
async getWXUserInfo() {
let wx_user_info = wx.$storage.get('wx_user_info')
if (!wx_user_info) {
const data = await this.getUserProfile()
wx.$storage.set('wx_user_info', data)
return data
} else return wx_user_info
}
/** 手机号授权解析(单纯解析内容返回前端)
* 只传loginToken就返回unionId和openid
* 传加密信息就解析手机号
*/
async getUserProfile(loginToken, detail = {}) {
if (detail.errMsg && detail.errMsg == 'getPhoneNumber:fail user deny') Promise.reject()
delete detail.errMsg
if (!loginToken) {
let res = await this.wxCodeLogin()
loginToken = res.data
}
detail.loginToken = loginToken
return api.post({
method: 'scrm.api.sso.wechat.applets.phone.grant.analysis',
...detail,
platformEntrance: 'STORE_ASSISTANT'
})
}
}
export default UsersApi
\ No newline at end of file
......@@ -164,10 +164,25 @@ Page({
});
},
onRoute(options) {
},
noPageAuth : true,
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log(options)
wx.nextTick(()=>{
let { actNum, activeNavIdx, scene } = this.options
this.shareTitle = `给你分享一个${senceData[actNum].productList[activeNavIdx].proName}~`
// let name = wx.$storage.get('staff_name') || (wx.$storage.get('userInfo') ? wx.$storage.get('userInfo').name : '')
let name = wx.$storage.get('userInfo') ? wx.$storage.get('userInfo').name : ''
this.shareTitle = `${name}给你分享一个${senceData[actNum].productList[activeNavIdx].proName}~`
this.shareQuery = `actNum=${actNum}&activeNavIdx=${activeNavIdx}`
wx.setNavigationBarTitle({
title: senceData[actNum].name || '特色产品'
})
if(scene){
let qrcodeQuery = decodeURIComponent(scene)
let id = qrcodeQuery.split('=').pop()
......@@ -188,14 +203,6 @@ Page({
this.setRouteParams(this.options)
}
})
},
noPageAuth : true,
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
......
......@@ -26,37 +26,42 @@ Page({
isFirst: true,
changeSale: 0,
sceneCodeList:[],
currentId: 0
currentId: 0,
showPage: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
const { merchantId } = wx.$storage.get('userInfo')
wx.showLoading({
title: '加载中...',
})
ActivityApi.getOpenSceneList({
merchantId
}).then(res => {
wx.hideLoading()
if(res?.length>0){
let sceneCodeList = []
let senceData = [...this.data.senceData]
// let resp = [
// {
// sceneCode: 'SC001',
// status: 1
// },
// {
// sceneCode: 'SC002',
// status: 1
// },
// {
// sceneCode: 'SC003',
// status: 1
// },
// {
// sceneCode: 'SC004',
// status: 1
// }
// ]
let res = [
{
sceneCode: 'SC001',
status: 1
},
{
sceneCode: 'SC002',
status: 1
},
{
sceneCode: 'SC003',
status: 1
},
{
sceneCode: 'SC004',
status: 1
}
]
res.forEach((item,index) => {
if(item.status==1) {
let sceneTarget = senceData.find(sitem => sitem.sceneCode == item.sceneCode)
......@@ -68,15 +73,16 @@ Page({
sceneCodeList.push(item.sceneCode)
}
})
let idx = sceneCodeList.findIndex(item => item=='SC004')
let actNum = 0,currentId = 0;
if(idx>-1){
actNum = 3
currentId = idx
}else{
actNum = senceData.findIndex(item => item.sceneCode== sceneCodeList[0])
}
if(sceneCodeList?.length){
if(idx>-1){
actNum = 3
currentId = idx
}else{
actNum = senceData.findIndex(item => item.sceneCode== sceneCodeList[0])
}
}
this.setData({
sceneCodeList,
senceData,
......@@ -84,6 +90,13 @@ Page({
currentId
})
}
this.setData({
showPage:true
})
}).catch(err =>{
this.setData({
showPage:true
})
})
},
navbarReady(e) {
......
<view class="container">
<image wx:if="{{sceneCodeList.length>0}}" style="height: {{headerHeight+45}}px;" src="{{IMGURL}}discovery_center_bg.png" class="bg-img"></image>
<image wx:if="{{sceneCodeList.length>0 && showPage}}" style="height: {{headerHeight+45}}px;" src="{{IMGURL}}discovery_center_bg.png" class="bg-img"></image>
<navigation-bar bindnavbarReady="navbarReady" navStyle="{{navStyle}}" page-title="发现">
<text>发现</text>
</navigation-bar>
<block wx:if="{{sceneCodeList.length>0}}">
<block wx:if="{{sceneCodeList.length>0 && showPage}}">
<view style="padding-top: {{headerHeight}}px;">
<view class="header">
<swiper bindchange="changeSwiper" current="{{currentId}}" class="scene-wrap" circular="{{true}}" previousMargin="40rpx" nextMargin="40rpx">
......@@ -54,7 +54,7 @@
</view>
</view>
</block>
<block wx:else>
<block wx:if="{{sceneCodeList.length<=0 && showPage}}">
<view class="emptyData" style="margin-top: {{headerHeight+32}}px;">
<image src="{{IMGURL}}toLink.png" style="height: 400rpx;width: 400rpx;"></image>
<view class="tip">
......
......@@ -12,5 +12,6 @@ export const STORAGE_OBJECTkEY = {
app_title: 'appTitle',
auto_login_object: 'auto_login_object',
address_info: 'address_info',
srcm_shopmall_merchant_id: 'srcm_shopmall_merchant_id'
srcm_shopmall_merchant_id: 'srcm_shopmall_merchant_id',
wx_user_info: 'wx_user_info'
}
......@@ -9,10 +9,10 @@
* @param {*} onViewTrack 开启浏览埋点
* @returns
*/
// import {
// reportData
// } from '~/api/index.js'
// import USERAPI from '~/api/usersApi/index'
import {
reportData
} from '~/api/api.js'
import USERAPI from '~/api/usersApi/index'
class Share {
constructor() {
......@@ -50,13 +50,12 @@ class Share {
} = this,
path = `/${this.route}`
if (sharePath) path = `/${sharePath}`
// path += that.setCommonShareQuery()
if (shareQuery) path += `?${shareQuery}`
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)
console.log('::', path)
if (shareTrackData) that.reportShareData(shareTrackData)
return {
path,
title: shareTitle,
......@@ -74,8 +73,8 @@ class Share {
shareTrackData
} = this
if (shareFun) shareFun()
// if (shareTrackData) that.reportShareData(shareTrackData)
// shareQuery = that.setCommonShareQuery(shareQuery)
if (shareTrackData) that.reportShareData(shareTrackData)
shareQuery = that.setCommonShareQuery(shareQuery)
console.log(shareQuery)
return {
query: shareQuery,
......@@ -84,7 +83,24 @@ class Share {
}
}
}
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'),
......@@ -98,9 +114,9 @@ class Share {
const {
WXUSERINFO,
USERINFO
} = this.getCommonData()
query = `${query? `?${query}&`:'?'}merchantId=${USERINFO.merchantId}&shareOpenId=${WXUSERINFO.openId}`
if (USERINFO.phone) query += `&sharePhone=${USERINFO.phone}`
} = this.getCommonData(),
thisPage = wx.$router.getPageInstance()
query = `${query? `?${query}&`:'?'}merchantId=${thisPage.merchantId ||USERINFO.merchantId}&shareOpenId=${thisPage.shareOpenId || WXUSERINFO.openId}&sharePhone=${thisPage.sharePhone || USERINFO.phone}`
return query
}
reportShareData(shareTrackData) {
......@@ -108,7 +124,7 @@ class Share {
WXUSERINFO,
USERINFO
} = this.getCommonData(),
thisPage = wx.$router.getPageInstance()
thisPage = wx.$router.getPageInstance().options
reportData({
openId: WXUSERINFO.openId || '',
unionId: WXUSERINFO.unionId || '',
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!