Authored by 陈峰

Merge branch 'feature/home-optimization' into 'release/6.9.4'

Feature/home optimization



See merge request !1762
... ... @@ -21,7 +21,7 @@
{{/ifcond}}
{{#ifcond layout_float '==' 'C'}}
{{#if data.prdList}}
<div class="resource-collage-buy-prd-list-c" data-prd-list-length="{{data.prdList.length}}" data-prd-speed="{{speed}}">
<div class="resource-collage-buy-prd-list-c templates" data-f-name="{{../template_name}}" data-f-id="{{../template_id}}" data-id="{{@index}}" data-prd-list-length="{{data.prdList.length}}" data-prd-speed="{{speed}}">
{{!-- <div class="collage-buy-title">{{../template_intro}}</div> --}}
<div class="collage-buy-title">今日必拼</div>
<div class="swiper-container1 swiper-container">
... ...
<div class="banner-top">
<div class="banner-top templates" data-f-name="{{template_name}}" data-f-id="{{template_id}}" data-id="{{@index}}">
<div class="banner-swiper swiper-container">
<ul class="swiper-wrapper">
{{#each data}}
... ...
<div id='fixedTab' class="guess-like">
<div id='fixedTab' class="guess-like templates" data-template-name="{{template_name}}" data-template-id="{{template_id}}" data-id="{{@index}}">
<div class="wapper">
<div class="guess-scroll">
{{#each data}}
... ...
<div class="new-index-filter-list-item" data-activity-id="{{activity_id}}" data-product-skn="{{product_skn}}">
<div class="new-index-filter-list-item" data-item-idx="{{@index}}" data-activity-id="{{activity_id}}" data-product-skn="{{product_skn}}">
<div class="group-product-header">
{{#ifcond joinLimitStr "==" "邀新团"}}
<div class="new-group-product-left-icon">
... ...
{{#data}}
<div class="resource-single">
<div class="resource-single templates" data-f-name="{{../template_name}}" data-f-id="{{../template_id}}" data-id="{{@index}}">
{{#if title}}
<div class="title">
<div class='line'></div>
... ...
{{#data}}
<div class="split-image" {{#ifcond ../is_extend '!==' '1'}}style="margin: 0 15px"{{/ifcond}}>
<div class="split-image templates" data-id="{{@index}}" data-f-name="{{../template_name}}" data-f-id="{{../template_id}}" {{#ifcond ../is_extend '!==' '1'}}style="margin: 0 15px"{{/ifcond}}>
<img src="{{image2 src w=../image_width h=../image_height q=60 mode=3}}"></img>
<div class='url-content'>
{{#each urls}}
... ...
{{#data}}
<div class="resource-two-image">
<div class="resource-two-image templates" data-id="{{@../index}}">
{{#each list}}
<div class="img-item">
<a href="{{url}}" id="{{../template_id}}" name="{{../template_intro}}">
... ...
<div class="new-index-filter-list-item" data-activity-id="{{activity_id}}" data-product-skn="{{product_skn}}">
<div class="new-index-filter-list-item" data-item-idx="{{@index}}" data-activity-id="{{activity_id}}" data-product-skn="{{product_skn}}">
<div class="group-product-header">
{{#ifcond joinLimitStr "==" "邀新团"}}
<div class="new-group-product-left-icon">
... ...
import qs from 'yoho-qs';
const yoho = require('js/yoho-app');
const _ = require('lodash');
class ResourceShowYasRpter {
constructor() {
this.timer = null;
this.reportParams = {
C_ID: qs.physical_channel || 1,
DATA: []
};
this.lastShowSkns = [];
window.onscroll = _.throttle(() => {
this.reportCtl();
}, 100);
this.report();
}
getPname() {
let isiOS = yoho.isiOS;
let isAndroid = yoho.isAndroid;
let P_NAME = 'h5FP_CollageHome';
if (isAndroid) {
P_NAME = 'aFP_CollageHome';
}
if (isiOS) {
P_NAME = 'iFP_CollageHome';
}
return P_NAME;
}
reportCtl() {
if (this.timer) {
clearTimeout(this.timer);
}
this.timer = setTimeout(() => {
this.reportParams.DATA = [];
this.report();
}, 300);
}
/**
* 这个链接是否是商品
*/
theAisGoods(slideClass, aIndex) {
if (
slideClass.indexOf('swiper-slide-active') !== -1 ||
slideClass.indexOf('swiper-slide-next') !== -1
) {
this.aIndex = aIndex;
return true;
} else if (this.aIndex) {
this.aIndex = false;
return true;
} else {
this.aIndex = false;
return false;
}
}
report() {
let cacheTheShowSkns = []; // 暂存此次上报的楼层,上报后复制给 lastReportSkns
$('.templates').each((floorIndex, theFloor) => {
let $theFloor = $(theFloor);
let F_INDEX = $theFloor.data('id') + 1;
let floorsRawArr = []; // 当前展示楼层
let F_ID = $theFloor.data('f-id');
let F_NAME = $theFloor.data('f-name');
if ($.inviewport($theFloor, { threshold: 0 })) {
// 楼层可见
$theFloor.find('ul > li').each((aIndex, theA) => {
let $theA = $(theA);
let href = $theA.attr('data-href');
F_INDEX = $theFloor.data('id') + 1;
if ($.inviewport($theA, { threshold: 0 }) && href) {
floorsRawArr.push({
href: href,
I_INDEX: aIndex + 1,
F_INDEX,
F_ID,
F_NAME
});
}
});
$theFloor.find('.split-item').each((aIndex, theA) => {
let $theA = $(theA);
let href = $theA.data('href');
F_INDEX = $theFloor.data('id') + 1;
if ($.inviewport($theA, { threshold: 0 }) && href) {
floorsRawArr.push({
href: href,
I_INDEX: aIndex + 1,
F_INDEX,
F_ID,
F_NAME
});
}
});
$theFloor.find('.swiper-slide-1').each((aIndex, theA) => {
let $theA = $(theA);
let productSkn = $theA.data('product-skn');
let itemIndex = $theA.data('item-idx');
F_INDEX = $theFloor.data('id') + 1;
if (
$.inviewport($theA, { threshold: 0 }) &&
productSkn &&
this.theAisGoods($(theA).attr('class'), aIndex)
) {
floorsRawArr.push({
href: '',
PRD_SKN: productSkn,
I_INDEX: itemIndex + 1,
F_INDEX,
F_ID,
F_NAME
});
}
});
}
if (floorsRawArr.length) { // 本楼层有符合上报条件的商品
for (let goodsRawObj of floorsRawArr) {
let newParams = {
P_NAME: this.getPname(),
P_PARAM: goodsRawObj.href && goodsRawObj.href.split('?')[0] || '',
F_INDEX: goodsRawObj.F_INDEX,
I_INDEX: goodsRawObj.I_INDEX,
F_ID: goodsRawObj.F_ID,
F_NAME: goodsRawObj.F_NAME
};
if (goodsRawObj.PRD_SKN) {
newParams.PRD_SKN = goodsRawObj.PRD_SKN;
newParams.ACTION_URL = '';
} else {
newParams.ACTION_URL = goodsRawObj.href;
}
this.reportParams.DATA.push(newParams);
}
}
});
$('.new-goods-list').each((floorIndex, theFloor) => {
let currentState = history.state;
let $theFloor = $(theFloor);
let F_INDEX = (currentState.index_idx || 0) + 2;
let TAB_NAME = currentState.tab_name;
let F_ID = currentState.template_id;
let F_NAME = currentState.template_name;
let floorsRawArr = [];
$theFloor.find('.new-index-filter-list-item').each((aIndex, theA) => {
let $theA = $(theA);
let productSkn = $theA.data('product-skn');
let itemIndex = $theA.data('item-idx');
if (
$.inviewport($theA, { threshold: 0 }) &&
productSkn
) {
floorsRawArr.push({
href: '',
PRD_SKN: productSkn,
I_INDEX: itemIndex + 1,
F_INDEX,
F_ID,
TAB_NAME,
F_NAME
});
}
});
if (floorsRawArr.length) { // 本楼层有符合上报条件的商品
for (let goodsRawObj of floorsRawArr) {
let indexInLast = this.lastShowSkns.indexOf(goodsRawObj.PRD_SKN);
if (indexInLast < 0) {
let newParams = {
P_NAME: this.getPname(),
P_PARAM: goodsRawObj.href && goodsRawObj.href.split('?')[0] || '',
F_INDEX: goodsRawObj.F_INDEX,
I_INDEX: goodsRawObj.I_INDEX,
F_ID: goodsRawObj.F_ID,
F_NAME: goodsRawObj.F_NAME,
TAB_NAME: goodsRawObj.TAB_NAME,
PRD_SKN: goodsRawObj.PRD_SKN,
ACTION_URL: ''
};
this.reportParams.DATA.push(newParams);
}
cacheTheShowSkns.push(goodsRawObj.PRD_SKN);
}
}
});
this.lastShowSkns = cacheTheShowSkns;
setTimeout(() => {
if (typeof window._yas !== 'undefined' && window._yas.sendCustomInfo &&
this.reportParams.DATA && this.reportParams.DATA.length) {
window._yas.sendCustomInfo({
op: 'YB_SHOW_EVENT',
appop: 'YB_SHOW_EVENT',
param: JSON.stringify(this.reportParams)
}, true);
}
}, 1000);
}
}
export default new ResourceShowYasRpter();
... ...
... ... @@ -214,8 +214,8 @@ class Group extends Page {
checkDetail(e) {
let $this = $(e.currentTarget);
let productSkn = $this.data('product-skn');
let isFloor = $this.data('is-floor');
let activityId = $this.data('activity-id');
let templateId = $this.data('template-id');
let isApp = $('.group').data('is-App');
let isiOS = yoho.isiOS;
let isAndroid = yoho.isAndroid;
... ... @@ -227,11 +227,20 @@ class Group extends Page {
if (isiOS) {
P_NAME = 'iFP_CollageHome';
}
if (isFloor) {
if (templateId) {
this.sendCustomInfo($this, {PRD_SKN: productSkn});
} else {
this.sendCustomInfo($this, {
F_ID: this.templateId,
F_NAME: this.templateName,
TAB_ID: this.tabName,
TAB_NAME: this.tabName,
F_INDEX: this.indexIdx
});
}
console.log(this.indexIdx);
if (isApp) {
let param = {
action: 'go.productDetail',
... ... @@ -239,7 +248,8 @@ class Group extends Page {
product_skn: productSkn,
activity_id: activityId,
activity_type: 'groupPurchase',
P_NAME
P_NAME,
FP_NAME: P_NAME
}
};
let paramStr = JSON.stringify(param);
... ... @@ -247,7 +257,7 @@ class Group extends Page {
paramStr = `?activityId=${activityId}&productSkn=${productSkn}&openby:yohobuy=${paramStr}`;
window.location.href = `/activity/group/detail?${paramStr}`;
} else {
window.location.href = `/activity/group/detail?activityId=${activityId}&productSkn=${productSkn}`;
// window.location.href = `/activity/group/detail?activityId=${activityId}&productSkn=${productSkn}`;
}
}
... ... @@ -255,10 +265,29 @@ class Group extends Page {
let $this = $(e.currentTarget);
let query = $this.data('query');
let index = $this.data('index');
let tabName = $this.data('tab-name');
let templateName = $this.data('template-name');
let templateId = $this.data('template-id');
let indexIdx = $this.data('index-idx');
let queryObject = {};
let newNavType = this.judgeNavType(this.newFilterTab);
let newNav = this.newNavInfo[newNavType];
this.tabName = tabName;
this.templateId = templateId;
this.templateName = templateName;
this.indexIdx = indexIdx;
let stateObj = {
tab_name: this.tabName,
index_idx: this.indexIdx,
template_id: templateId,
template_name: templateName
};
let url = window.location.href;
let valiable = url.split('?')[0];
window.history.replaceState(stateObj, 'page', valiable);
this.sendCustomInfo($this, {});
query.forEach(item => {
queryObject = Object.assign(queryObject, item);
... ... @@ -680,6 +709,23 @@ class Group extends Page {
// 筛选初始化
filterInit() {
$('.guess-scroll').find('div:first-child').children('div').addClass('guess-tab-active');
let first = $('.guess-scroll').find('div:first-child');
this.tabName = first.data('tab-name');
this.templateName = first.data('template-name');
this.templateId = first.data('template-id');
this.indexIdx = first.data('index-idx');
let stateObj = {
tab_name: this.tabName,
index_idx: this.indexIdx,
template_id: this.templateId,
template_name: this.templateName
};
let url = window.location.href;
let valiable = url.split('?')[0];
window.history.replaceState(stateObj, 'page', valiable);
// let selectedChannel = this.selectedChannel;
// let requestParams = {
... ... @@ -720,4 +766,5 @@ class Group extends Page {
$(() => {
new Group();
require('./feature/resource-show-yas-rpter');
});
... ...