pb-sxp-ui 1.12.3 → 1.13.1

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
@@ -232,70 +232,6 @@
232
232
  }
233
233
  return content;
234
234
  };
235
- function getBrowserInfo() {
236
- var _a, _b, _c, _d, _e, _f, _g;
237
- let userAgent = self.navigator.userAgent;
238
- if (!userAgent)
239
- return null;
240
- if (/edge\/([\d\.]+)/i.exec(userAgent))
241
- return `Edge ${(_a = /edge\/([\d\.]+)/i.exec(userAgent)) === null || _a === void 0 ? void 0 : _a[1]}`;
242
- if (/edg\/([\d\.]+)/i.exec(userAgent))
243
- return `Edge(Chromium) ${(_b = /edge\/([\d\.]+)/i.exec(userAgent)) === null || _b === void 0 ? void 0 : _b[1]}`;
244
- if (/msie/i.test(userAgent))
245
- return `Internet Explorer ${(_c = /msie ([\d\.]+)/i.exec(userAgent)) === null || _c === void 0 ? void 0 : _c[1]}`;
246
- if (/Trident/i.test(userAgent))
247
- return `Internet Explorer ${(_d = /rv:([\d\.]+)/i.exec(userAgent)) === null || _d === void 0 ? void 0 : _d[1]}`;
248
- if (/chrome/i.test(userAgent))
249
- return `Chrome ${(_e = /chrome\/([\d\.]+)/i.exec(userAgent)) === null || _e === void 0 ? void 0 : _e[1]}`;
250
- if (/firefox/i.test(userAgent))
251
- return `Firefox ${(_f = /firefox\/([\d\.]+)/i.exec(userAgent)) === null || _f === void 0 ? void 0 : _f[1]}`;
252
- if (/safari/i.test(userAgent))
253
- return `Safari ${(_g = /version\/([\d\.]+)/i.exec(userAgent)) === null || _g === void 0 ? void 0 : _g[1]}`;
254
- return null;
255
- }
256
- function getSystem() {
257
- var _a, _b, _c;
258
- let userAgent = self.navigator.userAgent;
259
- if (!userAgent)
260
- return null;
261
- if (/iphone/i.test(userAgent))
262
- return `IOS ${(_a = userAgent.match(/OS\s(.*?)\slike/)) === null || _a === void 0 ? void 0 : _a[1]}`;
263
- if (/android/i.test(userAgent))
264
- return `Android ${(_b = userAgent.match(/Android\s(.*?)\;/)) === null || _b === void 0 ? void 0 : _b[1]}`;
265
- if (/windows/i.test(userAgent))
266
- return `Windows ${(_c = userAgent.match(/Windows\s(.*?)\;/)) === null || _c === void 0 ? void 0 : _c[1]}`;
267
- if (/mac/i.test(userAgent))
268
- return `Mac OS`;
269
- return null;
270
- }
271
- function getDevice$1() {
272
- let userAgent = self.navigator.userAgent;
273
- if (!userAgent)
274
- return null;
275
- if (/iphone/i.test(userAgent))
276
- return `iPhone`;
277
- if (/android/i.test(userAgent)) {
278
- // var index1 = userAgent.indexOf(';');
279
- // var index2 = userAgent.indexOf(';', index1 + 1);
280
- // var index3 = userAgent.indexOf(';', index2 + 1);
281
- // var index4 = userAgent.indexOf(';', index3 + 1);
282
- // if (index2 !== -1 && index3 !== -1) {
283
- // var value1 = userAgent.substring(index3 + 1, index4);
284
- // return `${value1}`;
285
- // }
286
- var index1 = userAgent.indexOf('(');
287
- var index2 = userAgent.indexOf(')');
288
- if (index1 !== -1 && index2 !== -1) {
289
- var value = userAgent.substring(index1 + 1, index2);
290
- return `${value}`;
291
- }
292
- }
293
- if (/windows/i.test(userAgent))
294
- return `Windows`;
295
- if (/mac/i.test(userAgent))
296
- return `Mac`;
297
- return null;
298
- }
299
235
  function getCookie(val) {
300
236
  // const expirationDate = new Date();
301
237
  // expirationDate.setDate(expirationDate.getDate() + 100);
@@ -734,12 +670,15 @@
734
670
  const bffDataSource = React.useMemo(() => {
735
671
  return dataSources === null || dataSources === void 0 ? void 0 : dataSources.find((d) => d.type === DataSourceType.BFF);
736
672
  }, [dataSources]);
673
+ const fakeUserId = React.useMemo(() => {
674
+ var _a;
675
+ return ((_a = bffDataSource === null || bffDataSource === void 0 ? void 0 : bffDataSource.headers) === null || _a === void 0 ? void 0 : _a['x-app-id']) + storeAndLoadFeUserId();
676
+ }, [bffDataSource]);
737
677
  // bff API 请求方法
738
678
  const bffFetch = React.useCallback((path, options) => {
739
679
  if (!bffDataSource)
740
680
  return;
741
681
  const url = bffDataSource.url;
742
- const fakeUserId = storeAndLoadFeUserId();
743
682
  if (options === null || options === void 0 ? void 0 : options.query) {
744
683
  const queryString = qs.stringify(options.query);
745
684
  path = `${path}?${queryString}`;
@@ -747,19 +686,19 @@
747
686
  // 事件上报优化
748
687
  // Beacon API 用于发送异步和非阻塞请求到服务器。这类请求不需要响应。
749
688
  if (options.type === 'beacon' && navigator.sendBeacon) {
750
- return navigator.sendBeacon(`${url}/api/v1${path}`, new Blob([
689
+ return navigator.sendBeacon(`${url}/api/${path}`, new Blob([
751
690
  JSON.stringify(Object.assign(Object.assign(Object.assign({}, options.body), bffDataSource.headers), { 'x-user-id': fakeUserId }))
752
691
  ], { type: 'application/json;charset=UTF-8' }));
753
692
  }
754
693
  return window
755
- .fetch(`${url}/api/v1${path}`, {
694
+ .fetch(`${url}/api/${path}`, {
756
695
  headers: Object.assign({ 'Content-Type': 'application/json', 'x-user-id': fakeUserId }, bffDataSource.headers),
757
696
  method: options.method,
758
697
  body: JSON.stringify(options.body)
759
698
  })
760
699
  .then((res) => res.json())
761
700
  .catch((err) => Promise.reject(err));
762
- }, [bffDataSource]);
701
+ }, [bffDataSource, fakeUserId]);
763
702
  // 获取推荐视频数据
764
703
  const getRecommendVideos = React.useCallback((query) => __awaiter(void 0, void 0, void 0, function* () {
765
704
  var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
@@ -797,7 +736,7 @@
797
736
  const recurveRecList = (query) => __awaiter(void 0, void 0, void 0, function* () {
798
737
  var _v, _w, _x, _y, _z, _0;
799
738
  query.pageNum = pageNum;
800
- result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/recommend/list', { method: 'POST', body: query }));
739
+ result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/list', { method: 'POST', body: query }));
801
740
  if (!(result === null || result === void 0 ? void 0 : result.success)) {
802
741
  return undefined;
803
742
  }
@@ -819,7 +758,7 @@
819
758
  if (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview) {
820
759
  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 });
821
760
  }
822
- const result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/recommend/list', { method: 'POST', body: query }));
761
+ const result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/list', { method: 'POST', body: query }));
823
762
  if (!(result === null || result === void 0 ? void 0 : result.success)) {
824
763
  return undefined;
825
764
  }
@@ -869,6 +808,7 @@
869
808
  return expire;
870
809
  }, [data]);
871
810
  const bffEventReport = React.useCallback(({ userInfo, eventInfo, reportLayId = true }) => {
811
+ var _a;
872
812
  // 关闭 BFF 事件上报
873
813
  if (!enableReportEvent || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview)) {
874
814
  return;
@@ -881,7 +821,7 @@
881
821
  };
882
822
  }
883
823
  const sessionID = storeAndLoadFeSessionId();
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 + '' }));
824
+ const ef = Object.assign(Object.assign(Object.assign(Object.assign({ sessionID, rtc: curReqInfo.rtc, requestId: curReqInfo.requestId }, { playbookType }), (layoutVariantId && reportLayId && { layoutVariantId })), eventInfo), ((eventInfo === null || eventInfo === void 0 ? void 0 : eventInfo.position) && channel && { position: Number(eventInfo === null || eventInfo === void 0 ? void 0 : eventInfo.position) + 1 + '' }));
885
825
  const realUserInfo = Object.entries(userInfo).map(([k, v]) => ({ name: k, value: v }));
886
826
  const realEventInfo = Object.entries(ef)
887
827
  .map(([k, v]) => v && { name: k, value: v })
@@ -890,14 +830,23 @@
890
830
  console.log('userInfo:', userInfo);
891
831
  console.log('eventInfo:', ef);
892
832
  console.log('========= 结束 =========');
893
- return bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/event/report', {
833
+ 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}`, {
894
834
  method: 'POST',
895
835
  body: { userInfo: realUserInfo, eventInfo: realEventInfo },
896
836
  type: 'beacon'
897
837
  });
898
- }, [bffFetch, curReqInfo, enableReportEvent, globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview, layoutVariantId, globalConfig, playbookType]);
838
+ }, [
839
+ bffFetch,
840
+ curReqInfo,
841
+ enableReportEvent,
842
+ globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview,
843
+ layoutVariantId,
844
+ globalConfig,
845
+ playbookType,
846
+ bffDataSource
847
+ ]);
899
848
  const bffFbReport = React.useCallback(({ eventName, product }) => {
900
- var _a, _b, _c, _d, _e;
849
+ var _a, _b, _c, _d, _e, _f;
901
850
  if (!enableReportEvent ||
902
851
  !enabledMetaConversionApi ||
903
852
  (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview) ||
@@ -909,7 +858,7 @@
909
858
  const fbclid = urlParams === null || urlParams === void 0 ? void 0 : urlParams.get('fbclid');
910
859
  const fix_par = {
911
860
  event_source_url: (_c = window === null || window === void 0 ? void 0 : window.location) === null || _c === void 0 ? void 0 : _c.href,
912
- external_id: storeAndLoadFeUserId(),
861
+ external_id: fakeUserId,
913
862
  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 : '',
914
863
  fbc: fbclid ? `fb.2.${new Date().getTime()}.${fbclid}` : '',
915
864
  fbp: getCookie('_fbp') ? `fb.2.${new Date().getTime()}.${getCookie('_fbp')}` : '',
@@ -961,22 +910,30 @@
961
910
  }
962
911
  };
963
912
  getEventParams(jsonParams);
964
- return bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/fb/events', {
913
+ 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}`, {
965
914
  method: 'POST',
966
915
  body: jsonParams,
967
916
  type: 'beacon'
968
917
  });
969
- }, [bffFetch, enableReportEvent, enabledMetaConversionApi, globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview, globalConfig]);
918
+ }, [
919
+ bffFetch,
920
+ enableReportEvent,
921
+ enabledMetaConversionApi,
922
+ globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview,
923
+ globalConfig,
924
+ fakeUserId,
925
+ bffDataSource
926
+ ]);
970
927
  const bffMutateLike = React.useCallback((body) => __awaiter(void 0, void 0, void 0, function* () {
971
- const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/recommend/like', { method: 'POST', body }));
928
+ const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/like', { method: 'POST', body }));
972
929
  return res === null || res === void 0 ? void 0 : res.success;
973
930
  }), [bffFetch]);
974
931
  const bffMutateUnlike = React.useCallback((body) => __awaiter(void 0, void 0, void 0, function* () {
975
- const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/recommend/unlike', { method: 'POST', body }));
932
+ const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/unlike', { method: 'POST', body }));
976
933
  return res === null || res === void 0 ? void 0 : res.success;
977
934
  }), [bffFetch]);
978
935
  const bffSubmitForm = React.useCallback((body) => __awaiter(void 0, void 0, void 0, function* () {
979
- const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/customform', { method: 'POST', body }));
936
+ const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/customform', { method: 'POST', body }));
980
937
  return res === null || res === void 0 ? void 0 : res.success;
981
938
  }), [bffFetch]);
982
939
  // 获取 Tag
@@ -991,7 +948,7 @@
991
948
  const key = val.split('=')[0];
992
949
  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);
993
950
  })) === null || _9 === void 0 ? void 0 : _9.join('&')) !== null && _10 !== void 0 ? _10 : '';
994
- const result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/tag/list', { method: 'GET', query: { channel: decodeURIComponent(val) } }));
951
+ const result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/tag/list', { method: 'GET', query: { channel: decodeURIComponent(val) } }));
995
952
  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 : []);
996
953
  }
997
954
  catch (e) {
@@ -1065,10 +1022,10 @@
1065
1022
  let curData;
1066
1023
  let gldata;
1067
1024
  if (data === null || data === void 0 ? void 0 : data.layoutVariantId) {
1025
+ layId = data === null || data === void 0 ? void 0 : data.layoutVariantId;
1026
+ setLayoutVariantId(data === null || data === void 0 ? void 0 : data.layoutVariantId);
1068
1027
  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];
1069
1028
  if (id) {
1070
- layId = id;
1071
- setLayoutVariantId(id);
1072
1029
  curData = dataList === null || dataList === void 0 ? void 0 : dataList.find((item) => (item === null || item === void 0 ? void 0 : item.id) === id);
1073
1030
  if (curData) {
1074
1031
  setPageData(curData);
@@ -10155,7 +10112,7 @@
10155
10112
  * @Author: binruan@chatlabs.com
10156
10113
  * @Date: 2024-03-20 14:56:16
10157
10114
  * @LastEditors: binruan@chatlabs.com
10158
- * @LastEditTime: 2024-10-24 17:51:19
10115
+ * @LastEditTime: 2024-12-20 14:32:26
10159
10116
  * @FilePath: \pb-sxp-ui\src\core\utils\materials.ts
10160
10117
  *
10161
10118
  */
@@ -10193,14 +10150,16 @@
10193
10150
  };
10194
10151
  const getPriceText = ({ product, enableFormattedPrice, globalConfig, isHiddenDef, style }) => {
10195
10152
  var _a, _b, _c, _d, _e, _f, _g, _h;
10153
+ let text = '';
10196
10154
  if ((!(product === null || product === void 0 ? void 0 : product.currency) || !(product === null || product === void 0 ? void 0 : product.price)) && isHiddenDef)
10197
10155
  return null;
10198
- 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;
10199
- let text = '';
10156
+ 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);
10157
+ if (typeof price !== 'number')
10158
+ return text;
10200
10159
  let priceSymbol = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.priceSymbol;
10201
10160
  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 : '' : '$';
10202
10161
  const isToLocStr = enableFormattedPrice === undefined || enableFormattedPrice;
10203
- let decPic = price.toString();
10162
+ let decPic = price === null || price === void 0 ? void 0 : price.toString();
10204
10163
  if (priceSymbol === null || priceSymbol === void 0 ? void 0 : priceSymbol.showTwoDecimalPoint) {
10205
10164
  decPic = price === null || price === void 0 ? void 0 : price.toFixed(2);
10206
10165
  }