pb-sxp-ui 1.11.1 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/pb-ui.js CHANGED
@@ -847,22 +847,26 @@
847
847
  setCacheRtcList(cacheRtcList.concat(getFilterRecList(data)));
848
848
  return data;
849
849
  }), [getRecommendVideos, rtcList, waterFallData, cacheRtcList]);
850
- const refreshFeSession = React.useCallback((enableReSid) => {
850
+ const refreshFeSession = React.useCallback((enableReSid, event) => {
851
851
  var _a, _b, _c, _d, _e;
852
+ let expire = false;
852
853
  const defaultGlobalConfig = (_b = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.sxpPageConf) === null || _b === void 0 ? void 0 : _b.globalConfig;
853
854
  if ((_c = defaultGlobalConfig === null || defaultGlobalConfig === void 0 ? void 0 : defaultGlobalConfig.session) === null || _c === void 0 ? void 0 : _c.enable) {
854
855
  const sessionStartTime = localStorage.getItem('sessionStartTime');
855
- const sst = sessionStartTime ? new Date(sessionStartTime) : new Date();
856
- if (Math.floor((new Date() - sst) / (1000 * 60)) >=
856
+ const sst = sessionStartTime ? JSON.parse(sessionStartTime) : new Date().getTime();
857
+ if (Math.floor((new Date().getTime() - sst) / 1000 / 60) >=
857
858
  ((_e = (_d = defaultGlobalConfig === null || defaultGlobalConfig === void 0 ? void 0 : defaultGlobalConfig.session) === null || _d === void 0 ? void 0 : _d.expires) !== null && _e !== void 0 ? _e : 30)) {
859
+ event === null || event === void 0 ? void 0 : event('sessionTimeOut');
858
860
  refreshFeSessionId();
859
861
  curTime.current = new Date();
862
+ expire = true;
860
863
  }
861
- localStorage.setItem('sessionStartTime', new Date().toISOString());
864
+ localStorage.setItem('sessionStartTime', JSON.stringify(new Date().getTime()));
862
865
  }
863
866
  else if (enableReSid) {
864
867
  refreshFeSessionId();
865
868
  }
869
+ return expire;
866
870
  }, [data]);
867
871
  const bffEventReport = React.useCallback(({ userInfo, eventInfo, reportLayId = true }) => {
868
872
  // 关闭 BFF 事件上报
@@ -876,7 +880,6 @@
876
880
  // tpChannelId: 'H5' // 后端处理
877
881
  };
878
882
  }
879
- refreshFeSession();
880
883
  const sessionID = storeAndLoadFeSessionId();
881
884
  const ef = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ sessionID, rtc: curReqInfo.rtc, requestId: curReqInfo.requestId }, { playbookType }), (layoutVariantId && reportLayId && { layoutVariantId })), eventInfo), (getDevice$1() && { sxpDevice: getDevice$1() })), (getSystem() && { sxpSystem: getSystem() })), (getBrowserInfo() && { sxpBrowser: getBrowserInfo() })), ((eventInfo === null || eventInfo === void 0 ? void 0 : eventInfo.position) && channel && { position: Number(eventInfo === null || eventInfo === void 0 ? void 0 : eventInfo.position) + 1 + '' }));
882
885
  const realUserInfo = Object.entries(userInfo).map(([k, v]) => ({ name: k, value: v }));
@@ -892,16 +895,7 @@
892
895
  body: { userInfo: realUserInfo, eventInfo: realEventInfo },
893
896
  type: 'beacon'
894
897
  });
895
- }, [
896
- bffFetch,
897
- curReqInfo,
898
- enableReportEvent,
899
- globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview,
900
- layoutVariantId,
901
- globalConfig,
902
- playbookType,
903
- refreshFeSession
904
- ]);
898
+ }, [bffFetch, curReqInfo, enableReportEvent, globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview, layoutVariantId, globalConfig, playbookType]);
905
899
  const bffFbReport = React.useCallback(({ eventName, product }) => {
906
900
  var _a, _b, _c, _d, _e;
907
901
  if (!enableReportEvent ||
@@ -1059,7 +1053,7 @@
1059
1053
  React.useEffect(() => {
1060
1054
  if (!isShowConsent)
1061
1055
  h5EnterLink();
1062
- }, [isShowConsent, h5EnterLink]);
1056
+ }, [isShowConsent]);
1063
1057
  React.useEffect(() => {
1064
1058
  if (isShowConsent || isPreview)
1065
1059
  return;
@@ -17186,7 +17180,6 @@ Made in Italy` })));
17186
17180
  const { bffEventReport, sxpParameter, waterFallData, openHashtag, bffFbReport } = useSxpDataSource();
17187
17181
  const videoStartTime = React.useRef(0);
17188
17182
  const [isLoadFinish, setIsLoadFinish] = React.useState(false);
17189
- const [isFirstPlay, setIsFirstPlay] = React.useState(true);
17190
17183
  const { isActive } = useSwiperSlide();
17191
17184
  const canvasRef = React.useRef(null);
17192
17185
  const [firstFrameSrc, setFirstFrameSrc] = React.useState('');
@@ -17197,6 +17190,7 @@ Made in Italy` })));
17197
17190
  const hlsRef = React.useRef(null);
17198
17191
  const initTimeRef = React.useRef();
17199
17192
  const loadedTimeRef = React.useRef();
17193
+ const isFirstPlayRef = React.useRef(true);
17200
17194
  const blur = React.useMemo(() => {
17201
17195
  return (videoPostConfig === null || videoPostConfig === void 0 ? void 0 : videoPostConfig.mode) === '2';
17202
17196
  }, [videoPostConfig]);
@@ -17252,26 +17246,13 @@ Made in Italy` })));
17252
17246
  videoStartTime.current = ((_b = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) === null || _b === void 0 ? void 0 : _b.currentTime) || 0;
17253
17247
  const videoDuration = ((_d = (_c = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) === null || _c === void 0 ? void 0 : _c.duration) !== null && _d !== void 0 ? _d : 0).toFixed(2);
17254
17248
  const videoCurrentTime = ((_f = (_e = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) === null || _e === void 0 ? void 0 : _e.currentTime) !== null && _f !== void 0 ? _f : 0).toFixed(2);
17255
- const playType = isFirstPlay ? '0' : '1';
17249
+ const playType = (isFirstPlayRef === null || isFirstPlayRef === void 0 ? void 0 : isFirstPlayRef.current) ? '0' : '1';
17256
17250
  bffEventReport === null || bffEventReport === void 0 ? void 0 : bffEventReport({
17257
- eventInfo: {
17258
- eventSubject: 'playVideo',
17259
- eventDescription: 'User played the video',
17260
- contentId: (_h = (_g = item === null || item === void 0 ? void 0 : item.video) === null || _g === void 0 ? void 0 : _g.itemId) !== null && _h !== void 0 ? _h : '',
17261
- contentName: (_k = (_j = item === null || item === void 0 ? void 0 : item.video) === null || _j === void 0 ? void 0 : _j.title) !== null && _k !== void 0 ? _k : '',
17262
- playType,
17263
- startTime: videoCurrentTime,
17264
- videoDuration,
17265
- contentTags: JSON.stringify((_m = (_l = item === null || item === void 0 ? void 0 : item.video) === null || _l === void 0 ? void 0 : _l.tags) !== null && _m !== void 0 ? _m : []),
17266
- position: index + '',
17267
- contentFormat: 'video',
17268
- traceInfo: (_o = item === null || item === void 0 ? void 0 : item.video) === null || _o === void 0 ? void 0 : _o.traceInfo,
17269
- loadTime: (loadedTimeRef === null || loadedTimeRef === void 0 ? void 0 : loadedTimeRef.current) - (initTimeRef === null || initTimeRef === void 0 ? void 0 : initTimeRef.current) + ''
17270
- }
17251
+ eventInfo: Object.assign({ eventSubject: 'playVideo', eventDescription: 'User played the video', contentId: (_h = (_g = item === null || item === void 0 ? void 0 : item.video) === null || _g === void 0 ? void 0 : _g.itemId) !== null && _h !== void 0 ? _h : '', contentName: (_k = (_j = item === null || item === void 0 ? void 0 : item.video) === null || _j === void 0 ? void 0 : _j.title) !== null && _k !== void 0 ? _k : '', playType, startTime: videoCurrentTime, videoDuration, contentTags: JSON.stringify((_m = (_l = item === null || item === void 0 ? void 0 : item.video) === null || _l === void 0 ? void 0 : _l.tags) !== null && _m !== void 0 ? _m : []), position: index + '', contentFormat: 'video', traceInfo: (_o = item === null || item === void 0 ? void 0 : item.video) === null || _o === void 0 ? void 0 : _o.traceInfo }, ((isFirstPlayRef === null || isFirstPlayRef === void 0 ? void 0 : isFirstPlayRef.current) && { loadTime: (loadedTimeRef === null || loadedTimeRef === void 0 ? void 0 : loadedTimeRef.current) - (initTimeRef === null || initTimeRef === void 0 ? void 0 : initTimeRef.current) + '' }))
17271
17252
  });
17272
- setIsFirstPlay(false);
17253
+ isFirstPlayRef.current = false;
17273
17254
  }
17274
- }), [bffEventReport, data, index, isFirstPlay, videoRef === null || videoRef === void 0 ? void 0 : videoRef.current]);
17255
+ }), [bffEventReport, data, index, isFirstPlayRef, videoRef === null || videoRef === void 0 ? void 0 : videoRef.current]);
17275
17256
  const handLoadeddata = React.useCallback(() => {
17276
17257
  var _a;
17277
17258
  if (!(videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) || firstFrameSrc || !blur)
@@ -17630,13 +17611,14 @@ Made in Italy` })));
17630
17611
 
17631
17612
  const PictureGroup$2 = ({ imgUrls, width, height, rec, index, onViewImageEndEvent, onViewImageStartEvent, imgUrlsPostConfig }) => {
17632
17613
  var _a, _b;
17633
- const swiperRef = React.useRef();
17634
17614
  const { isActive } = useSwiperSlide();
17635
17615
  const { sxpParameter, openHashtag } = useSxpDataSource();
17636
17616
  const [isLoad, setIsLoad] = React.useState(false);
17637
17617
  const [imgInfo, setImgInfo] = React.useState();
17638
- const initTime = new Date();
17639
17618
  const [swiperActiveIndex, setSwiperActiveIndex] = React.useState(0);
17619
+ const swiperRef = React.useRef();
17620
+ const isFirstPlayRef = React.useRef(true);
17621
+ const initTime = new Date();
17640
17622
  React.useEffect(() => {
17641
17623
  if (isLoad && isActive) {
17642
17624
  (swiperRef === null || swiperRef === void 0 ? void 0 : swiperRef.current) && swiperRef.current.swiper.autoplay.start();
@@ -17644,7 +17626,8 @@ Made in Italy` })));
17644
17626
  onViewImageEndEvent(rec);
17645
17627
  }
17646
17628
  else {
17647
- onViewImageStartEvent(index, imgInfo, true);
17629
+ onViewImageStartEvent(index, isFirstPlayRef.current ? imgInfo : undefined, true);
17630
+ isFirstPlayRef.current = false;
17648
17631
  }
17649
17632
  }
17650
17633
  else {
@@ -17999,7 +17982,7 @@ Made in Italy` })));
17999
17982
  * @Author: binruan@chatlabs.com
18000
17983
  * @Date: 2024-03-20 10:27:31
18001
17984
  * @LastEditors: binruan@chatlabs.com
18002
- * @LastEditTime: 2024-12-16 15:03:38
17985
+ * @LastEditTime: 2024-12-17 15:46:14
18003
17986
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\index.tsx
18004
17987
  *
18005
17988
  */
@@ -18059,10 +18042,46 @@ Made in Italy` })));
18059
18042
  if (index !== -1)
18060
18043
  (_a = swiperRef === null || swiperRef === void 0 ? void 0 : swiperRef.current) === null || _a === void 0 ? void 0 : _a.swiper.slideTo(index);
18061
18044
  }, [data, ctaType, swiperRef]);
18045
+ const handleSessionCompleted = React.useCallback((fk) => {
18046
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
18047
+ const item = data === null || data === void 0 ? void 0 : data[activeIndex];
18048
+ let fromKName = '';
18049
+ if (popupDetailData && (((_b = (_a = item === null || item === void 0 ? void 0 : item.video) === null || _a === void 0 ? void 0 : _a.bindProducts) === null || _b === void 0 ? void 0 : _b.length) || ((_c = item === null || item === void 0 ? void 0 : item.video) === null || _c === void 0 ? void 0 : _c.bindProduct))) {
18050
+ fromKName = 'pdpPage';
18051
+ }
18052
+ else if (popupDetailData && ((_g = tempMap === null || tempMap === void 0 ? void 0 : tempMap[(_f = (_e = (_d = item === null || item === void 0 ? void 0 : item.video) === null || _d === void 0 ? void 0 : _d.bindCta) === null || _e === void 0 ? void 0 : _e.itemId) !== null && _f !== void 0 ? _f : ''].item) === null || _g === void 0 ? void 0 : _g.type) === 'Appoint') {
18053
+ fromKName = 'formPage';
18054
+ }
18055
+ else if (isFromHashtag) {
18056
+ fromKName = 'hashTagPage';
18057
+ }
18058
+ else if ((_h = item === null || item === void 0 ? void 0 : item.video) === null || _h === void 0 ? void 0 : _h.url) {
18059
+ fromKName = 'videoPage';
18060
+ }
18061
+ else if (((_j = item === null || item === void 0 ? void 0 : item.video) === null || _j === void 0 ? void 0 : _j.imgUrls) && ((_l = (_k = item === null || item === void 0 ? void 0 : item.video) === null || _k === void 0 ? void 0 : _k.imgUrls) === null || _l === void 0 ? void 0 : _l.length)) {
18062
+ fromKName = 'imagePage';
18063
+ }
18064
+ else if (item === null || item === void 0 ? void 0 : item.product) {
18065
+ fromKName = 'productPage';
18066
+ }
18067
+ bffEventReport === null || bffEventReport === void 0 ? void 0 : bffEventReport({
18068
+ eventInfo: {
18069
+ sessionDuration: Math.floor((new Date() - curTime.current) / 1000) + '',
18070
+ eventSubject: 'sessionCompleted',
18071
+ eventDescription: 'Session completed',
18072
+ contentId: (_m = item === null || item === void 0 ? void 0 : item.video) === null || _m === void 0 ? void 0 : _m.itemId,
18073
+ productId: (_o = item === null || item === void 0 ? void 0 : item.product) === null || _o === void 0 ? void 0 : _o.itemId,
18074
+ position: activeIndex + '',
18075
+ fromKName: fk ? fk : fromKName,
18076
+ fromKPage: location === null || location === void 0 ? void 0 : location.href,
18077
+ ctatId: (_r = (_q = (_p = item === null || item === void 0 ? void 0 : item.video) === null || _p === void 0 ? void 0 : _p.bindCta) === null || _q === void 0 ? void 0 : _q.itemId) !== null && _r !== void 0 ? _r : '',
18078
+ traceInfo: (_v = (_t = (_s = item === null || item === void 0 ? void 0 : item.video) === null || _s === void 0 ? void 0 : _s.traceInfo) !== null && _t !== void 0 ? _t : (_u = item === null || item === void 0 ? void 0 : item.product) === null || _u === void 0 ? void 0 : _u.traceInfo) !== null && _v !== void 0 ? _v : ''
18079
+ }
18080
+ });
18081
+ }, [data, bffEventReport, activeIndex, popupDetailData, tempMap, isFromHashtag, curTime]);
18062
18082
  React.useEffect(() => {
18063
18083
  const item = data === null || data === void 0 ? void 0 : data[activeIndex];
18064
18084
  const visibleChange = () => {
18065
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
18066
18085
  const repCond = !openHashtag && !isShowConsent;
18067
18086
  if (document.visibilityState === 'hidden') {
18068
18087
  // 当用户导航到新页面、切换标签页、关闭标签页、最小化或关闭浏览器、刷新原页面(即离开原页面时),或者在移动设备上从浏览器切换到不同的应用程序时
@@ -18071,40 +18090,10 @@ Made in Italy` })));
18071
18090
  SXP_EVENT_BUS.emit(SXP_EVENT_TYPE.PAGE_DID_HIDE, item);
18072
18091
  handleReportProductView(item);
18073
18092
  }
18074
- let fromKName = '';
18075
- if (popupDetailData && (((_b = (_a = item === null || item === void 0 ? void 0 : item.video) === null || _a === void 0 ? void 0 : _a.bindProducts) === null || _b === void 0 ? void 0 : _b.length) || ((_c = item === null || item === void 0 ? void 0 : item.video) === null || _c === void 0 ? void 0 : _c.bindProduct))) {
18076
- fromKName = 'pdpPage';
18077
- }
18078
- else if (popupDetailData && ((_g = tempMap === null || tempMap === void 0 ? void 0 : tempMap[(_f = (_e = (_d = item === null || item === void 0 ? void 0 : item.video) === null || _d === void 0 ? void 0 : _d.bindCta) === null || _e === void 0 ? void 0 : _e.itemId) !== null && _f !== void 0 ? _f : ''].item) === null || _g === void 0 ? void 0 : _g.type) === 'Appoint') {
18079
- fromKName = 'formPage';
18080
- }
18081
- else if (isFromHashtag) {
18082
- fromKName = 'hashTagPage';
18083
- }
18084
- else if ((_h = item === null || item === void 0 ? void 0 : item.video) === null || _h === void 0 ? void 0 : _h.url) {
18085
- fromKName = 'videoPage';
18086
- }
18087
- else if (((_j = item === null || item === void 0 ? void 0 : item.video) === null || _j === void 0 ? void 0 : _j.imgUrls) && ((_l = (_k = item === null || item === void 0 ? void 0 : item.video) === null || _k === void 0 ? void 0 : _k.imgUrls) === null || _l === void 0 ? void 0 : _l.length)) {
18088
- fromKName = 'imagePage';
18089
- }
18090
- else if (item === null || item === void 0 ? void 0 : item.product) {
18091
- fromKName = 'productPage';
18092
- }
18093
18093
  if ((globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.playbook) !== 'organic menu' || activeIndex !== 0 || channel) {
18094
- bffEventReport === null || bffEventReport === void 0 ? void 0 : bffEventReport({
18095
- eventInfo: {
18096
- sessionDuration: Math.floor((new Date() - curTime.current) / 1000) + '',
18097
- eventSubject: 'sessionCompleted',
18098
- eventDescription: 'Session completed',
18099
- contentId: (_m = item === null || item === void 0 ? void 0 : item.video) === null || _m === void 0 ? void 0 : _m.itemId,
18100
- productId: (_o = item === null || item === void 0 ? void 0 : item.product) === null || _o === void 0 ? void 0 : _o.itemId,
18101
- position: activeIndex + '',
18102
- fromKName,
18103
- fromKPage: location === null || location === void 0 ? void 0 : location.href,
18104
- ctatId: (_r = (_q = (_p = item === null || item === void 0 ? void 0 : item.video) === null || _p === void 0 ? void 0 : _p.bindCta) === null || _q === void 0 ? void 0 : _q.itemId) !== null && _r !== void 0 ? _r : '',
18105
- traceInfo: (_v = (_t = (_s = item === null || item === void 0 ? void 0 : item.video) === null || _s === void 0 ? void 0 : _s.traceInfo) !== null && _t !== void 0 ? _t : (_u = item === null || item === void 0 ? void 0 : item.product) === null || _u === void 0 ? void 0 : _u.traceInfo) !== null && _v !== void 0 ? _v : ''
18106
- }
18107
- });
18094
+ const isExpire = refreshFeSession === null || refreshFeSession === void 0 ? void 0 : refreshFeSession(true, handleSessionCompleted);
18095
+ if (!isExpire)
18096
+ handleSessionCompleted();
18108
18097
  }
18109
18098
  }
18110
18099
  else if (document.visibilityState === 'visible') {
@@ -18137,8 +18126,24 @@ Made in Italy` })));
18137
18126
  openHashtag,
18138
18127
  isShowConsent,
18139
18128
  selectTag,
18140
- channel
18129
+ channel,
18130
+ handleSessionCompleted,
18131
+ refreshFeSession
18141
18132
  ]);
18133
+ const handleSessionExpire = React.useCallback(lodash.debounce(() => {
18134
+ refreshFeSession === null || refreshFeSession === void 0 ? void 0 : refreshFeSession(false, handleSessionCompleted);
18135
+ }, 1000), [handleSessionCompleted, refreshFeSession]);
18136
+ React.useEffect(() => {
18137
+ const events = ['touchstart', 'touchcancel'];
18138
+ events.forEach((event) => {
18139
+ window.addEventListener(event, handleSessionExpire);
18140
+ });
18141
+ return () => {
18142
+ events.forEach((event) => {
18143
+ window.removeEventListener(event, handleSessionExpire);
18144
+ });
18145
+ };
18146
+ }, [handleSessionExpire]);
18142
18147
  const tagHeight = React.useMemo(() => {
18143
18148
  let h = 0;
18144
18149
  if (tagList.length > 0) {