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/index.cjs +46 -87
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +46 -87
- package/dist/index.js.map +1 -1
- package/dist/index.min.cjs +6 -6
- package/dist/index.min.cjs.map +1 -1
- package/dist/index.min.js +6 -6
- package/dist/index.min.js.map +1 -1
- package/dist/pb-ui.js +46 -87
- package/dist/pb-ui.js.map +1 -1
- package/dist/pb-ui.min.js +6 -6
- package/dist/pb-ui.min.js.map +1 -1
- package/es/core/context/SxpDataSourceProvider.js +41 -20
- package/es/core/utils/materials.js +5 -3
- package/lib/core/context/SxpDataSourceProvider.js +40 -19
- package/lib/core/utils/materials.js +5 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -239,70 +239,6 @@ const setFontForText = (textContent, style) => {
|
|
239
239
|
}
|
240
240
|
return content;
|
241
241
|
};
|
242
|
-
function getBrowserInfo() {
|
243
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
244
|
-
let userAgent = self.navigator.userAgent;
|
245
|
-
if (!userAgent)
|
246
|
-
return null;
|
247
|
-
if (/edge\/([\d\.]+)/i.exec(userAgent))
|
248
|
-
return `Edge ${(_a = /edge\/([\d\.]+)/i.exec(userAgent)) === null || _a === void 0 ? void 0 : _a[1]}`;
|
249
|
-
if (/edg\/([\d\.]+)/i.exec(userAgent))
|
250
|
-
return `Edge(Chromium) ${(_b = /edge\/([\d\.]+)/i.exec(userAgent)) === null || _b === void 0 ? void 0 : _b[1]}`;
|
251
|
-
if (/msie/i.test(userAgent))
|
252
|
-
return `Internet Explorer ${(_c = /msie ([\d\.]+)/i.exec(userAgent)) === null || _c === void 0 ? void 0 : _c[1]}`;
|
253
|
-
if (/Trident/i.test(userAgent))
|
254
|
-
return `Internet Explorer ${(_d = /rv:([\d\.]+)/i.exec(userAgent)) === null || _d === void 0 ? void 0 : _d[1]}`;
|
255
|
-
if (/chrome/i.test(userAgent))
|
256
|
-
return `Chrome ${(_e = /chrome\/([\d\.]+)/i.exec(userAgent)) === null || _e === void 0 ? void 0 : _e[1]}`;
|
257
|
-
if (/firefox/i.test(userAgent))
|
258
|
-
return `Firefox ${(_f = /firefox\/([\d\.]+)/i.exec(userAgent)) === null || _f === void 0 ? void 0 : _f[1]}`;
|
259
|
-
if (/safari/i.test(userAgent))
|
260
|
-
return `Safari ${(_g = /version\/([\d\.]+)/i.exec(userAgent)) === null || _g === void 0 ? void 0 : _g[1]}`;
|
261
|
-
return null;
|
262
|
-
}
|
263
|
-
function getSystem() {
|
264
|
-
var _a, _b, _c;
|
265
|
-
let userAgent = self.navigator.userAgent;
|
266
|
-
if (!userAgent)
|
267
|
-
return null;
|
268
|
-
if (/iphone/i.test(userAgent))
|
269
|
-
return `IOS ${(_a = userAgent.match(/OS\s(.*?)\slike/)) === null || _a === void 0 ? void 0 : _a[1]}`;
|
270
|
-
if (/android/i.test(userAgent))
|
271
|
-
return `Android ${(_b = userAgent.match(/Android\s(.*?)\;/)) === null || _b === void 0 ? void 0 : _b[1]}`;
|
272
|
-
if (/windows/i.test(userAgent))
|
273
|
-
return `Windows ${(_c = userAgent.match(/Windows\s(.*?)\;/)) === null || _c === void 0 ? void 0 : _c[1]}`;
|
274
|
-
if (/mac/i.test(userAgent))
|
275
|
-
return `Mac OS`;
|
276
|
-
return null;
|
277
|
-
}
|
278
|
-
function getDevice$1() {
|
279
|
-
let userAgent = self.navigator.userAgent;
|
280
|
-
if (!userAgent)
|
281
|
-
return null;
|
282
|
-
if (/iphone/i.test(userAgent))
|
283
|
-
return `iPhone`;
|
284
|
-
if (/android/i.test(userAgent)) {
|
285
|
-
// var index1 = userAgent.indexOf(';');
|
286
|
-
// var index2 = userAgent.indexOf(';', index1 + 1);
|
287
|
-
// var index3 = userAgent.indexOf(';', index2 + 1);
|
288
|
-
// var index4 = userAgent.indexOf(';', index3 + 1);
|
289
|
-
// if (index2 !== -1 && index3 !== -1) {
|
290
|
-
// var value1 = userAgent.substring(index3 + 1, index4);
|
291
|
-
// return `${value1}`;
|
292
|
-
// }
|
293
|
-
var index1 = userAgent.indexOf('(');
|
294
|
-
var index2 = userAgent.indexOf(')');
|
295
|
-
if (index1 !== -1 && index2 !== -1) {
|
296
|
-
var value = userAgent.substring(index1 + 1, index2);
|
297
|
-
return `${value}`;
|
298
|
-
}
|
299
|
-
}
|
300
|
-
if (/windows/i.test(userAgent))
|
301
|
-
return `Windows`;
|
302
|
-
if (/mac/i.test(userAgent))
|
303
|
-
return `Mac`;
|
304
|
-
return null;
|
305
|
-
}
|
306
242
|
function getCookie(val) {
|
307
243
|
// const expirationDate = new Date();
|
308
244
|
// expirationDate.setDate(expirationDate.getDate() + 100);
|
@@ -741,12 +677,15 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
741
677
|
const bffDataSource = React.useMemo(() => {
|
742
678
|
return dataSources === null || dataSources === void 0 ? void 0 : dataSources.find((d) => d.type === DataSourceType.BFF);
|
743
679
|
}, [dataSources]);
|
680
|
+
const fakeUserId = React.useMemo(() => {
|
681
|
+
var _a;
|
682
|
+
return ((_a = bffDataSource === null || bffDataSource === void 0 ? void 0 : bffDataSource.headers) === null || _a === void 0 ? void 0 : _a['x-app-id']) + storeAndLoadFeUserId();
|
683
|
+
}, [bffDataSource]);
|
744
684
|
// bff API 请求方法
|
745
685
|
const bffFetch = React.useCallback((path, options) => {
|
746
686
|
if (!bffDataSource)
|
747
687
|
return;
|
748
688
|
const url = bffDataSource.url;
|
749
|
-
const fakeUserId = storeAndLoadFeUserId();
|
750
689
|
if (options === null || options === void 0 ? void 0 : options.query) {
|
751
690
|
const queryString = qs.stringify(options.query);
|
752
691
|
path = `${path}?${queryString}`;
|
@@ -754,19 +693,19 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
754
693
|
// 事件上报优化
|
755
694
|
// Beacon API 用于发送异步和非阻塞请求到服务器。这类请求不需要响应。
|
756
695
|
if (options.type === 'beacon' && navigator.sendBeacon) {
|
757
|
-
return navigator.sendBeacon(`${url}/api
|
696
|
+
return navigator.sendBeacon(`${url}/api/${path}`, new Blob([
|
758
697
|
JSON.stringify(Object.assign(Object.assign(Object.assign({}, options.body), bffDataSource.headers), { 'x-user-id': fakeUserId }))
|
759
698
|
], { type: 'application/json;charset=UTF-8' }));
|
760
699
|
}
|
761
700
|
return window
|
762
|
-
.fetch(`${url}/api
|
701
|
+
.fetch(`${url}/api/${path}`, {
|
763
702
|
headers: Object.assign({ 'Content-Type': 'application/json', 'x-user-id': fakeUserId }, bffDataSource.headers),
|
764
703
|
method: options.method,
|
765
704
|
body: JSON.stringify(options.body)
|
766
705
|
})
|
767
706
|
.then((res) => res.json())
|
768
707
|
.catch((err) => Promise.reject(err));
|
769
|
-
}, [bffDataSource]);
|
708
|
+
}, [bffDataSource, fakeUserId]);
|
770
709
|
// 获取推荐视频数据
|
771
710
|
const getRecommendVideos = React.useCallback((query) => __awaiter(void 0, void 0, void 0, function* () {
|
772
711
|
var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
@@ -804,7 +743,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
804
743
|
const recurveRecList = (query) => __awaiter(void 0, void 0, void 0, function* () {
|
805
744
|
var _v, _w, _x, _y, _z, _0;
|
806
745
|
query.pageNum = pageNum;
|
807
|
-
result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/recommend/list', { method: 'POST', body: query }));
|
746
|
+
result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/list', { method: 'POST', body: query }));
|
808
747
|
if (!(result === null || result === void 0 ? void 0 : result.success)) {
|
809
748
|
return undefined;
|
810
749
|
}
|
@@ -826,7 +765,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
826
765
|
if (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview) {
|
827
766
|
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 });
|
828
767
|
}
|
829
|
-
const result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/recommend/list', { method: 'POST', body: query }));
|
768
|
+
const result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/list', { method: 'POST', body: query }));
|
830
769
|
if (!(result === null || result === void 0 ? void 0 : result.success)) {
|
831
770
|
return undefined;
|
832
771
|
}
|
@@ -876,6 +815,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
876
815
|
return expire;
|
877
816
|
}, [data]);
|
878
817
|
const bffEventReport = React.useCallback(({ userInfo, eventInfo, reportLayId = true }) => {
|
818
|
+
var _a;
|
879
819
|
// 关闭 BFF 事件上报
|
880
820
|
if (!enableReportEvent || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview)) {
|
881
821
|
return;
|
@@ -888,7 +828,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
888
828
|
};
|
889
829
|
}
|
890
830
|
const sessionID = storeAndLoadFeSessionId();
|
891
|
-
const ef = Object.assign(Object.assign(Object.assign(Object.assign(
|
831
|
+
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 + '' }));
|
892
832
|
const realUserInfo = Object.entries(userInfo).map(([k, v]) => ({ name: k, value: v }));
|
893
833
|
const realEventInfo = Object.entries(ef)
|
894
834
|
.map(([k, v]) => v && { name: k, value: v })
|
@@ -897,14 +837,23 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
897
837
|
console.log('userInfo:', userInfo);
|
898
838
|
console.log('eventInfo:', ef);
|
899
839
|
console.log('========= 结束 =========');
|
900
|
-
return bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch(
|
840
|
+
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}`, {
|
901
841
|
method: 'POST',
|
902
842
|
body: { userInfo: realUserInfo, eventInfo: realEventInfo },
|
903
843
|
type: 'beacon'
|
904
844
|
});
|
905
|
-
}, [
|
845
|
+
}, [
|
846
|
+
bffFetch,
|
847
|
+
curReqInfo,
|
848
|
+
enableReportEvent,
|
849
|
+
globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview,
|
850
|
+
layoutVariantId,
|
851
|
+
globalConfig,
|
852
|
+
playbookType,
|
853
|
+
bffDataSource
|
854
|
+
]);
|
906
855
|
const bffFbReport = React.useCallback(({ eventName, product }) => {
|
907
|
-
var _a, _b, _c, _d, _e;
|
856
|
+
var _a, _b, _c, _d, _e, _f;
|
908
857
|
if (!enableReportEvent ||
|
909
858
|
!enabledMetaConversionApi ||
|
910
859
|
(globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview) ||
|
@@ -916,7 +865,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
916
865
|
const fbclid = urlParams === null || urlParams === void 0 ? void 0 : urlParams.get('fbclid');
|
917
866
|
const fix_par = {
|
918
867
|
event_source_url: (_c = window === null || window === void 0 ? void 0 : window.location) === null || _c === void 0 ? void 0 : _c.href,
|
919
|
-
external_id:
|
868
|
+
external_id: fakeUserId,
|
920
869
|
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 : '',
|
921
870
|
fbc: fbclid ? `fb.2.${new Date().getTime()}.${fbclid}` : '',
|
922
871
|
fbp: getCookie('_fbp') ? `fb.2.${new Date().getTime()}.${getCookie('_fbp')}` : '',
|
@@ -968,22 +917,30 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
968
917
|
}
|
969
918
|
};
|
970
919
|
getEventParams(jsonParams);
|
971
|
-
return bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch(
|
920
|
+
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}`, {
|
972
921
|
method: 'POST',
|
973
922
|
body: jsonParams,
|
974
923
|
type: 'beacon'
|
975
924
|
});
|
976
|
-
}, [
|
925
|
+
}, [
|
926
|
+
bffFetch,
|
927
|
+
enableReportEvent,
|
928
|
+
enabledMetaConversionApi,
|
929
|
+
globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview,
|
930
|
+
globalConfig,
|
931
|
+
fakeUserId,
|
932
|
+
bffDataSource
|
933
|
+
]);
|
977
934
|
const bffMutateLike = React.useCallback((body) => __awaiter(void 0, void 0, void 0, function* () {
|
978
|
-
const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/recommend/like', { method: 'POST', body }));
|
935
|
+
const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/like', { method: 'POST', body }));
|
979
936
|
return res === null || res === void 0 ? void 0 : res.success;
|
980
937
|
}), [bffFetch]);
|
981
938
|
const bffMutateUnlike = React.useCallback((body) => __awaiter(void 0, void 0, void 0, function* () {
|
982
|
-
const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/recommend/unlike', { method: 'POST', body }));
|
939
|
+
const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/unlike', { method: 'POST', body }));
|
983
940
|
return res === null || res === void 0 ? void 0 : res.success;
|
984
941
|
}), [bffFetch]);
|
985
942
|
const bffSubmitForm = React.useCallback((body) => __awaiter(void 0, void 0, void 0, function* () {
|
986
|
-
const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/customform', { method: 'POST', body }));
|
943
|
+
const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/customform', { method: 'POST', body }));
|
987
944
|
return res === null || res === void 0 ? void 0 : res.success;
|
988
945
|
}), [bffFetch]);
|
989
946
|
// 获取 Tag
|
@@ -998,7 +955,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
998
955
|
const key = val.split('=')[0];
|
999
956
|
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);
|
1000
957
|
})) === null || _9 === void 0 ? void 0 : _9.join('&')) !== null && _10 !== void 0 ? _10 : '';
|
1001
|
-
const result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/tag/list', { method: 'GET', query: { channel: decodeURIComponent(val) } }));
|
958
|
+
const result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/tag/list', { method: 'GET', query: { channel: decodeURIComponent(val) } }));
|
1002
959
|
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 : []);
|
1003
960
|
}
|
1004
961
|
catch (e) {
|
@@ -1072,10 +1029,10 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
1072
1029
|
let curData;
|
1073
1030
|
let gldata;
|
1074
1031
|
if (data === null || data === void 0 ? void 0 : data.layoutVariantId) {
|
1032
|
+
layId = data === null || data === void 0 ? void 0 : data.layoutVariantId;
|
1033
|
+
setLayoutVariantId(data === null || data === void 0 ? void 0 : data.layoutVariantId);
|
1075
1034
|
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];
|
1076
1035
|
if (id) {
|
1077
|
-
layId = id;
|
1078
|
-
setLayoutVariantId(id);
|
1079
1036
|
curData = dataList === null || dataList === void 0 ? void 0 : dataList.find((item) => (item === null || item === void 0 ? void 0 : item.id) === id);
|
1080
1037
|
if (curData) {
|
1081
1038
|
setPageData(curData);
|
@@ -10162,7 +10119,7 @@ var CommodityGroup$1 = React.memo(CommodityGroup);
|
|
10162
10119
|
* @Author: binruan@chatlabs.com
|
10163
10120
|
* @Date: 2024-03-20 14:56:16
|
10164
10121
|
* @LastEditors: binruan@chatlabs.com
|
10165
|
-
* @LastEditTime: 2024-
|
10122
|
+
* @LastEditTime: 2024-12-20 14:32:26
|
10166
10123
|
* @FilePath: \pb-sxp-ui\src\core\utils\materials.ts
|
10167
10124
|
*
|
10168
10125
|
*/
|
@@ -10200,14 +10157,16 @@ const getBgStyle = (imgSrc) => {
|
|
10200
10157
|
};
|
10201
10158
|
const getPriceText = ({ product, enableFormattedPrice, globalConfig, isHiddenDef, style }) => {
|
10202
10159
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
10160
|
+
let text = '';
|
10203
10161
|
if ((!(product === null || product === void 0 ? void 0 : product.currency) || !(product === null || product === void 0 ? void 0 : product.price)) && isHiddenDef)
|
10204
10162
|
return null;
|
10205
|
-
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;
|
10206
|
-
|
10163
|
+
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);
|
10164
|
+
if (typeof price !== 'number')
|
10165
|
+
return text;
|
10207
10166
|
let priceSymbol = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.priceSymbol;
|
10208
10167
|
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 : '' : '$';
|
10209
10168
|
const isToLocStr = enableFormattedPrice === undefined || enableFormattedPrice;
|
10210
|
-
let decPic = price.toString();
|
10169
|
+
let decPic = price === null || price === void 0 ? void 0 : price.toString();
|
10211
10170
|
if (priceSymbol === null || priceSymbol === void 0 ? void 0 : priceSymbol.showTwoDecimalPoint) {
|
10212
10171
|
decPic = price === null || price === void 0 ? void 0 : price.toFixed(2);
|
10213
10172
|
}
|