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.js CHANGED
@@ -832,22 +832,26 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
832
832
  setCacheRtcList(cacheRtcList.concat(getFilterRecList(data)));
833
833
  return data;
834
834
  }), [getRecommendVideos, rtcList, waterFallData, cacheRtcList]);
835
- const refreshFeSession = useCallback((enableReSid) => {
835
+ const refreshFeSession = useCallback((enableReSid, event) => {
836
836
  var _a, _b, _c, _d, _e;
837
+ let expire = false;
837
838
  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;
838
839
  if ((_c = defaultGlobalConfig === null || defaultGlobalConfig === void 0 ? void 0 : defaultGlobalConfig.session) === null || _c === void 0 ? void 0 : _c.enable) {
839
840
  const sessionStartTime = localStorage.getItem('sessionStartTime');
840
- const sst = sessionStartTime ? new Date(sessionStartTime) : new Date();
841
- if (Math.floor((new Date() - sst) / (1000 * 60)) >=
841
+ const sst = sessionStartTime ? JSON.parse(sessionStartTime) : new Date().getTime();
842
+ if (Math.floor((new Date().getTime() - sst) / 1000 / 60) >=
842
843
  ((_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)) {
844
+ event === null || event === void 0 ? void 0 : event('sessionTimeOut');
843
845
  refreshFeSessionId();
844
846
  curTime.current = new Date();
847
+ expire = true;
845
848
  }
846
- localStorage.setItem('sessionStartTime', new Date().toISOString());
849
+ localStorage.setItem('sessionStartTime', JSON.stringify(new Date().getTime()));
847
850
  }
848
851
  else if (enableReSid) {
849
852
  refreshFeSessionId();
850
853
  }
854
+ return expire;
851
855
  }, [data]);
852
856
  const bffEventReport = useCallback(({ userInfo, eventInfo, reportLayId = true }) => {
853
857
  // 关闭 BFF 事件上报
@@ -861,7 +865,6 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
861
865
  // tpChannelId: 'H5' // 后端处理
862
866
  };
863
867
  }
864
- refreshFeSession();
865
868
  const sessionID = storeAndLoadFeSessionId();
866
869
  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 + '' }));
867
870
  const realUserInfo = Object.entries(userInfo).map(([k, v]) => ({ name: k, value: v }));
@@ -877,16 +880,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
877
880
  body: { userInfo: realUserInfo, eventInfo: realEventInfo },
878
881
  type: 'beacon'
879
882
  });
880
- }, [
881
- bffFetch,
882
- curReqInfo,
883
- enableReportEvent,
884
- globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview,
885
- layoutVariantId,
886
- globalConfig,
887
- playbookType,
888
- refreshFeSession
889
- ]);
883
+ }, [bffFetch, curReqInfo, enableReportEvent, globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview, layoutVariantId, globalConfig, playbookType]);
890
884
  const bffFbReport = useCallback(({ eventName, product }) => {
891
885
  var _a, _b, _c, _d, _e;
892
886
  if (!enableReportEvent ||
@@ -1044,7 +1038,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
1044
1038
  useEffect(() => {
1045
1039
  if (!isShowConsent)
1046
1040
  h5EnterLink();
1047
- }, [isShowConsent, h5EnterLink]);
1041
+ }, [isShowConsent]);
1048
1042
  useEffect(() => {
1049
1043
  if (isShowConsent || isPreview)
1050
1044
  return;
@@ -17171,7 +17165,6 @@ const VideoWidget$2 = ({ rec, index, height, data, muted, activeIndex, videoPost
17171
17165
  const { bffEventReport, sxpParameter, waterFallData, openHashtag, bffFbReport } = useSxpDataSource();
17172
17166
  const videoStartTime = useRef(0);
17173
17167
  const [isLoadFinish, setIsLoadFinish] = useState(false);
17174
- const [isFirstPlay, setIsFirstPlay] = useState(true);
17175
17168
  const { isActive } = useSwiperSlide();
17176
17169
  const canvasRef = useRef(null);
17177
17170
  const [firstFrameSrc, setFirstFrameSrc] = useState('');
@@ -17182,6 +17175,7 @@ const VideoWidget$2 = ({ rec, index, height, data, muted, activeIndex, videoPost
17182
17175
  const hlsRef = useRef(null);
17183
17176
  const initTimeRef = useRef();
17184
17177
  const loadedTimeRef = useRef();
17178
+ const isFirstPlayRef = useRef(true);
17185
17179
  const blur = useMemo(() => {
17186
17180
  return (videoPostConfig === null || videoPostConfig === void 0 ? void 0 : videoPostConfig.mode) === '2';
17187
17181
  }, [videoPostConfig]);
@@ -17237,26 +17231,13 @@ const VideoWidget$2 = ({ rec, index, height, data, muted, activeIndex, videoPost
17237
17231
  videoStartTime.current = ((_b = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) === null || _b === void 0 ? void 0 : _b.currentTime) || 0;
17238
17232
  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);
17239
17233
  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);
17240
- const playType = isFirstPlay ? '0' : '1';
17234
+ const playType = (isFirstPlayRef === null || isFirstPlayRef === void 0 ? void 0 : isFirstPlayRef.current) ? '0' : '1';
17241
17235
  bffEventReport === null || bffEventReport === void 0 ? void 0 : bffEventReport({
17242
- eventInfo: {
17243
- eventSubject: 'playVideo',
17244
- eventDescription: 'User played the video',
17245
- 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 : '',
17246
- 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 : '',
17247
- playType,
17248
- startTime: videoCurrentTime,
17249
- videoDuration,
17250
- 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 : []),
17251
- position: index + '',
17252
- contentFormat: 'video',
17253
- traceInfo: (_o = item === null || item === void 0 ? void 0 : item.video) === null || _o === void 0 ? void 0 : _o.traceInfo,
17254
- loadTime: (loadedTimeRef === null || loadedTimeRef === void 0 ? void 0 : loadedTimeRef.current) - (initTimeRef === null || initTimeRef === void 0 ? void 0 : initTimeRef.current) + ''
17255
- }
17236
+ 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) + '' }))
17256
17237
  });
17257
- setIsFirstPlay(false);
17238
+ isFirstPlayRef.current = false;
17258
17239
  }
17259
- }), [bffEventReport, data, index, isFirstPlay, videoRef === null || videoRef === void 0 ? void 0 : videoRef.current]);
17240
+ }), [bffEventReport, data, index, isFirstPlayRef, videoRef === null || videoRef === void 0 ? void 0 : videoRef.current]);
17260
17241
  const handLoadeddata = useCallback(() => {
17261
17242
  var _a;
17262
17243
  if (!(videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) || firstFrameSrc || !blur)
@@ -17615,13 +17596,14 @@ const Picture = (props) => {
17615
17596
 
17616
17597
  const PictureGroup$2 = ({ imgUrls, width, height, rec, index, onViewImageEndEvent, onViewImageStartEvent, imgUrlsPostConfig }) => {
17617
17598
  var _a, _b;
17618
- const swiperRef = useRef();
17619
17599
  const { isActive } = useSwiperSlide();
17620
17600
  const { sxpParameter, openHashtag } = useSxpDataSource();
17621
17601
  const [isLoad, setIsLoad] = useState(false);
17622
17602
  const [imgInfo, setImgInfo] = useState();
17623
- const initTime = new Date();
17624
17603
  const [swiperActiveIndex, setSwiperActiveIndex] = useState(0);
17604
+ const swiperRef = useRef();
17605
+ const isFirstPlayRef = useRef(true);
17606
+ const initTime = new Date();
17625
17607
  useEffect(() => {
17626
17608
  if (isLoad && isActive) {
17627
17609
  (swiperRef === null || swiperRef === void 0 ? void 0 : swiperRef.current) && swiperRef.current.swiper.autoplay.start();
@@ -17629,7 +17611,8 @@ const PictureGroup$2 = ({ imgUrls, width, height, rec, index, onViewImageEndEven
17629
17611
  onViewImageEndEvent(rec);
17630
17612
  }
17631
17613
  else {
17632
- onViewImageStartEvent(index, imgInfo, true);
17614
+ onViewImageStartEvent(index, isFirstPlayRef.current ? imgInfo : undefined, true);
17615
+ isFirstPlayRef.current = false;
17633
17616
  }
17634
17617
  }
17635
17618
  else {
@@ -17984,7 +17967,7 @@ var NavBack$1 = memo(NavBack);
17984
17967
  * @Author: binruan@chatlabs.com
17985
17968
  * @Date: 2024-03-20 10:27:31
17986
17969
  * @LastEditors: binruan@chatlabs.com
17987
- * @LastEditTime: 2024-12-16 15:03:38
17970
+ * @LastEditTime: 2024-12-17 15:46:14
17988
17971
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\index.tsx
17989
17972
  *
17990
17973
  */
@@ -18044,10 +18027,46 @@ const SxpPageRender = ({ globalConfig, descStyle, containerHeight = window.inner
18044
18027
  if (index !== -1)
18045
18028
  (_a = swiperRef === null || swiperRef === void 0 ? void 0 : swiperRef.current) === null || _a === void 0 ? void 0 : _a.swiper.slideTo(index);
18046
18029
  }, [data, ctaType, swiperRef]);
18030
+ const handleSessionCompleted = useCallback((fk) => {
18031
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
18032
+ const item = data === null || data === void 0 ? void 0 : data[activeIndex];
18033
+ let fromKName = '';
18034
+ 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))) {
18035
+ fromKName = 'pdpPage';
18036
+ }
18037
+ 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') {
18038
+ fromKName = 'formPage';
18039
+ }
18040
+ else if (isFromHashtag) {
18041
+ fromKName = 'hashTagPage';
18042
+ }
18043
+ else if ((_h = item === null || item === void 0 ? void 0 : item.video) === null || _h === void 0 ? void 0 : _h.url) {
18044
+ fromKName = 'videoPage';
18045
+ }
18046
+ 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)) {
18047
+ fromKName = 'imagePage';
18048
+ }
18049
+ else if (item === null || item === void 0 ? void 0 : item.product) {
18050
+ fromKName = 'productPage';
18051
+ }
18052
+ bffEventReport === null || bffEventReport === void 0 ? void 0 : bffEventReport({
18053
+ eventInfo: {
18054
+ sessionDuration: Math.floor((new Date() - curTime.current) / 1000) + '',
18055
+ eventSubject: 'sessionCompleted',
18056
+ eventDescription: 'Session completed',
18057
+ contentId: (_m = item === null || item === void 0 ? void 0 : item.video) === null || _m === void 0 ? void 0 : _m.itemId,
18058
+ productId: (_o = item === null || item === void 0 ? void 0 : item.product) === null || _o === void 0 ? void 0 : _o.itemId,
18059
+ position: activeIndex + '',
18060
+ fromKName: fk ? fk : fromKName,
18061
+ fromKPage: location === null || location === void 0 ? void 0 : location.href,
18062
+ 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 : '',
18063
+ 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 : ''
18064
+ }
18065
+ });
18066
+ }, [data, bffEventReport, activeIndex, popupDetailData, tempMap, isFromHashtag, curTime]);
18047
18067
  useEffect(() => {
18048
18068
  const item = data === null || data === void 0 ? void 0 : data[activeIndex];
18049
18069
  const visibleChange = () => {
18050
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
18051
18070
  const repCond = !openHashtag && !isShowConsent;
18052
18071
  if (document.visibilityState === 'hidden') {
18053
18072
  // 当用户导航到新页面、切换标签页、关闭标签页、最小化或关闭浏览器、刷新原页面(即离开原页面时),或者在移动设备上从浏览器切换到不同的应用程序时
@@ -18056,40 +18075,10 @@ const SxpPageRender = ({ globalConfig, descStyle, containerHeight = window.inner
18056
18075
  SXP_EVENT_BUS.emit(SXP_EVENT_TYPE.PAGE_DID_HIDE, item);
18057
18076
  handleReportProductView(item);
18058
18077
  }
18059
- let fromKName = '';
18060
- 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))) {
18061
- fromKName = 'pdpPage';
18062
- }
18063
- 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') {
18064
- fromKName = 'formPage';
18065
- }
18066
- else if (isFromHashtag) {
18067
- fromKName = 'hashTagPage';
18068
- }
18069
- else if ((_h = item === null || item === void 0 ? void 0 : item.video) === null || _h === void 0 ? void 0 : _h.url) {
18070
- fromKName = 'videoPage';
18071
- }
18072
- 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)) {
18073
- fromKName = 'imagePage';
18074
- }
18075
- else if (item === null || item === void 0 ? void 0 : item.product) {
18076
- fromKName = 'productPage';
18077
- }
18078
18078
  if ((globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.playbook) !== 'organic menu' || activeIndex !== 0 || channel) {
18079
- bffEventReport === null || bffEventReport === void 0 ? void 0 : bffEventReport({
18080
- eventInfo: {
18081
- sessionDuration: Math.floor((new Date() - curTime.current) / 1000) + '',
18082
- eventSubject: 'sessionCompleted',
18083
- eventDescription: 'Session completed',
18084
- contentId: (_m = item === null || item === void 0 ? void 0 : item.video) === null || _m === void 0 ? void 0 : _m.itemId,
18085
- productId: (_o = item === null || item === void 0 ? void 0 : item.product) === null || _o === void 0 ? void 0 : _o.itemId,
18086
- position: activeIndex + '',
18087
- fromKName,
18088
- fromKPage: location === null || location === void 0 ? void 0 : location.href,
18089
- 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 : '',
18090
- 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 : ''
18091
- }
18092
- });
18079
+ const isExpire = refreshFeSession === null || refreshFeSession === void 0 ? void 0 : refreshFeSession(true, handleSessionCompleted);
18080
+ if (!isExpire)
18081
+ handleSessionCompleted();
18093
18082
  }
18094
18083
  }
18095
18084
  else if (document.visibilityState === 'visible') {
@@ -18122,8 +18111,24 @@ const SxpPageRender = ({ globalConfig, descStyle, containerHeight = window.inner
18122
18111
  openHashtag,
18123
18112
  isShowConsent,
18124
18113
  selectTag,
18125
- channel
18114
+ channel,
18115
+ handleSessionCompleted,
18116
+ refreshFeSession
18126
18117
  ]);
18118
+ const handleSessionExpire = useCallback(debounce(() => {
18119
+ refreshFeSession === null || refreshFeSession === void 0 ? void 0 : refreshFeSession(false, handleSessionCompleted);
18120
+ }, 1000), [handleSessionCompleted, refreshFeSession]);
18121
+ useEffect(() => {
18122
+ const events = ['touchstart', 'touchcancel'];
18123
+ events.forEach((event) => {
18124
+ window.addEventListener(event, handleSessionExpire);
18125
+ });
18126
+ return () => {
18127
+ events.forEach((event) => {
18128
+ window.removeEventListener(event, handleSessionExpire);
18129
+ });
18130
+ };
18131
+ }, [handleSessionExpire]);
18127
18132
  const tagHeight = useMemo(() => {
18128
18133
  let h = 0;
18129
18134
  if (tagList.length > 0) {