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/index.cjs CHANGED
@@ -854,22 +854,26 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
854
854
  setCacheRtcList(cacheRtcList.concat(getFilterRecList(data)));
855
855
  return data;
856
856
  }), [getRecommendVideos, rtcList, waterFallData, cacheRtcList]);
857
- const refreshFeSession = React.useCallback((enableReSid) => {
857
+ const refreshFeSession = React.useCallback((enableReSid, event) => {
858
858
  var _a, _b, _c, _d, _e;
859
+ let expire = false;
859
860
  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;
860
861
  if ((_c = defaultGlobalConfig === null || defaultGlobalConfig === void 0 ? void 0 : defaultGlobalConfig.session) === null || _c === void 0 ? void 0 : _c.enable) {
861
862
  const sessionStartTime = localStorage.getItem('sessionStartTime');
862
- const sst = sessionStartTime ? new Date(sessionStartTime) : new Date();
863
- if (Math.floor((new Date() - sst) / (1000 * 60)) >=
863
+ const sst = sessionStartTime ? JSON.parse(sessionStartTime) : new Date().getTime();
864
+ if (Math.floor((new Date().getTime() - sst) / 1000 / 60) >=
864
865
  ((_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)) {
866
+ event === null || event === void 0 ? void 0 : event('sessionTimeOut');
865
867
  refreshFeSessionId();
866
868
  curTime.current = new Date();
869
+ expire = true;
867
870
  }
868
- localStorage.setItem('sessionStartTime', new Date().toISOString());
871
+ localStorage.setItem('sessionStartTime', JSON.stringify(new Date().getTime()));
869
872
  }
870
873
  else if (enableReSid) {
871
874
  refreshFeSessionId();
872
875
  }
876
+ return expire;
873
877
  }, [data]);
874
878
  const bffEventReport = React.useCallback(({ userInfo, eventInfo, reportLayId = true }) => {
875
879
  // 关闭 BFF 事件上报
@@ -883,7 +887,6 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
883
887
  // tpChannelId: 'H5' // 后端处理
884
888
  };
885
889
  }
886
- refreshFeSession();
887
890
  const sessionID = storeAndLoadFeSessionId();
888
891
  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 + '' }));
889
892
  const realUserInfo = Object.entries(userInfo).map(([k, v]) => ({ name: k, value: v }));
@@ -899,16 +902,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
899
902
  body: { userInfo: realUserInfo, eventInfo: realEventInfo },
900
903
  type: 'beacon'
901
904
  });
902
- }, [
903
- bffFetch,
904
- curReqInfo,
905
- enableReportEvent,
906
- globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview,
907
- layoutVariantId,
908
- globalConfig,
909
- playbookType,
910
- refreshFeSession
911
- ]);
905
+ }, [bffFetch, curReqInfo, enableReportEvent, globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview, layoutVariantId, globalConfig, playbookType]);
912
906
  const bffFbReport = React.useCallback(({ eventName, product }) => {
913
907
  var _a, _b, _c, _d, _e;
914
908
  if (!enableReportEvent ||
@@ -1066,7 +1060,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
1066
1060
  React.useEffect(() => {
1067
1061
  if (!isShowConsent)
1068
1062
  h5EnterLink();
1069
- }, [isShowConsent, h5EnterLink]);
1063
+ }, [isShowConsent]);
1070
1064
  React.useEffect(() => {
1071
1065
  if (isShowConsent || isPreview)
1072
1066
  return;
@@ -17193,7 +17187,6 @@ const VideoWidget$2 = ({ rec, index, height, data, muted, activeIndex, videoPost
17193
17187
  const { bffEventReport, sxpParameter, waterFallData, openHashtag, bffFbReport } = useSxpDataSource();
17194
17188
  const videoStartTime = React.useRef(0);
17195
17189
  const [isLoadFinish, setIsLoadFinish] = React.useState(false);
17196
- const [isFirstPlay, setIsFirstPlay] = React.useState(true);
17197
17190
  const { isActive } = useSwiperSlide();
17198
17191
  const canvasRef = React.useRef(null);
17199
17192
  const [firstFrameSrc, setFirstFrameSrc] = React.useState('');
@@ -17204,6 +17197,7 @@ const VideoWidget$2 = ({ rec, index, height, data, muted, activeIndex, videoPost
17204
17197
  const hlsRef = React.useRef(null);
17205
17198
  const initTimeRef = React.useRef();
17206
17199
  const loadedTimeRef = React.useRef();
17200
+ const isFirstPlayRef = React.useRef(true);
17207
17201
  const blur = React.useMemo(() => {
17208
17202
  return (videoPostConfig === null || videoPostConfig === void 0 ? void 0 : videoPostConfig.mode) === '2';
17209
17203
  }, [videoPostConfig]);
@@ -17259,26 +17253,13 @@ const VideoWidget$2 = ({ rec, index, height, data, muted, activeIndex, videoPost
17259
17253
  videoStartTime.current = ((_b = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) === null || _b === void 0 ? void 0 : _b.currentTime) || 0;
17260
17254
  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);
17261
17255
  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);
17262
- const playType = isFirstPlay ? '0' : '1';
17256
+ const playType = (isFirstPlayRef === null || isFirstPlayRef === void 0 ? void 0 : isFirstPlayRef.current) ? '0' : '1';
17263
17257
  bffEventReport === null || bffEventReport === void 0 ? void 0 : bffEventReport({
17264
- eventInfo: {
17265
- eventSubject: 'playVideo',
17266
- eventDescription: 'User played the video',
17267
- 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 : '',
17268
- 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 : '',
17269
- playType,
17270
- startTime: videoCurrentTime,
17271
- videoDuration,
17272
- 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 : []),
17273
- position: index + '',
17274
- contentFormat: 'video',
17275
- traceInfo: (_o = item === null || item === void 0 ? void 0 : item.video) === null || _o === void 0 ? void 0 : _o.traceInfo,
17276
- loadTime: (loadedTimeRef === null || loadedTimeRef === void 0 ? void 0 : loadedTimeRef.current) - (initTimeRef === null || initTimeRef === void 0 ? void 0 : initTimeRef.current) + ''
17277
- }
17258
+ 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) + '' }))
17278
17259
  });
17279
- setIsFirstPlay(false);
17260
+ isFirstPlayRef.current = false;
17280
17261
  }
17281
- }), [bffEventReport, data, index, isFirstPlay, videoRef === null || videoRef === void 0 ? void 0 : videoRef.current]);
17262
+ }), [bffEventReport, data, index, isFirstPlayRef, videoRef === null || videoRef === void 0 ? void 0 : videoRef.current]);
17282
17263
  const handLoadeddata = React.useCallback(() => {
17283
17264
  var _a;
17284
17265
  if (!(videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) || firstFrameSrc || !blur)
@@ -17637,13 +17618,14 @@ const Picture = (props) => {
17637
17618
 
17638
17619
  const PictureGroup$2 = ({ imgUrls, width, height, rec, index, onViewImageEndEvent, onViewImageStartEvent, imgUrlsPostConfig }) => {
17639
17620
  var _a, _b;
17640
- const swiperRef = React.useRef();
17641
17621
  const { isActive } = useSwiperSlide();
17642
17622
  const { sxpParameter, openHashtag } = useSxpDataSource();
17643
17623
  const [isLoad, setIsLoad] = React.useState(false);
17644
17624
  const [imgInfo, setImgInfo] = React.useState();
17645
- const initTime = new Date();
17646
17625
  const [swiperActiveIndex, setSwiperActiveIndex] = React.useState(0);
17626
+ const swiperRef = React.useRef();
17627
+ const isFirstPlayRef = React.useRef(true);
17628
+ const initTime = new Date();
17647
17629
  React.useEffect(() => {
17648
17630
  if (isLoad && isActive) {
17649
17631
  (swiperRef === null || swiperRef === void 0 ? void 0 : swiperRef.current) && swiperRef.current.swiper.autoplay.start();
@@ -17651,7 +17633,8 @@ const PictureGroup$2 = ({ imgUrls, width, height, rec, index, onViewImageEndEven
17651
17633
  onViewImageEndEvent(rec);
17652
17634
  }
17653
17635
  else {
17654
- onViewImageStartEvent(index, imgInfo, true);
17636
+ onViewImageStartEvent(index, isFirstPlayRef.current ? imgInfo : undefined, true);
17637
+ isFirstPlayRef.current = false;
17655
17638
  }
17656
17639
  }
17657
17640
  else {
@@ -18006,7 +17989,7 @@ var NavBack$1 = React.memo(NavBack);
18006
17989
  * @Author: binruan@chatlabs.com
18007
17990
  * @Date: 2024-03-20 10:27:31
18008
17991
  * @LastEditors: binruan@chatlabs.com
18009
- * @LastEditTime: 2024-12-16 15:03:38
17992
+ * @LastEditTime: 2024-12-17 15:46:14
18010
17993
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\index.tsx
18011
17994
  *
18012
17995
  */
@@ -18066,10 +18049,46 @@ const SxpPageRender = ({ globalConfig, descStyle, containerHeight = window.inner
18066
18049
  if (index !== -1)
18067
18050
  (_a = swiperRef === null || swiperRef === void 0 ? void 0 : swiperRef.current) === null || _a === void 0 ? void 0 : _a.swiper.slideTo(index);
18068
18051
  }, [data, ctaType, swiperRef]);
18052
+ const handleSessionCompleted = React.useCallback((fk) => {
18053
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
18054
+ const item = data === null || data === void 0 ? void 0 : data[activeIndex];
18055
+ let fromKName = '';
18056
+ 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))) {
18057
+ fromKName = 'pdpPage';
18058
+ }
18059
+ 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') {
18060
+ fromKName = 'formPage';
18061
+ }
18062
+ else if (isFromHashtag) {
18063
+ fromKName = 'hashTagPage';
18064
+ }
18065
+ else if ((_h = item === null || item === void 0 ? void 0 : item.video) === null || _h === void 0 ? void 0 : _h.url) {
18066
+ fromKName = 'videoPage';
18067
+ }
18068
+ 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)) {
18069
+ fromKName = 'imagePage';
18070
+ }
18071
+ else if (item === null || item === void 0 ? void 0 : item.product) {
18072
+ fromKName = 'productPage';
18073
+ }
18074
+ bffEventReport === null || bffEventReport === void 0 ? void 0 : bffEventReport({
18075
+ eventInfo: {
18076
+ sessionDuration: Math.floor((new Date() - curTime.current) / 1000) + '',
18077
+ eventSubject: 'sessionCompleted',
18078
+ eventDescription: 'Session completed',
18079
+ contentId: (_m = item === null || item === void 0 ? void 0 : item.video) === null || _m === void 0 ? void 0 : _m.itemId,
18080
+ productId: (_o = item === null || item === void 0 ? void 0 : item.product) === null || _o === void 0 ? void 0 : _o.itemId,
18081
+ position: activeIndex + '',
18082
+ fromKName: fk ? fk : fromKName,
18083
+ fromKPage: location === null || location === void 0 ? void 0 : location.href,
18084
+ 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 : '',
18085
+ 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 : ''
18086
+ }
18087
+ });
18088
+ }, [data, bffEventReport, activeIndex, popupDetailData, tempMap, isFromHashtag, curTime]);
18069
18089
  React.useEffect(() => {
18070
18090
  const item = data === null || data === void 0 ? void 0 : data[activeIndex];
18071
18091
  const visibleChange = () => {
18072
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
18073
18092
  const repCond = !openHashtag && !isShowConsent;
18074
18093
  if (document.visibilityState === 'hidden') {
18075
18094
  // 当用户导航到新页面、切换标签页、关闭标签页、最小化或关闭浏览器、刷新原页面(即离开原页面时),或者在移动设备上从浏览器切换到不同的应用程序时
@@ -18078,40 +18097,10 @@ const SxpPageRender = ({ globalConfig, descStyle, containerHeight = window.inner
18078
18097
  SXP_EVENT_BUS.emit(SXP_EVENT_TYPE.PAGE_DID_HIDE, item);
18079
18098
  handleReportProductView(item);
18080
18099
  }
18081
- let fromKName = '';
18082
- 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))) {
18083
- fromKName = 'pdpPage';
18084
- }
18085
- 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') {
18086
- fromKName = 'formPage';
18087
- }
18088
- else if (isFromHashtag) {
18089
- fromKName = 'hashTagPage';
18090
- }
18091
- else if ((_h = item === null || item === void 0 ? void 0 : item.video) === null || _h === void 0 ? void 0 : _h.url) {
18092
- fromKName = 'videoPage';
18093
- }
18094
- 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)) {
18095
- fromKName = 'imagePage';
18096
- }
18097
- else if (item === null || item === void 0 ? void 0 : item.product) {
18098
- fromKName = 'productPage';
18099
- }
18100
18100
  if ((globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.playbook) !== 'organic menu' || activeIndex !== 0 || channel) {
18101
- bffEventReport === null || bffEventReport === void 0 ? void 0 : bffEventReport({
18102
- eventInfo: {
18103
- sessionDuration: Math.floor((new Date() - curTime.current) / 1000) + '',
18104
- eventSubject: 'sessionCompleted',
18105
- eventDescription: 'Session completed',
18106
- contentId: (_m = item === null || item === void 0 ? void 0 : item.video) === null || _m === void 0 ? void 0 : _m.itemId,
18107
- productId: (_o = item === null || item === void 0 ? void 0 : item.product) === null || _o === void 0 ? void 0 : _o.itemId,
18108
- position: activeIndex + '',
18109
- fromKName,
18110
- fromKPage: location === null || location === void 0 ? void 0 : location.href,
18111
- 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 : '',
18112
- 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 : ''
18113
- }
18114
- });
18101
+ const isExpire = refreshFeSession === null || refreshFeSession === void 0 ? void 0 : refreshFeSession(true, handleSessionCompleted);
18102
+ if (!isExpire)
18103
+ handleSessionCompleted();
18115
18104
  }
18116
18105
  }
18117
18106
  else if (document.visibilityState === 'visible') {
@@ -18144,8 +18133,24 @@ const SxpPageRender = ({ globalConfig, descStyle, containerHeight = window.inner
18144
18133
  openHashtag,
18145
18134
  isShowConsent,
18146
18135
  selectTag,
18147
- channel
18136
+ channel,
18137
+ handleSessionCompleted,
18138
+ refreshFeSession
18148
18139
  ]);
18140
+ const handleSessionExpire = React.useCallback(lodash.debounce(() => {
18141
+ refreshFeSession === null || refreshFeSession === void 0 ? void 0 : refreshFeSession(false, handleSessionCompleted);
18142
+ }, 1000), [handleSessionCompleted, refreshFeSession]);
18143
+ React.useEffect(() => {
18144
+ const events = ['touchstart', 'touchcancel'];
18145
+ events.forEach((event) => {
18146
+ window.addEventListener(event, handleSessionExpire);
18147
+ });
18148
+ return () => {
18149
+ events.forEach((event) => {
18150
+ window.removeEventListener(event, handleSessionExpire);
18151
+ });
18152
+ };
18153
+ }, [handleSessionExpire]);
18149
18154
  const tagHeight = React.useMemo(() => {
18150
18155
  let h = 0;
18151
18156
  if (tagList.length > 0) {