@fonixtree/magic-design 1.0.164 → 1.0.166

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.
@@ -278,17 +278,34 @@ var LAYOUT_IMAGE_SIZE = {
278
278
  */
279
279
 
280
280
  var insertArrayRandomly = function insertArrayRandomly(arr1, arr2) {
281
- // 创建一个复制的第一个数组,以免修改原数组
281
+ if (arr1.length < 1) {
282
+ return [];
283
+ }
284
+
285
+ if (arr1.length < 2) {
286
+ return __spreadArrays(arr1, arr2);
287
+ }
288
+
289
+ if (arr1.length === 2) {
290
+ return __spreadArrays([arr1[0]], arr2, [arr1[1]]);
291
+ }
292
+
293
+ if (arr1.length === 3) {
294
+ return __spreadArrays([arr1[0]], arr2, arr1.splice(1));
295
+ } // 创建一个复制的第一个数组,以免修改原数组
296
+
297
+
282
298
  var result = __spreadArrays(arr1); // 记录已插入元素的位置
283
299
 
284
300
 
285
301
  var insertedIndices = [];
286
302
 
287
303
  var _loop_1 = function _loop_1(i) {
288
- var randomIndex; // 确保生成的随机索引与已插入的索引相隔至少两个位置
304
+ var randomIndex; // 确保生成的随机索引不在首尾,并且与已插入的索引相隔至少两个位置
289
305
 
290
306
  do {
291
- randomIndex = Math.floor(Math.random() * (result.length + 1)); // eslint-disable-next-line no-loop-func
307
+ randomIndex = Math.floor(Math.random() * (result.length - 2)) + 1; // 1 到 result.length - 2
308
+ // eslint-disable-next-line no-loop-func
292
309
  } while (insertedIndices.some(function (index) {
293
310
  return Math.abs(index - randomIndex) < 2;
294
311
  })); // 在随机位置插入第二个数组的元素
@@ -308,10 +325,12 @@ var insertArrayRandomly = function insertArrayRandomly(arr1, arr2) {
308
325
  return result;
309
326
  };
310
327
 
311
- var getRandomItemsAndRemove = function getRandomItemsAndRemove(arr, count) {
328
+ var getRandomItemsAndRemove = function getRandomItemsAndRemove(arr, list) {
329
+ var _count = Math.ceil(list.length / 5);
330
+
312
331
  var result = []; // eslint-disable-next-line no-plusplus
313
332
 
314
- for (var i = 0; i < count && arr.length > 0; i++) {
333
+ for (var i = 0; i < _count && arr.length > 0; i++) {
315
334
  var randomIndex = Math.floor(Math.random() * arr.length);
316
335
  result.push(arr.splice(randomIndex, 1)[0]);
317
336
  }
@@ -379,7 +398,7 @@ function (_super) {
379
398
 
380
399
  _this.getAdvertise = function () {
381
400
  return __awaiter(_this, void 0, void 0, function () {
382
- var res;
401
+ var ad;
383
402
  return __generator(this, function (_a) {
384
403
  switch (_a.label) {
385
404
  case 0:
@@ -388,18 +407,16 @@ function (_super) {
388
407
  , (0, _commonUtil.commonFetch)('/designer/v1/h5/ad/today/valid/MagicDesignRecommendation/list', {}, 'GET')];
389
408
 
390
409
  case 1:
391
- res = _a.sent();
410
+ ad = _a.sent();
392
411
 
393
- if (res === null || res === void 0 ? void 0 : res.length) {
412
+ if (ad === null || ad === void 0 ? void 0 : ad.length) {
394
413
  return [2
395
414
  /*return*/
396
- , res.map(function (it) {
397
- var _a, _b, _c;
398
-
415
+ , ad[0].advertiseContents.map(function (it) {
399
416
  return {
400
417
  type: 'ad',
401
- url: (_b = (_a = it === null || it === void 0 ? void 0 : it.advertiseContents) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.url,
402
- adObj: (_c = it === null || it === void 0 ? void 0 : it.advertiseContents) === null || _c === void 0 ? void 0 : _c[0]
418
+ url: it === null || it === void 0 ? void 0 : it.url,
419
+ adObj: it
403
420
  };
404
421
  })];
405
422
  }
@@ -531,6 +548,9 @@ function (_super) {
531
548
  , 10];
532
549
 
533
550
  case 10:
551
+ if (!window.magicDesign.showRecommendAds) return [3
552
+ /*break*/
553
+ , 12];
534
554
  _h = this;
535
555
  return [4
536
556
  /*yield*/
@@ -538,9 +558,11 @@ function (_super) {
538
558
 
539
559
  case 11:
540
560
  _h.ads = _m.sent();
541
- insertAds = getRandomItemsAndRemove(this.ads, 2);
561
+ insertAds = getRandomItemsAndRemove(this.ads, newData);
542
562
  newData = insertArrayRandomly(newData, insertAds);
563
+ _m.label = 12;
543
564
 
565
+ case 12:
544
566
  if (!(0, _coreUtil.isDesignMode)()) {
545
567
  _cache = (0, _storeUtil.getMagicStore)("recommend_" + pageId + "_" + recommendId);
546
568
  (0, _storeUtil.setMagicStore)("recommend_" + pageId + "_" + recommendId, __assign(__assign({}, _cache), (_k = {}, _k["products" + index] = newData, _k.endTime = Date.now() + 3 * 60 * 1000, _k)));
@@ -45,7 +45,8 @@ var setDesignConfig = function setDesignConfig(props) {
45
45
  var config = props.config,
46
46
  device = props.device,
47
47
  isPreview = props.isPreview,
48
- projectCode = props.projectCode;
48
+ projectCode = props.projectCode,
49
+ showRecommendAds = props.showRecommendAds;
49
50
  window.magicDesign = __assign(__assign({
50
51
  pageBackground: '#f2f2f2',
51
52
  mode: 'renderer',
@@ -55,7 +56,8 @@ var setDesignConfig = function setDesignConfig(props) {
55
56
  }, config), {
56
57
  projectCode: projectCode,
57
58
  compSpacing: Number(config.compSpacing),
58
- compWidth: Number(config.compWidth)
59
+ compWidth: Number(config.compWidth),
60
+ showRecommendAds: showRecommendAds
59
61
  });
60
62
  };
61
63
  /**
@@ -1,5 +1,5 @@
1
1
  {
2
- "COLLECT_VOUCHER_SUCCESS": "Collect voucher success!",
2
+ "COLLECT_VOUCHER_SUCCESS": "Voucher collection successful!",
3
3
  "LOGIN_BUTTON": "Login Button",
4
4
  "SEARCH_ICON": "Search Icon",
5
5
  "NAVIGATION": "Navigation",
@@ -1,5 +1,5 @@
1
1
  {
2
- "COLLECT_VOUCHER_SUCCESS": "Collect voucher success!",
2
+ "COLLECT_VOUCHER_SUCCESS": "Voucher collection successful!",
3
3
  "LOGIN_BUTTON": "Login Button",
4
4
  "SEARCH_ICON": "Search Icon",
5
5
  "NAVIGATION": "Navigation",
@@ -1,5 +1,5 @@
1
1
  {
2
- "COLLECT_VOUCHER_SUCCESS": "Collect voucher success!",
2
+ "COLLECT_VOUCHER_SUCCESS": "Voucher collection successful!",
3
3
  "LOGIN_BUTTON": "Login Button",
4
4
  "SEARCH_ICON": "Search Icon",
5
5
  "NAVIGATION": "Navigation",
@@ -523,9 +523,11 @@ var JsonToUrl = function JsonToUrl(data) {
523
523
  exports.JsonToUrl = JsonToUrl;
524
524
 
525
525
  var jumpUrlConfig = function jumpUrlConfig(item) {
526
- var _a = item || {},
527
- objType = _a.objType,
528
- objValue = _a.objValue;
526
+ var _a, _b, _c;
527
+
528
+ var _d = item || {},
529
+ objType = _d.objType,
530
+ objValue = _d.objValue;
529
531
 
530
532
  var jumpUrl = '';
531
533
 
@@ -558,6 +560,14 @@ var jumpUrlConfig = function jumpUrlConfig(item) {
558
560
  break;
559
561
  }
560
562
 
563
+ case 'ProductDetailPage':
564
+ {
565
+ var offerId = objValue.objId && objValue.objId.split(',')[0];
566
+ var productId = objValue.objId && objValue.objId.split(',')[1];
567
+ jumpUrl = "/product/detail/" + offerId + "?productId=" + productId;
568
+ break;
569
+ }
570
+
561
571
  case 'FilteredProducts':
562
572
  {
563
573
  var params = JsonToUrl(objValue.filteredProductsRela);
@@ -579,10 +589,10 @@ var jumpUrlConfig = function jumpUrlConfig(item) {
579
589
 
580
590
  case 'URL':
581
591
  {
582
- if (objValue.urlRelaDto.openMode === 'new') {
592
+ if (((_a = objValue.urlRelaDto) === null || _a === void 0 ? void 0 : _a.openMode) === 'new') {
583
593
  window.open(objValue.urlRelaDto.url);
584
594
  } else {
585
- window.location.href = objValue.urlRelaDto.url;
595
+ window.location.href = (_c = (_b = objValue === null || objValue === void 0 ? void 0 : objValue.urlRelaDto) === null || _b === void 0 ? void 0 : _b.url) !== null && _c !== void 0 ? _c : objValue.url;
586
596
  }
587
597
 
588
598
  return;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.message = void 0;
7
+ exports.toast = toast;
8
+
9
+ var _mobx = require("../mobx");
10
+
11
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
12
+
13
+ function toast(config) {
14
+ var defaults = {
15
+ message: 'success',
16
+ duration: 3000,
17
+ onClose: function onClose() {},
18
+ visible: true
19
+ };
20
+
21
+ var _a = _extends(defaults, config),
22
+ message = _a.message,
23
+ duration = _a.duration,
24
+ onClose = _a.onClose,
25
+ visible = _a.visible;
26
+
27
+ _mobx.frameStore.setState({
28
+ toastState: {
29
+ message: message,
30
+ duration: duration,
31
+ onClose: onClose,
32
+ visible: visible
33
+ }
34
+ });
35
+ }
36
+
37
+ var message = {
38
+ toast: toast
39
+ };
40
+ exports.message = message;
@@ -278,17 +278,34 @@ var LAYOUT_IMAGE_SIZE = {
278
278
  */
279
279
 
280
280
  var insertArrayRandomly = function insertArrayRandomly(arr1, arr2) {
281
- // 创建一个复制的第一个数组,以免修改原数组
281
+ if (arr1.length < 1) {
282
+ return [];
283
+ }
284
+
285
+ if (arr1.length < 2) {
286
+ return __spreadArrays(arr1, arr2);
287
+ }
288
+
289
+ if (arr1.length === 2) {
290
+ return __spreadArrays([arr1[0]], arr2, [arr1[1]]);
291
+ }
292
+
293
+ if (arr1.length === 3) {
294
+ return __spreadArrays([arr1[0]], arr2, arr1.splice(1));
295
+ } // 创建一个复制的第一个数组,以免修改原数组
296
+
297
+
282
298
  var result = __spreadArrays(arr1); // 记录已插入元素的位置
283
299
 
284
300
 
285
301
  var insertedIndices = [];
286
302
 
287
303
  var _loop_1 = function _loop_1(i) {
288
- var randomIndex; // 确保生成的随机索引与已插入的索引相隔至少两个位置
304
+ var randomIndex; // 确保生成的随机索引不在首尾,并且与已插入的索引相隔至少两个位置
289
305
 
290
306
  do {
291
- randomIndex = Math.floor(Math.random() * (result.length + 1)); // eslint-disable-next-line no-loop-func
307
+ randomIndex = Math.floor(Math.random() * (result.length - 2)) + 1; // 1 到 result.length - 2
308
+ // eslint-disable-next-line no-loop-func
292
309
  } while (insertedIndices.some(function (index) {
293
310
  return Math.abs(index - randomIndex) < 2;
294
311
  })); // 在随机位置插入第二个数组的元素
@@ -308,10 +325,12 @@ var insertArrayRandomly = function insertArrayRandomly(arr1, arr2) {
308
325
  return result;
309
326
  };
310
327
 
311
- var getRandomItemsAndRemove = function getRandomItemsAndRemove(arr, count) {
328
+ var getRandomItemsAndRemove = function getRandomItemsAndRemove(arr, list) {
329
+ var _count = Math.ceil(list.length / 5);
330
+
312
331
  var result = []; // eslint-disable-next-line no-plusplus
313
332
 
314
- for (var i = 0; i < count && arr.length > 0; i++) {
333
+ for (var i = 0; i < _count && arr.length > 0; i++) {
315
334
  var randomIndex = Math.floor(Math.random() * arr.length);
316
335
  result.push(arr.splice(randomIndex, 1)[0]);
317
336
  }
@@ -379,7 +398,7 @@ function (_super) {
379
398
 
380
399
  _this.getAdvertise = function () {
381
400
  return __awaiter(_this, void 0, void 0, function () {
382
- var res;
401
+ var ad;
383
402
  return __generator(this, function (_a) {
384
403
  switch (_a.label) {
385
404
  case 0:
@@ -388,18 +407,16 @@ function (_super) {
388
407
  , (0, _commonUtil.commonFetch)('/designer/v1/h5/ad/today/valid/MagicDesignRecommendation/list', {}, 'GET')];
389
408
 
390
409
  case 1:
391
- res = _a.sent();
410
+ ad = _a.sent();
392
411
 
393
- if (res === null || res === void 0 ? void 0 : res.length) {
412
+ if (ad === null || ad === void 0 ? void 0 : ad.length) {
394
413
  return [2
395
414
  /*return*/
396
- , res.map(function (it) {
397
- var _a, _b, _c;
398
-
415
+ , ad[0].advertiseContents.map(function (it) {
399
416
  return {
400
417
  type: 'ad',
401
- url: (_b = (_a = it === null || it === void 0 ? void 0 : it.advertiseContents) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.url,
402
- adObj: (_c = it === null || it === void 0 ? void 0 : it.advertiseContents) === null || _c === void 0 ? void 0 : _c[0]
418
+ url: it === null || it === void 0 ? void 0 : it.url,
419
+ adObj: it
403
420
  };
404
421
  })];
405
422
  }
@@ -531,6 +548,9 @@ function (_super) {
531
548
  , 10];
532
549
 
533
550
  case 10:
551
+ if (!window.magicDesign.showRecommendAds) return [3
552
+ /*break*/
553
+ , 12];
534
554
  _h = this;
535
555
  return [4
536
556
  /*yield*/
@@ -538,9 +558,11 @@ function (_super) {
538
558
 
539
559
  case 11:
540
560
  _h.ads = _m.sent();
541
- insertAds = getRandomItemsAndRemove(this.ads, 2);
561
+ insertAds = getRandomItemsAndRemove(this.ads, newData);
542
562
  newData = insertArrayRandomly(newData, insertAds);
563
+ _m.label = 12;
543
564
 
565
+ case 12:
544
566
  if (!(0, _coreUtil.isDesignMode)()) {
545
567
  _cache = (0, _storeUtil.getMagicStore)("recommend_" + pageId + "_" + recommendId);
546
568
  (0, _storeUtil.setMagicStore)("recommend_" + pageId + "_" + recommendId, __assign(__assign({}, _cache), (_k = {}, _k["products" + index] = newData, _k.endTime = Date.now() + 3 * 60 * 1000, _k)));
@@ -45,7 +45,8 @@ var setDesignConfig = function setDesignConfig(props) {
45
45
  var config = props.config,
46
46
  device = props.device,
47
47
  isPreview = props.isPreview,
48
- projectCode = props.projectCode;
48
+ projectCode = props.projectCode,
49
+ showRecommendAds = props.showRecommendAds;
49
50
  window.magicDesign = __assign(__assign({
50
51
  pageBackground: '#f2f2f2',
51
52
  mode: 'renderer',
@@ -55,7 +56,8 @@ var setDesignConfig = function setDesignConfig(props) {
55
56
  }, config), {
56
57
  projectCode: projectCode,
57
58
  compSpacing: Number(config.compSpacing),
58
- compWidth: Number(config.compWidth)
59
+ compWidth: Number(config.compWidth),
60
+ showRecommendAds: showRecommendAds
59
61
  });
60
62
  };
61
63
  /**
@@ -1,5 +1,5 @@
1
1
  {
2
- "COLLECT_VOUCHER_SUCCESS": "Collect voucher success!",
2
+ "COLLECT_VOUCHER_SUCCESS": "Voucher collection successful!",
3
3
  "LOGIN_BUTTON": "Login Button",
4
4
  "SEARCH_ICON": "Search Icon",
5
5
  "NAVIGATION": "Navigation",
@@ -1,5 +1,5 @@
1
1
  {
2
- "COLLECT_VOUCHER_SUCCESS": "Collect voucher success!",
2
+ "COLLECT_VOUCHER_SUCCESS": "Voucher collection successful!",
3
3
  "LOGIN_BUTTON": "Login Button",
4
4
  "SEARCH_ICON": "Search Icon",
5
5
  "NAVIGATION": "Navigation",
@@ -1,5 +1,5 @@
1
1
  {
2
- "COLLECT_VOUCHER_SUCCESS": "Collect voucher success!",
2
+ "COLLECT_VOUCHER_SUCCESS": "Voucher collection successful!",
3
3
  "LOGIN_BUTTON": "Login Button",
4
4
  "SEARCH_ICON": "Search Icon",
5
5
  "NAVIGATION": "Navigation",
@@ -523,9 +523,11 @@ var JsonToUrl = function JsonToUrl(data) {
523
523
  exports.JsonToUrl = JsonToUrl;
524
524
 
525
525
  var jumpUrlConfig = function jumpUrlConfig(item) {
526
- var _a = item || {},
527
- objType = _a.objType,
528
- objValue = _a.objValue;
526
+ var _a, _b, _c;
527
+
528
+ var _d = item || {},
529
+ objType = _d.objType,
530
+ objValue = _d.objValue;
529
531
 
530
532
  var jumpUrl = '';
531
533
 
@@ -558,6 +560,14 @@ var jumpUrlConfig = function jumpUrlConfig(item) {
558
560
  break;
559
561
  }
560
562
 
563
+ case 'ProductDetailPage':
564
+ {
565
+ var offerId = objValue.objId && objValue.objId.split(',')[0];
566
+ var productId = objValue.objId && objValue.objId.split(',')[1];
567
+ jumpUrl = "/product/detail/" + offerId + "?productId=" + productId;
568
+ break;
569
+ }
570
+
561
571
  case 'FilteredProducts':
562
572
  {
563
573
  var params = JsonToUrl(objValue.filteredProductsRela);
@@ -579,10 +589,10 @@ var jumpUrlConfig = function jumpUrlConfig(item) {
579
589
 
580
590
  case 'URL':
581
591
  {
582
- if (objValue.urlRelaDto.openMode === 'new') {
592
+ if (((_a = objValue.urlRelaDto) === null || _a === void 0 ? void 0 : _a.openMode) === 'new') {
583
593
  window.open(objValue.urlRelaDto.url);
584
594
  } else {
585
- window.location.href = objValue.urlRelaDto.url;
595
+ window.location.href = (_c = (_b = objValue === null || objValue === void 0 ? void 0 : objValue.urlRelaDto) === null || _b === void 0 ? void 0 : _b.url) !== null && _c !== void 0 ? _c : objValue.url;
586
596
  }
587
597
 
588
598
  return;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.message = void 0;
7
+ exports.toast = toast;
8
+
9
+ var _mobx = require("../mobx");
10
+
11
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
12
+
13
+ function toast(config) {
14
+ var defaults = {
15
+ message: 'success',
16
+ duration: 3000,
17
+ onClose: function onClose() {},
18
+ visible: true
19
+ };
20
+
21
+ var _a = _extends(defaults, config),
22
+ message = _a.message,
23
+ duration = _a.duration,
24
+ onClose = _a.onClose,
25
+ visible = _a.visible;
26
+
27
+ _mobx.frameStore.setState({
28
+ toastState: {
29
+ message: message,
30
+ duration: duration,
31
+ onClose: onClose,
32
+ visible: visible
33
+ }
34
+ });
35
+ }
36
+
37
+ var message = {
38
+ toast: toast
39
+ };
40
+ exports.message = message;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fonixtree/magic-design",
3
3
  "author": "Cylon Team",
4
- "version": "1.0.164",
4
+ "version": "1.0.166",
5
5
  "description": "Magic Design",
6
6
  "license": "MIT",
7
7
  "module": "es/index.js",