Commit cecf7503 by 匡雅琴

分享事件

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