Commit fec7ae10 by zhangquan

添加埋点

1 parent c67c6b01
...@@ -124,5 +124,32 @@ class UsersApi { ...@@ -124,5 +124,32 @@ class UsersApi {
true 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 export default UsersApi
\ No newline at end of file \ No newline at end of file
...@@ -164,10 +164,25 @@ Page({ ...@@ -164,10 +164,25 @@ Page({
}); });
}, },
onRoute(options) { onRoute(options) {
},
noPageAuth : true,
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log(options)
wx.nextTick(()=>{ wx.nextTick(()=>{
let { actNum, activeNavIdx, scene } = this.options 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}` this.shareQuery = `actNum=${actNum}&activeNavIdx=${activeNavIdx}`
wx.setNavigationBarTitle({
title: senceData[actNum].name || '特色产品'
})
if(scene){ if(scene){
let qrcodeQuery = decodeURIComponent(scene) let qrcodeQuery = decodeURIComponent(scene)
let id = qrcodeQuery.split('=').pop() let id = qrcodeQuery.split('=').pop()
...@@ -188,14 +203,6 @@ Page({ ...@@ -188,14 +203,6 @@ Page({
this.setRouteParams(this.options) this.setRouteParams(this.options)
} }
}) })
},
noPageAuth : true,
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
}, },
/** /**
......
...@@ -26,37 +26,42 @@ Page({ ...@@ -26,37 +26,42 @@ Page({
isFirst: true, isFirst: true,
changeSale: 0, changeSale: 0,
sceneCodeList:[], sceneCodeList:[],
currentId: 0 currentId: 0,
showPage: false
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad(options) { onLoad(options) {
const { merchantId } = wx.$storage.get('userInfo') const { merchantId } = wx.$storage.get('userInfo')
wx.showLoading({
title: '加载中...',
})
ActivityApi.getOpenSceneList({ ActivityApi.getOpenSceneList({
merchantId merchantId
}).then(res => { }).then(res => {
wx.hideLoading()
if(res?.length>0){ if(res?.length>0){
let sceneCodeList = [] let sceneCodeList = []
let senceData = [...this.data.senceData] let senceData = [...this.data.senceData]
// let resp = [ let res = [
// { {
// sceneCode: 'SC001', sceneCode: 'SC001',
// status: 1 status: 1
// }, },
// { {
// sceneCode: 'SC002', sceneCode: 'SC002',
// status: 1 status: 1
// }, },
// { {
// sceneCode: 'SC003', sceneCode: 'SC003',
// status: 1 status: 1
// }, },
// { {
// sceneCode: 'SC004', sceneCode: 'SC004',
// status: 1 status: 1
// } }
// ] ]
res.forEach((item,index) => { res.forEach((item,index) => {
if(item.status==1) { if(item.status==1) {
let sceneTarget = senceData.find(sitem => sitem.sceneCode == item.sceneCode) let sceneTarget = senceData.find(sitem => sitem.sceneCode == item.sceneCode)
...@@ -68,15 +73,16 @@ Page({ ...@@ -68,15 +73,16 @@ Page({
sceneCodeList.push(item.sceneCode) sceneCodeList.push(item.sceneCode)
} }
}) })
let idx = sceneCodeList.findIndex(item => item=='SC004') let idx = sceneCodeList.findIndex(item => item=='SC004')
let actNum = 0,currentId = 0; let actNum = 0,currentId = 0;
if(idx>-1){ if(sceneCodeList?.length){
actNum = 3 if(idx>-1){
currentId = idx actNum = 3
}else{ currentId = idx
actNum = senceData.findIndex(item => item.sceneCode== sceneCodeList[0]) }else{
} actNum = senceData.findIndex(item => item.sceneCode== sceneCodeList[0])
}
}
this.setData({ this.setData({
sceneCodeList, sceneCodeList,
senceData, senceData,
...@@ -84,6 +90,13 @@ Page({ ...@@ -84,6 +90,13 @@ Page({
currentId currentId
}) })
} }
this.setData({
showPage:true
})
}).catch(err =>{
this.setData({
showPage:true
})
}) })
}, },
navbarReady(e) { navbarReady(e) {
......
<view class="container"> <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="发现"> <navigation-bar bindnavbarReady="navbarReady" navStyle="{{navStyle}}" page-title="发现">
<text>发现</text> <text>发现</text>
</navigation-bar> </navigation-bar>
<block wx:if="{{sceneCodeList.length>0}}"> <block wx:if="{{sceneCodeList.length>0 && showPage}}">
<view style="padding-top: {{headerHeight}}px;"> <view style="padding-top: {{headerHeight}}px;">
<view class="header"> <view class="header">
<swiper bindchange="changeSwiper" current="{{currentId}}" class="scene-wrap" circular="{{true}}" previousMargin="40rpx" nextMargin="40rpx"> <swiper bindchange="changeSwiper" current="{{currentId}}" class="scene-wrap" circular="{{true}}" previousMargin="40rpx" nextMargin="40rpx">
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
</view> </view>
</view> </view>
</block> </block>
<block wx:else> <block wx:if="{{sceneCodeList.length<=0 && showPage}}">
<view class="emptyData" style="margin-top: {{headerHeight+32}}px;"> <view class="emptyData" style="margin-top: {{headerHeight+32}}px;">
<image src="{{IMGURL}}toLink.png" style="height: 400rpx;width: 400rpx;"></image> <image src="{{IMGURL}}toLink.png" style="height: 400rpx;width: 400rpx;"></image>
<view class="tip"> <view class="tip">
......
...@@ -12,5 +12,6 @@ export const STORAGE_OBJECTkEY = { ...@@ -12,5 +12,6 @@ export const STORAGE_OBJECTkEY = {
app_title: 'appTitle', app_title: 'appTitle',
auto_login_object: 'auto_login_object', auto_login_object: 'auto_login_object',
address_info: 'address_info', 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 @@ ...@@ -9,10 +9,10 @@
* @param {*} onViewTrack 开启浏览埋点 * @param {*} onViewTrack 开启浏览埋点
* @returns * @returns
*/ */
// import { import {
// reportData reportData
// } from '~/api/index.js' } from '~/api/api.js'
// import USERAPI from '~/api/usersApi/index' import USERAPI from '~/api/usersApi/index'
class Share { class Share {
constructor() { constructor() {
...@@ -50,13 +50,12 @@ class Share { ...@@ -50,13 +50,12 @@ class Share {
} = this, } = this,
path = `/${this.route}` path = `/${this.route}`
if (sharePath) path = `/${sharePath}` if (sharePath) path = `/${sharePath}`
// path += that.setCommonShareQuery() path += that.setCommonShareQuery()
if (shareQuery) path += `?${shareQuery}` if (shareQuery) path += `&${shareQuery}`
console.log('===============', path)
if (!noPageAuth) path = `/login/loading/loading?url=${encodeURIComponent(path)}` if (!noPageAuth) path = `/login/loading/loading?url=${encodeURIComponent(path)}`
if (shareFun) shareFun() if (shareFun) shareFun()
// if (shareTrackData) that.reportShareData(shareTrackData) if (shareTrackData) that.reportShareData(shareTrackData)
console.log('::', path)
return { return {
path, path,
title: shareTitle, title: shareTitle,
...@@ -74,8 +73,8 @@ class Share { ...@@ -74,8 +73,8 @@ class Share {
shareTrackData shareTrackData
} = this } = 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 {
query: shareQuery, query: shareQuery,
...@@ -84,7 +83,24 @@ class Share { ...@@ -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() { getCommonData() {
const WXUSERINFO = wx.$storage.get('wx_user_info'), const WXUSERINFO = wx.$storage.get('wx_user_info'),
...@@ -98,9 +114,9 @@ class Share { ...@@ -98,9 +114,9 @@ class Share {
const { const {
WXUSERINFO, WXUSERINFO,
USERINFO USERINFO
} = this.getCommonData() } = this.getCommonData(),
query = `${query? `?${query}&`:'?'}merchantId=${USERINFO.merchantId}&shareOpenId=${WXUSERINFO.openId}` thisPage = wx.$router.getPageInstance()
if (USERINFO.phone) query += `&sharePhone=${USERINFO.phone}` query = `${query? `?${query}&`:'?'}merchantId=${thisPage.merchantId ||USERINFO.merchantId}&shareOpenId=${thisPage.shareOpenId || WXUSERINFO.openId}&sharePhone=${thisPage.sharePhone || USERINFO.phone}`
return query return query
} }
reportShareData(shareTrackData) { reportShareData(shareTrackData) {
...@@ -108,7 +124,7 @@ class Share { ...@@ -108,7 +124,7 @@ class Share {
WXUSERINFO, WXUSERINFO,
USERINFO USERINFO
} = this.getCommonData(), } = this.getCommonData(),
thisPage = wx.$router.getPageInstance() thisPage = wx.$router.getPageInstance().options
reportData({ reportData({
openId: WXUSERINFO.openId || '', openId: WXUSERINFO.openId || '',
unionId: WXUSERINFO.unionId || '', unionId: WXUSERINFO.unionId || '',
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!