pb-sxp-ui 1.20.66 → 1.20.67

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
@@ -25814,8 +25814,10 @@ const Popup = () => {
25814
25814
  const { setPopupDetailData, popupDetailData, popupCurTimeRef, checkCommodityIndexRef } = useSxpDataSource();
25815
25815
  const { productView } = useEventReport();
25816
25816
  const [visible, setVisible] = React.useState();
25817
- // 记录商品弹窗的 popup id,用于加购弹窗关闭后恢复(仅 SPU 场景)
25817
+ // 记录上一个非加购弹窗的 popup,用于 SPU 场景:商品弹窗 → 加购弹窗关闭后恢复
25818
25818
  const prevCommodityPopupRef = React.useRef(null);
25819
+ // 记录当前弹窗是否是加购弹窗(用于关闭时判断)
25820
+ const isAddToCartPopupRef = React.useRef(false);
25819
25821
  React.useEffect(() => {
25820
25822
  const initTime = () => {
25821
25823
  popupCurTimeRef.current = new Date();
@@ -25831,13 +25833,19 @@ const Popup = () => {
25831
25833
  if (popup && (popup === null || popup === void 0 ? void 0 : popup.id) && (popup === null || popup === void 0 ? void 0 : popup.id) !== '') {
25832
25834
  popupCurTimeRef.current = new Date();
25833
25835
  setVisible(popup);
25834
- // 非加购弹窗时,记录当前 popup,供后续加购弹窗关闭后恢复(SPU 场景)
25835
25836
  const currentValue = (_c = (_b = (_a = schema === null || schema === void 0 ? void 0 : schema.sxpPageConf) === null || _a === void 0 ? void 0 : _a.globalConfig) === null || _b === void 0 ? void 0 : _b.popupList) === null || _c === void 0 ? void 0 : _c.find((item) => (item === null || item === void 0 ? void 0 : item.id) === (popup === null || popup === void 0 ? void 0 : popup.id));
25836
- if (((_d = currentValue === null || currentValue === void 0 ? void 0 : currentValue.item) === null || _d === void 0 ? void 0 : _d.type) !== 'AddToCart') {
25837
+ const isAddToCart = ((_d = currentValue === null || currentValue === void 0 ? void 0 : currentValue.item) === null || _d === void 0 ? void 0 : _d.type) === 'AddToCart';
25838
+ isAddToCartPopupRef.current = isAddToCart;
25839
+ if (!isAddToCart) {
25840
+ // 记录非加购弹窗(商品弹窗等),供加购弹窗关闭后恢复
25837
25841
  prevCommodityPopupRef.current = popup;
25838
25842
  }
25839
25843
  }
25840
- }, [popup]);
25844
+ else if ((popup === null || popup === void 0 ? void 0 : popup.id) === '') {
25845
+ // popup 被清空时,同步重置标记
25846
+ isAddToCartPopupRef.current = false;
25847
+ }
25848
+ }, [popup, schema]);
25841
25849
  const isFullScreen = React.useMemo(() => {
25842
25850
  var _a, _b, _c, _d;
25843
25851
  const valueItem = (_c = (_b = (_a = schema === null || schema === void 0 ? void 0 : schema.sxpPageConf) === null || _a === void 0 ? void 0 : _a.globalConfig) === null || _b === void 0 ? void 0 : _b.popupList) === null || _c === void 0 ? void 0 : _c.find((value, index) => {
@@ -25853,7 +25861,7 @@ const Popup = () => {
25853
25861
  }
25854
25862
  }, [popup, schema]);
25855
25863
  const handleClose = () => {
25856
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
25864
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
25857
25865
  if (!popup ||
25858
25866
  (popup === null || popup === void 0 ? void 0 : popup.id) === '' ||
25859
25867
  !visible ||
@@ -25879,23 +25887,24 @@ const Popup = () => {
25879
25887
  }
25880
25888
  // 加购弹窗关闭时,判断是否需要恢复商品弹窗
25881
25889
  if (((_u = value === null || value === void 0 ? void 0 : value.item) === null || _u === void 0 ? void 0 : _u.type) === 'AddToCart') {
25882
- const isFromSku = !!(popupDetailData === null || popupDetailData === void 0 ? void 0 : popupDetailData._defaultVariantId);
25883
- if (!isFromSku && ((_v = prevCommodityPopupRef.current) === null || _v === void 0 ? void 0 : _v.id)) {
25884
- // SPU 场景:从商品弹窗跳来的,关闭加购弹窗后恢复商品弹窗
25885
- const _w = prevCommodityPopupRef.current, { id: commodityId } = _w, commodityAni = __rest(_w, ["id"]);
25886
- prevCommodityPopupRef.current = null;
25890
+ const prevPopup = prevCommodityPopupRef.current;
25891
+ prevCommodityPopupRef.current = null;
25892
+ isAddToCartPopupRef.current = false;
25893
+ if (prevPopup === null || prevPopup === void 0 ? void 0 : prevPopup.id) {
25894
+ // SPU 场景:加购弹窗之前有商品弹窗,关闭后恢复商品弹窗
25895
+ const { id: commodityId } = prevPopup, commodityAni = __rest(prevPopup, ["id"]);
25887
25896
  setTimeout(() => {
25888
25897
  window === null || window === void 0 ? void 0 : window.sxpPopup(commodityId, commodityAni);
25889
25898
  }, popup === null || popup === void 0 ? void 0 : popup.duration);
25890
25899
  return;
25891
25900
  }
25892
- // SKU 场景:直接从 feed 打开的,关闭后直接回到 feed
25893
- prevCommodityPopupRef.current = null;
25901
+ // SKU 场景:之前没有商品弹窗,直接回到 feed
25894
25902
  }
25895
25903
  setTimeout(() => {
25896
25904
  window === null || window === void 0 ? void 0 : window.sxpPopup('');
25897
25905
  setPopupDetailData === null || setPopupDetailData === void 0 ? void 0 : setPopupDetailData(null);
25898
25906
  checkCommodityIndexRef.current = -1;
25907
+ prevCommodityPopupRef.current = null;
25899
25908
  }, popup === null || popup === void 0 ? void 0 : popup.duration);
25900
25909
  };
25901
25910
  const renderPopupDetail = React.useMemo(() => {