pb-sxp-ui 1.12.2 → 1.13.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.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.js
CHANGED
@@ -217,70 +217,6 @@ const setFontForText = (textContent, style) => {
|
|
217
217
|
}
|
218
218
|
return content;
|
219
219
|
};
|
220
|
-
function getBrowserInfo() {
|
221
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
222
|
-
let userAgent = self.navigator.userAgent;
|
223
|
-
if (!userAgent)
|
224
|
-
return null;
|
225
|
-
if (/edge\/([\d\.]+)/i.exec(userAgent))
|
226
|
-
return `Edge ${(_a = /edge\/([\d\.]+)/i.exec(userAgent)) === null || _a === void 0 ? void 0 : _a[1]}`;
|
227
|
-
if (/edg\/([\d\.]+)/i.exec(userAgent))
|
228
|
-
return `Edge(Chromium) ${(_b = /edge\/([\d\.]+)/i.exec(userAgent)) === null || _b === void 0 ? void 0 : _b[1]}`;
|
229
|
-
if (/msie/i.test(userAgent))
|
230
|
-
return `Internet Explorer ${(_c = /msie ([\d\.]+)/i.exec(userAgent)) === null || _c === void 0 ? void 0 : _c[1]}`;
|
231
|
-
if (/Trident/i.test(userAgent))
|
232
|
-
return `Internet Explorer ${(_d = /rv:([\d\.]+)/i.exec(userAgent)) === null || _d === void 0 ? void 0 : _d[1]}`;
|
233
|
-
if (/chrome/i.test(userAgent))
|
234
|
-
return `Chrome ${(_e = /chrome\/([\d\.]+)/i.exec(userAgent)) === null || _e === void 0 ? void 0 : _e[1]}`;
|
235
|
-
if (/firefox/i.test(userAgent))
|
236
|
-
return `Firefox ${(_f = /firefox\/([\d\.]+)/i.exec(userAgent)) === null || _f === void 0 ? void 0 : _f[1]}`;
|
237
|
-
if (/safari/i.test(userAgent))
|
238
|
-
return `Safari ${(_g = /version\/([\d\.]+)/i.exec(userAgent)) === null || _g === void 0 ? void 0 : _g[1]}`;
|
239
|
-
return null;
|
240
|
-
}
|
241
|
-
function getSystem() {
|
242
|
-
var _a, _b, _c;
|
243
|
-
let userAgent = self.navigator.userAgent;
|
244
|
-
if (!userAgent)
|
245
|
-
return null;
|
246
|
-
if (/iphone/i.test(userAgent))
|
247
|
-
return `IOS ${(_a = userAgent.match(/OS\s(.*?)\slike/)) === null || _a === void 0 ? void 0 : _a[1]}`;
|
248
|
-
if (/android/i.test(userAgent))
|
249
|
-
return `Android ${(_b = userAgent.match(/Android\s(.*?)\;/)) === null || _b === void 0 ? void 0 : _b[1]}`;
|
250
|
-
if (/windows/i.test(userAgent))
|
251
|
-
return `Windows ${(_c = userAgent.match(/Windows\s(.*?)\;/)) === null || _c === void 0 ? void 0 : _c[1]}`;
|
252
|
-
if (/mac/i.test(userAgent))
|
253
|
-
return `Mac OS`;
|
254
|
-
return null;
|
255
|
-
}
|
256
|
-
function getDevice$1() {
|
257
|
-
let userAgent = self.navigator.userAgent;
|
258
|
-
if (!userAgent)
|
259
|
-
return null;
|
260
|
-
if (/iphone/i.test(userAgent))
|
261
|
-
return `iPhone`;
|
262
|
-
if (/android/i.test(userAgent)) {
|
263
|
-
// var index1 = userAgent.indexOf(';');
|
264
|
-
// var index2 = userAgent.indexOf(';', index1 + 1);
|
265
|
-
// var index3 = userAgent.indexOf(';', index2 + 1);
|
266
|
-
// var index4 = userAgent.indexOf(';', index3 + 1);
|
267
|
-
// if (index2 !== -1 && index3 !== -1) {
|
268
|
-
// var value1 = userAgent.substring(index3 + 1, index4);
|
269
|
-
// return `${value1}`;
|
270
|
-
// }
|
271
|
-
var index1 = userAgent.indexOf('(');
|
272
|
-
var index2 = userAgent.indexOf(')');
|
273
|
-
if (index1 !== -1 && index2 !== -1) {
|
274
|
-
var value = userAgent.substring(index1 + 1, index2);
|
275
|
-
return `${value}`;
|
276
|
-
}
|
277
|
-
}
|
278
|
-
if (/windows/i.test(userAgent))
|
279
|
-
return `Windows`;
|
280
|
-
if (/mac/i.test(userAgent))
|
281
|
-
return `Mac`;
|
282
|
-
return null;
|
283
|
-
}
|
284
220
|
function getCookie(val) {
|
285
221
|
// const expirationDate = new Date();
|
286
222
|
// expirationDate.setDate(expirationDate.getDate() + 100);
|
@@ -719,12 +655,15 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
719
655
|
const bffDataSource = useMemo(() => {
|
720
656
|
return dataSources === null || dataSources === void 0 ? void 0 : dataSources.find((d) => d.type === DataSourceType.BFF);
|
721
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]);
|
722
662
|
// bff API 请求方法
|
723
663
|
const bffFetch = useCallback((path, options) => {
|
724
664
|
if (!bffDataSource)
|
725
665
|
return;
|
726
666
|
const url = bffDataSource.url;
|
727
|
-
const fakeUserId = storeAndLoadFeUserId();
|
728
667
|
if (options === null || options === void 0 ? void 0 : options.query) {
|
729
668
|
const queryString = qs.stringify(options.query);
|
730
669
|
path = `${path}?${queryString}`;
|
@@ -732,19 +671,19 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
732
671
|
// 事件上报优化
|
733
672
|
// Beacon API 用于发送异步和非阻塞请求到服务器。这类请求不需要响应。
|
734
673
|
if (options.type === 'beacon' && navigator.sendBeacon) {
|
735
|
-
return navigator.sendBeacon(`${url}/api
|
674
|
+
return navigator.sendBeacon(`${url}/api/${path}`, new Blob([
|
736
675
|
JSON.stringify(Object.assign(Object.assign(Object.assign({}, options.body), bffDataSource.headers), { 'x-user-id': fakeUserId }))
|
737
676
|
], { type: 'application/json;charset=UTF-8' }));
|
738
677
|
}
|
739
678
|
return window
|
740
|
-
.fetch(`${url}/api
|
679
|
+
.fetch(`${url}/api/${path}`, {
|
741
680
|
headers: Object.assign({ 'Content-Type': 'application/json', 'x-user-id': fakeUserId }, bffDataSource.headers),
|
742
681
|
method: options.method,
|
743
682
|
body: JSON.stringify(options.body)
|
744
683
|
})
|
745
684
|
.then((res) => res.json())
|
746
685
|
.catch((err) => Promise.reject(err));
|
747
|
-
}, [bffDataSource]);
|
686
|
+
}, [bffDataSource, fakeUserId]);
|
748
687
|
// 获取推荐视频数据
|
749
688
|
const getRecommendVideos = useCallback((query) => __awaiter(void 0, void 0, void 0, function* () {
|
750
689
|
var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
@@ -782,7 +721,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
782
721
|
const recurveRecList = (query) => __awaiter(void 0, void 0, void 0, function* () {
|
783
722
|
var _v, _w, _x, _y, _z, _0;
|
784
723
|
query.pageNum = pageNum;
|
785
|
-
result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/recommend/list', { method: 'POST', body: query }));
|
724
|
+
result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/list', { method: 'POST', body: query }));
|
786
725
|
if (!(result === null || result === void 0 ? void 0 : result.success)) {
|
787
726
|
return undefined;
|
788
727
|
}
|
@@ -804,7 +743,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
804
743
|
if (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview) {
|
805
744
|
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 });
|
806
745
|
}
|
807
|
-
const result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/recommend/list', { method: 'POST', body: query }));
|
746
|
+
const 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
|
}
|
@@ -854,6 +793,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
854
793
|
return expire;
|
855
794
|
}, [data]);
|
856
795
|
const bffEventReport = useCallback(({ userInfo, eventInfo, reportLayId = true }) => {
|
796
|
+
var _a;
|
857
797
|
// 关闭 BFF 事件上报
|
858
798
|
if (!enableReportEvent || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview)) {
|
859
799
|
return;
|
@@ -866,7 +806,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
866
806
|
};
|
867
807
|
}
|
868
808
|
const sessionID = storeAndLoadFeSessionId();
|
869
|
-
const ef = Object.assign(Object.assign(Object.assign(Object.assign(
|
809
|
+
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 + '' }));
|
870
810
|
const realUserInfo = Object.entries(userInfo).map(([k, v]) => ({ name: k, value: v }));
|
871
811
|
const realEventInfo = Object.entries(ef)
|
872
812
|
.map(([k, v]) => v && { name: k, value: v })
|
@@ -875,14 +815,23 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
875
815
|
console.log('userInfo:', userInfo);
|
876
816
|
console.log('eventInfo:', ef);
|
877
817
|
console.log('========= 结束 =========');
|
878
|
-
return bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch(
|
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}`, {
|
879
819
|
method: 'POST',
|
880
820
|
body: { userInfo: realUserInfo, eventInfo: realEventInfo },
|
881
821
|
type: 'beacon'
|
882
822
|
});
|
883
|
-
}, [
|
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
|
+
]);
|
884
833
|
const bffFbReport = useCallback(({ eventName, product }) => {
|
885
|
-
var _a, _b, _c, _d, _e;
|
834
|
+
var _a, _b, _c, _d, _e, _f;
|
886
835
|
if (!enableReportEvent ||
|
887
836
|
!enabledMetaConversionApi ||
|
888
837
|
(globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview) ||
|
@@ -894,7 +843,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
894
843
|
const fbclid = urlParams === null || urlParams === void 0 ? void 0 : urlParams.get('fbclid');
|
895
844
|
const fix_par = {
|
896
845
|
event_source_url: (_c = window === null || window === void 0 ? void 0 : window.location) === null || _c === void 0 ? void 0 : _c.href,
|
897
|
-
external_id:
|
846
|
+
external_id: fakeUserId,
|
898
847
|
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 : '',
|
899
848
|
fbc: fbclid ? `fb.2.${new Date().getTime()}.${fbclid}` : '',
|
900
849
|
fbp: getCookie('_fbp') ? `fb.2.${new Date().getTime()}.${getCookie('_fbp')}` : '',
|
@@ -946,22 +895,30 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
946
895
|
}
|
947
896
|
};
|
948
897
|
getEventParams(jsonParams);
|
949
|
-
return bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch(
|
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}`, {
|
950
899
|
method: 'POST',
|
951
900
|
body: jsonParams,
|
952
901
|
type: 'beacon'
|
953
902
|
});
|
954
|
-
}, [
|
903
|
+
}, [
|
904
|
+
bffFetch,
|
905
|
+
enableReportEvent,
|
906
|
+
enabledMetaConversionApi,
|
907
|
+
globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview,
|
908
|
+
globalConfig,
|
909
|
+
fakeUserId,
|
910
|
+
bffDataSource
|
911
|
+
]);
|
955
912
|
const bffMutateLike = useCallback((body) => __awaiter(void 0, void 0, void 0, function* () {
|
956
|
-
const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/recommend/like', { method: 'POST', body }));
|
913
|
+
const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/like', { method: 'POST', body }));
|
957
914
|
return res === null || res === void 0 ? void 0 : res.success;
|
958
915
|
}), [bffFetch]);
|
959
916
|
const bffMutateUnlike = useCallback((body) => __awaiter(void 0, void 0, void 0, function* () {
|
960
|
-
const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/recommend/unlike', { method: 'POST', body }));
|
917
|
+
const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/unlike', { method: 'POST', body }));
|
961
918
|
return res === null || res === void 0 ? void 0 : res.success;
|
962
919
|
}), [bffFetch]);
|
963
920
|
const bffSubmitForm = useCallback((body) => __awaiter(void 0, void 0, void 0, function* () {
|
964
|
-
const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/customform', { method: 'POST', body }));
|
921
|
+
const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/customform', { method: 'POST', body }));
|
965
922
|
return res === null || res === void 0 ? void 0 : res.success;
|
966
923
|
}), [bffFetch]);
|
967
924
|
// 获取 Tag
|
@@ -976,7 +933,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
976
933
|
const key = val.split('=')[0];
|
977
934
|
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);
|
978
935
|
})) === null || _9 === void 0 ? void 0 : _9.join('&')) !== null && _10 !== void 0 ? _10 : '';
|
979
|
-
const result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('/tag/list', { method: 'GET', query: { channel: decodeURIComponent(val) } }));
|
936
|
+
const result = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/tag/list', { method: 'GET', query: { channel: decodeURIComponent(val) } }));
|
980
937
|
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 : []);
|
981
938
|
}
|
982
939
|
catch (e) {
|
@@ -1050,10 +1007,10 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
1050
1007
|
let curData;
|
1051
1008
|
let gldata;
|
1052
1009
|
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);
|
1053
1012
|
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];
|
1054
1013
|
if (id) {
|
1055
|
-
layId = id;
|
1056
|
-
setLayoutVariantId(id);
|
1057
1014
|
curData = dataList === null || dataList === void 0 ? void 0 : dataList.find((item) => (item === null || item === void 0 ? void 0 : item.id) === id);
|
1058
1015
|
if (curData) {
|
1059
1016
|
setPageData(curData);
|
@@ -10140,7 +10097,7 @@ var CommodityGroup$1 = memo(CommodityGroup);
|
|
10140
10097
|
* @Author: binruan@chatlabs.com
|
10141
10098
|
* @Date: 2024-03-20 14:56:16
|
10142
10099
|
* @LastEditors: binruan@chatlabs.com
|
10143
|
-
* @LastEditTime: 2024-
|
10100
|
+
* @LastEditTime: 2024-12-20 14:32:26
|
10144
10101
|
* @FilePath: \pb-sxp-ui\src\core\utils\materials.ts
|
10145
10102
|
*
|
10146
10103
|
*/
|
@@ -10178,14 +10135,16 @@ const getBgStyle = (imgSrc) => {
|
|
10178
10135
|
};
|
10179
10136
|
const getPriceText = ({ product, enableFormattedPrice, globalConfig, isHiddenDef, style }) => {
|
10180
10137
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
10138
|
+
let text = '';
|
10181
10139
|
if ((!(product === null || product === void 0 ? void 0 : product.currency) || !(product === null || product === void 0 ? void 0 : product.price)) && isHiddenDef)
|
10182
10140
|
return null;
|
10183
|
-
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;
|
10184
|
-
|
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;
|
10185
10144
|
let priceSymbol = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.priceSymbol;
|
10186
10145
|
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 : '' : '$';
|
10187
10146
|
const isToLocStr = enableFormattedPrice === undefined || enableFormattedPrice;
|
10188
|
-
let decPic = price.toString();
|
10147
|
+
let decPic = price === null || price === void 0 ? void 0 : price.toString();
|
10189
10148
|
if (priceSymbol === null || priceSymbol === void 0 ? void 0 : priceSymbol.showTwoDecimalPoint) {
|
10190
10149
|
decPic = price === null || price === void 0 ? void 0 : price.toFixed(2);
|
10191
10150
|
}
|