pb-sxp-ui 1.13.1 → 1.13.2

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
@@ -655,15 +655,12 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
655
655
  const bffDataSource = useMemo(() => {
656
656
  return dataSources === null || dataSources === void 0 ? void 0 : dataSources.find((d) => d.type === DataSourceType.BFF);
657
657
  }, [dataSources]);
658
- const fakeUserId = useMemo(() => {
659
- var _a;
660
- return ((_a = bffDataSource === null || bffDataSource === void 0 ? void 0 : bffDataSource.headers) === null || _a === void 0 ? void 0 : _a['x-app-id']) + storeAndLoadFeUserId();
661
- }, [bffDataSource]);
662
658
  // bff API 请求方法
663
659
  const bffFetch = useCallback((path, options) => {
664
660
  if (!bffDataSource)
665
661
  return;
666
662
  const url = bffDataSource.url;
663
+ const fakeUserId = storeAndLoadFeUserId();
667
664
  if (options === null || options === void 0 ? void 0 : options.query) {
668
665
  const queryString = qs.stringify(options.query);
669
666
  path = `${path}?${queryString}`;
@@ -671,19 +668,19 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
671
668
  // 事件上报优化
672
669
  // Beacon API 用于发送异步和非阻塞请求到服务器。这类请求不需要响应。
673
670
  if (options.type === 'beacon' && navigator.sendBeacon) {
674
- return navigator.sendBeacon(`${url}/api/${path}`, new Blob([
671
+ return navigator.sendBeacon(`${url}/api/v1${path}`, new Blob([
675
672
  JSON.stringify(Object.assign(Object.assign(Object.assign({}, options.body), bffDataSource.headers), { 'x-user-id': fakeUserId }))
676
673
  ], { type: 'application/json;charset=UTF-8' }));
677
674
  }
678
675
  return window
679
- .fetch(`${url}/api/${path}`, {
676
+ .fetch(`${url}/api/v1${path}`, {
680
677
  headers: Object.assign({ 'Content-Type': 'application/json', 'x-user-id': fakeUserId }, bffDataSource.headers),
681
678
  method: options.method,
682
679
  body: JSON.stringify(options.body)
683
680
  })
684
681
  .then((res) => res.json())
685
682
  .catch((err) => Promise.reject(err));
686
- }, [bffDataSource, fakeUserId]);
683
+ }, [bffDataSource]);
687
684
  // 获取推荐视频数据
688
685
  const getRecommendVideos = useCallback((query) => __awaiter(void 0, void 0, void 0, function* () {
689
686
  var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
@@ -721,7 +718,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
721
718
  const recurveRecList = (query) => __awaiter(void 0, void 0, void 0, function* () {
722
719
  var _v, _w, _x, _y, _z, _0;
723
720
  query.pageNum = pageNum;
724
- result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/list', { method: 'POST', body: query }));
721
+ result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/recommend/list', { method: 'POST', body: query }));
725
722
  if (!(result === null || result === void 0 ? void 0 : result.success)) {
726
723
  return undefined;
727
724
  }
@@ -743,7 +740,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
743
740
  if (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview) {
744
741
  query = Object.assign(Object.assign({}, query), { directPage: true, level: 1, pageNum: (_o = query === null || query === void 0 ? void 0 : query.pageNum) !== null && _o !== void 0 ? _o : 1 });
745
742
  }
746
- const result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/list', { method: 'POST', body: query }));
743
+ const result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/recommend/list', { method: 'POST', body: query }));
747
744
  if (!(result === null || result === void 0 ? void 0 : result.success)) {
748
745
  return undefined;
749
746
  }
@@ -793,7 +790,6 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
793
790
  return expire;
794
791
  }, [data]);
795
792
  const bffEventReport = useCallback(({ userInfo, eventInfo, reportLayId = true }) => {
796
- var _a;
797
793
  // 关闭 BFF 事件上报
798
794
  if (!enableReportEvent || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview)) {
799
795
  return;
@@ -815,23 +811,14 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
815
811
  console.log('userInfo:', userInfo);
816
812
  console.log('eventInfo:', ef);
817
813
  console.log('========= 结束 =========');
818
- return bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch(`v2/event/report/CLD/${(_a = bffDataSource === null || bffDataSource === void 0 ? void 0 : bffDataSource.headers) === null || _a === void 0 ? void 0 : _a['x-app-id']}/${eventInfo === null || eventInfo === void 0 ? void 0 : eventInfo.eventSubject}`, {
814
+ return bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/event/report', {
819
815
  method: 'POST',
820
816
  body: { userInfo: realUserInfo, eventInfo: realEventInfo },
821
817
  type: 'beacon'
822
818
  });
823
- }, [
824
- bffFetch,
825
- curReqInfo,
826
- enableReportEvent,
827
- globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview,
828
- layoutVariantId,
829
- globalConfig,
830
- playbookType,
831
- bffDataSource
832
- ]);
819
+ }, [bffFetch, curReqInfo, enableReportEvent, globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview, layoutVariantId, globalConfig, playbookType]);
833
820
  const bffFbReport = useCallback(({ eventName, product }) => {
834
- var _a, _b, _c, _d, _e, _f;
821
+ var _a, _b, _c, _d, _e;
835
822
  if (!enableReportEvent ||
836
823
  !enabledMetaConversionApi ||
837
824
  (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview) ||
@@ -843,7 +830,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
843
830
  const fbclid = urlParams === null || urlParams === void 0 ? void 0 : urlParams.get('fbclid');
844
831
  const fix_par = {
845
832
  event_source_url: (_c = window === null || window === void 0 ? void 0 : window.location) === null || _c === void 0 ? void 0 : _c.href,
846
- external_id: fakeUserId,
833
+ external_id: storeAndLoadFeUserId(),
847
834
  client_user_agent: (_e = (_d = window === null || window === void 0 ? void 0 : window.navigator) === null || _d === void 0 ? void 0 : _d.userAgent) !== null && _e !== void 0 ? _e : '',
848
835
  fbc: fbclid ? `fb.2.${new Date().getTime()}.${fbclid}` : '',
849
836
  fbp: getCookie('_fbp') ? `fb.2.${new Date().getTime()}.${getCookie('_fbp')}` : '',
@@ -895,30 +882,22 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
895
882
  }
896
883
  };
897
884
  getEventParams(jsonParams);
898
- return bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch(`v2/event/report/FB/${(_f = bffDataSource === null || bffDataSource === void 0 ? void 0 : bffDataSource.headers) === null || _f === void 0 ? void 0 : _f['x-app-id']}/${eventName}`, {
885
+ return bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/fb/events', {
899
886
  method: 'POST',
900
887
  body: jsonParams,
901
888
  type: 'beacon'
902
889
  });
903
- }, [
904
- bffFetch,
905
- enableReportEvent,
906
- enabledMetaConversionApi,
907
- globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview,
908
- globalConfig,
909
- fakeUserId,
910
- bffDataSource
911
- ]);
890
+ }, [bffFetch, enableReportEvent, enabledMetaConversionApi, globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview, globalConfig]);
912
891
  const bffMutateLike = useCallback((body) => __awaiter(void 0, void 0, void 0, function* () {
913
- const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/like', { method: 'POST', body }));
892
+ const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/recommend/like', { method: 'POST', body }));
914
893
  return res === null || res === void 0 ? void 0 : res.success;
915
894
  }), [bffFetch]);
916
895
  const bffMutateUnlike = useCallback((body) => __awaiter(void 0, void 0, void 0, function* () {
917
- const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/unlike', { method: 'POST', body }));
896
+ const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/recommend/unlike', { method: 'POST', body }));
918
897
  return res === null || res === void 0 ? void 0 : res.success;
919
898
  }), [bffFetch]);
920
899
  const bffSubmitForm = useCallback((body) => __awaiter(void 0, void 0, void 0, function* () {
921
- const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/customform', { method: 'POST', body }));
900
+ const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/customform', { method: 'POST', body }));
922
901
  return res === null || res === void 0 ? void 0 : res.success;
923
902
  }), [bffFetch]);
924
903
  // 获取 Tag
@@ -933,7 +912,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
933
912
  const key = val.split('=')[0];
934
913
  return (_b = ((_a = utmParameter === null || utmParameter === void 0 ? void 0 : utmParameter.channels) !== null && _a !== void 0 ? _a : [])) === null || _b === void 0 ? void 0 : _b.includes(key);
935
914
  })) === null || _9 === void 0 ? void 0 : _9.join('&')) !== null && _10 !== void 0 ? _10 : '';
936
- const result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/tag/list', { method: 'GET', query: { channel: decodeURIComponent(val) } }));
915
+ const result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/tag/list', { method: 'GET', query: { channel: decodeURIComponent(val) } }));
937
916
  setTagList((_12 = (_11 = result === null || result === void 0 ? void 0 : result.data) === null || _11 === void 0 ? void 0 : _11.tags) !== null && _12 !== void 0 ? _12 : []);
938
917
  }
939
918
  catch (e) {
@@ -1007,10 +986,10 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
1007
986
  let curData;
1008
987
  let gldata;
1009
988
  if (data === null || data === void 0 ? void 0 : data.layoutVariantId) {
1010
- layId = data === null || data === void 0 ? void 0 : data.layoutVariantId;
1011
- setLayoutVariantId(data === null || data === void 0 ? void 0 : data.layoutVariantId);
1012
989
  const id = (_b = (_a = data === null || data === void 0 ? void 0 : data.layoutVariantId) === null || _a === void 0 ? void 0 : _a.split('-')) === null || _b === void 0 ? void 0 : _b[1];
1013
990
  if (id) {
991
+ layId = id;
992
+ setLayoutVariantId(id);
1014
993
  curData = dataList === null || dataList === void 0 ? void 0 : dataList.find((item) => (item === null || item === void 0 ? void 0 : item.id) === id);
1015
994
  if (curData) {
1016
995
  setPageData(curData);
@@ -10097,7 +10076,7 @@ var CommodityGroup$1 = memo(CommodityGroup);
10097
10076
  * @Author: binruan@chatlabs.com
10098
10077
  * @Date: 2024-03-20 14:56:16
10099
10078
  * @LastEditors: binruan@chatlabs.com
10100
- * @LastEditTime: 2024-12-20 14:32:26
10079
+ * @LastEditTime: 2024-10-24 17:51:19
10101
10080
  * @FilePath: \pb-sxp-ui\src\core\utils\materials.ts
10102
10081
  *
10103
10082
  */
@@ -10135,16 +10114,14 @@ const getBgStyle = (imgSrc) => {
10135
10114
  };
10136
10115
  const getPriceText = ({ product, enableFormattedPrice, globalConfig, isHiddenDef, style }) => {
10137
10116
  var _a, _b, _c, _d, _e, _f, _g, _h;
10138
- let text = '';
10139
10117
  if ((!(product === null || product === void 0 ? void 0 : product.currency) || !(product === null || product === void 0 ? void 0 : product.price)) && isHiddenDef)
10140
10118
  return null;
10141
- let price = Number((product === null || product === void 0 ? void 0 : product.currency) && (product === null || product === void 0 ? void 0 : product.price) ? product === null || product === void 0 ? void 0 : product.price : 7000);
10142
- if (typeof price !== 'number')
10143
- return text;
10119
+ let price = (product === null || product === void 0 ? void 0 : product.currency) && (product === null || product === void 0 ? void 0 : product.price) ? product === null || product === void 0 ? void 0 : product.price : 7000;
10120
+ let text = '';
10144
10121
  let priceSymbol = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.priceSymbol;
10145
10122
  let currency = (product === null || product === void 0 ? void 0 : product.currency) ? (_c = (_b = (_a = product === null || product === void 0 ? void 0 : product.currency) === null || _a === void 0 ? void 0 : _a.split('-')[1]) === null || _b === void 0 ? void 0 : _b.toUpperCase()) !== null && _c !== void 0 ? _c : '' : '$';
10146
10123
  const isToLocStr = enableFormattedPrice === undefined || enableFormattedPrice;
10147
- let decPic = price === null || price === void 0 ? void 0 : price.toString();
10124
+ let decPic = price.toString();
10148
10125
  if (priceSymbol === null || priceSymbol === void 0 ? void 0 : priceSymbol.showTwoDecimalPoint) {
10149
10126
  decPic = price === null || price === void 0 ? void 0 : price.toFixed(2);
10150
10127
  }