Commit cecf7503 by 匡雅琴

分享事件

1 parent f146ae1b
import USERAPI from '~/api/usersApi/index'
import USERAPI from "~/api/usersApi/index";
import Util from "~/utils/util";
Page({
data: {
strategyDetailObj: {},
},
onLoad(options) {
this.data.enter_time =new Date().format('yyyy-MM-dd hh:mm:ss')
this.firstEnter = true
this.getStrategyDetail(options.id);
// 触发埋点
this.heartbeatFn({
......@@ -13,105 +16,107 @@ Page({
view: 1
})
},
onRoute: function (options) {
console.log(options, "000000");
this.data.enter_time =new Date().format('yyyy-MM-dd hh:mm:ss')
this.firstEnter = true
this.getStrategyDetail(options.id);
// 触发埋点
this.heartbeatFn({
id: options.id,
item_type: 6,
view: 1,
});
},
getStrategyDetail(id) {
wx.p.api.strategyApi
.getStrategyDetail({
id,
})
.then((res) => {
Util.setNavigationBarTitle(res.strategyName);
this.setData({
strategyDetailObj: res,
});
});
},
/**添加埋点开始 */
/**添加埋点开始 */
/**
* 商品-活动id,
* 商品-活动id,
* 物品类型item_type 1 商品 3活动,
* view 动作类型 1浏览 4分享 5离开页面 6心跳
* */
async addTrack(query) {
const {
id,
item_type,
view
} = query
async addTrack(query) {
const { id, item_type, view } = query;
const userInfo = wx.p.cache.userInfo.getUserInfo() || {},
{
openId
} = await USERAPI.getWXUserInfo()
{ openId } = await USERAPI.getWXUserInfo();
console.log(wx.$merchant_id, "=======");
let data = {
open_id: openId || null,
create_time: this.firstEnter ? this.data.enter_time : new Date().format('yyyy-MM-dd hh:mm:ss'), // 离开时间
create_time: this.firstEnter
? this.data.enter_time
: new Date().format("yyyy-MM-dd hh:mm:ss"), // 离开时间
enter_time: this.data.enter_time, // 进入时间
item_type,
customer_phone: userInfo.phone || null,
action_type: view,
staff_uuid: wx.p.storage.get('scrm_shopmall_staff_uuid'),
item_id: id,
business_type: 1,
add_way: 104,
merchant_id: wx.p.storage.get('srcm_shopmall_merchant_id'),
merchant_id: wx.$merchant_id,
guest_no: wx.p.$Track.getGuestNo(), //游客ID,
user_open_id:this.shareOpenId || ''
}
this.firstEnter = false
const jsonList = [JSON.stringify(data)]
user_open_id: this.shareOpenId || "",
};
this.firstEnter = false;
const jsonList = [JSON.stringify(data)];
const res = await wx.p.api.shopmallApi.trackHttp({
jsonList
})
jsonList,
});
},
heartbeatFn(query) {
this.trackQuery = query
this.addTrack(query)
this.trackQuery = query;
this.addTrack(query);
this.timer = setInterval(() => {
this.trackQuery.view = 6
this.addTrack(this.trackQuery)
}, 60 * 1e3)
this.trackQuery.view = 6;
this.addTrack(this.trackQuery);
}, 60 * 1e3);
},
/**
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
if (this.timer) clearInterval(this.timer)
this.trackQuery.view = 5
this.addTrack(this.trackQuery)
wx.$util.customerbehavior(2)
},
onUnload: function () {
if (this.timer) clearInterval(this.timer);
this.trackQuery.view = 5;
this.addTrack(this.trackQuery);
wx.$util.customerbehavior(2);
},
/**
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
const merchantId = wx.p.storage.get('srcm_shopmall_merchant_id')
const userInfo = wx.p.cache.userInfo.getUserInfo()
let {
isActivity,
isLive,
goodsInfo
} = this.data,open_id = ''
this.trackQuery.view = 4
this.addTrack(this.trackQuery)
if(userInfo)open_id = userInfo.openId
let title = goodsInfo.goodsName
let path = `${this.route}?id=${goodsInfo.id}&openId=${open_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}&isUpgrade=${this.isUpgrade || false}&isCarOwner=${this.isCarOwner || false}`
return {
imageUrl,
title,
path
}
},
onShareAppMessage: function () {
const merchantId = wx.$merchant_id;
const userInfo = wx.p.cache.userInfo.getUserInfo();
let { strategyDetailObj } = this.data,
open_id = "";
console.log(strategyDetailObj, '9999999999');
this.trackQuery.view = 4;
this.addTrack(this.trackQuery);
if (userInfo) open_id = userInfo.openId;
let title = strategyDetailObj.strategyName;
let path = `${this.route}?id=${strategyDetailObj.id}&openId=${open_id}`;
let imageUrl = strategyDetailObj.strategyImg;
if (merchantId) path = `${path}&merchantId=${merchantId}`;
console.log(path);
console.log(imageUrl, title);
return {
imageUrl,
title,
path,
};
},
});
{
"usingComponents": {
"mp-html": "../../../components/mp-html/index"
}
}
\ No newline at end of file
"usingComponents": {
"mp-html": "../../../components/mp-html/index"
}
}
......@@ -51,7 +51,6 @@ class Storage {
* @param {*} syncFlag | 同步状态,默认 false (异步),true 为同步
*/
get = (key, syncFlag = true) => {
console.log(key, '====');
// 有值默认取key值
if (key) {
// 判断值是否是指定的对象值
......
......@@ -107,12 +107,39 @@ const promise = callBack => {
})
}
//设置标题
const setNavigationBarTitle = (title) =>{
wx.getSystemInfo({
success: (res) => {
let width = res.safeArea.width / res.fontSizeSetting;
let space = '';
width = width-(title.length)/2
for (let i = 0; i < width; i++) {
space = space + ' ';
}
if (res.system.includes('iOS') === false) {
wx.setNavigationBarTitle({
title: space + title
});
} else {
wx.setNavigationBarTitle({
title: title
});
}
}
});
}
const Util = {
onReachBottom,
clearObjNull,
throttle,
isEmptyObj,
parseString,
promise
promise,
setNavigationBarTitle
}
export default Util
\ 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!