@fonixtree/magic-design 1.0.162 → 1.0.164

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.
@@ -44,19 +44,17 @@ function ProductCardModal(_a) {
44
44
 
45
45
  var flag = true;
46
46
 
47
- var _data = data.slice(0, 2);
48
-
49
47
  var handleNext = function handleNext(e) {
50
48
  e.stopPropagation();
51
49
  setActive(function (prev) {
52
- return (prev + 1) % _data.length;
50
+ return (prev + 1) % data.length;
53
51
  });
54
52
  };
55
53
 
56
54
  var handlePrev = function handlePrev(e) {
57
55
  e.stopPropagation();
58
56
  setActive(function (prev) {
59
- return (prev - 1 + _data.length) % _data.length;
57
+ return (prev - 1 + data.length) % data.length;
60
58
  });
61
59
  };
62
60
 
@@ -64,9 +62,32 @@ function ProductCardModal(_a) {
64
62
  return index === active;
65
63
  };
66
64
 
65
+ var isShow = function isShow(index) {
66
+ if (data.length > 3) {
67
+ var oneShow = 0;
68
+ var twoShow = 0;
69
+
70
+ if (active === 0) {
71
+ oneShow = data.length - 1;
72
+ twoShow = active + 1;
73
+ } else if (active === data.length - 1) {
74
+ oneShow = active - 1;
75
+ twoShow = 0;
76
+ } else {
77
+ oneShow = active - 1;
78
+ twoShow = active + 1;
79
+ }
80
+
81
+ return index === oneShow || index === twoShow;
82
+ } else {
83
+ return true;
84
+ }
85
+ };
86
+
67
87
  var randomRotateY = function randomRotateY(index) {
68
88
  // return Math.floor(Math.random() * 21) - 10;
69
- return Math.floor((index % 2 === 0 ? -index : index) * 0.1 * 21) - 10;
89
+ // return Math.floor((index % 2 === 0 ? -index : index) * 0.1 * 21) - 10;
90
+ return index === 0 || index === 1 ? -10 : 10;
70
91
  };
71
92
 
72
93
  var handleScroll = function handleScroll(e) {
@@ -123,15 +144,15 @@ function ProductCardModal(_a) {
123
144
  onClick: function onClick(e) {
124
145
  return e.stopPropagation();
125
146
  }
126
- }, /*#__PURE__*/_react["default"].createElement(_framerMotion.AnimatePresence, null, _data.map(function (item, index) {
147
+ }, /*#__PURE__*/_react["default"].createElement(_framerMotion.AnimatePresence, null, data.map(function (item, index) {
127
148
  return /*#__PURE__*/_react["default"].createElement(_framerMotion.motion.div, {
128
149
  key: item.offerId,
129
150
  animate: {
130
- opacity: isActive(index) ? 1 : 0.7,
151
+ opacity: isActive(index) ? 1 : isShow(index) ? 0.7 : 0,
131
152
  scale: isActive(index) ? 1 : 0.95,
132
153
  z: isActive(index) ? 0 : -100,
133
154
  rotate: isActive(index) ? 0 : randomRotateY(index),
134
- zIndex: isActive(index) ? 999 : _data.length + 2 - index,
155
+ zIndex: isActive(index) ? 999 : data.length + 2 - index,
135
156
  y: isActive(index) ? [0, -80, 0] : 0
136
157
  },
137
158
  className: "card",
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = Toast;
9
+
10
+ var _react = _interopRequireWildcard(require("react"));
11
+
12
+ require("./index.less");
13
+
14
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
+
16
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
+
18
+ function Toast(_a) {
19
+ var message = _a.message,
20
+ onClose = _a.onClose,
21
+ duration = _a.duration;
22
+ (0, _react.useEffect)(function () {
23
+ setTimeout(function () {
24
+ onClose();
25
+ }, duration);
26
+ }, []);
27
+ return /*#__PURE__*/_react["default"].createElement("div", {
28
+ className: "toastWrap"
29
+ }, /*#__PURE__*/_react["default"].createElement("span", null, message));
30
+ }
@@ -0,0 +1,29 @@
1
+ .toastWrap {
2
+ position: fixed;
3
+ display: flex;
4
+ top: 40%;
5
+ left: 20px;
6
+ right: 20px;
7
+ z-index: 99999;
8
+ transform: translateZ(1000px);
9
+ background-color: #e5f6ea;
10
+ min-height: 32px;
11
+ align-items: center;
12
+ margin-bottom: 15px;
13
+ background: rgba(0, 0, 0, 0.8);
14
+ border-radius: 16px;
15
+ animation: fadeIn .2s linear;
16
+
17
+ span {
18
+ text-overflow: ellipsis;
19
+ color: #fff;
20
+ font-weight: 500;
21
+ font-size: 14px;
22
+ text-align: center;
23
+ color: #FFFFFF;
24
+ line-height: 24px;
25
+ padding: 15px;
26
+ letter-spacing: .5px;
27
+ width: 100%;
28
+ }
29
+ }
@@ -147,6 +147,12 @@ Object.defineProperty(exports, "SystemNotification", {
147
147
  return _SystemNotification["default"];
148
148
  }
149
149
  });
150
+ Object.defineProperty(exports, "Toast", {
151
+ enumerable: true,
152
+ get: function get() {
153
+ return _Toast["default"];
154
+ }
155
+ });
150
156
  Object.defineProperty(exports, "UrlPicker", {
151
157
  enumerable: true,
152
158
  get: function get() {
@@ -228,4 +234,6 @@ var _ErrorBoundary = _interopRequireDefault(require("./ErrorBoundary"));
228
234
 
229
235
  var _ProductCardModal = _interopRequireDefault(require("./ProductCardModal"));
230
236
 
237
+ var _Toast = _interopRequireDefault(require("./Toast"));
238
+
231
239
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -144,13 +144,7 @@ function (_super) {
144
144
  var salePercent = Number(data.salePercent) / 100 || 0;
145
145
  var imgStyle = {};
146
146
  if (imgWidth) imgStyle.width = imgWidth;
147
- if (imgHeight) imgStyle.height = imgHeight; // data.labels = [
148
- // {
149
- // position: 1,
150
- // imgUrl: '/get/resource/platform/20241129/picture/Group1162591862390719062056960.png',
151
- // },
152
- // ];
153
-
147
+ if (imgHeight) imgStyle.height = imgHeight;
154
148
  var imgLabels = ((_a = data.labels) === null || _a === void 0 ? void 0 : _a.filter(function (f) {
155
149
  return f.position !== '6' && f.position !== '7';
156
150
  })) || [];
@@ -159,7 +153,20 @@ function (_super) {
159
153
  })) || [];
160
154
  var priceLabels = ((_c = data.labels) === null || _c === void 0 ? void 0 : _c.filter(function (f) {
161
155
  return f.position === '7';
162
- })) || [];
156
+ })) || []; // ad 卡片
157
+
158
+ if (data.type === 'ad') {
159
+ return /*#__PURE__*/_react["default"].createElement("div", {
160
+ className: "m-product-item-advertise"
161
+ }, data.url && /*#__PURE__*/_react["default"].createElement("img", {
162
+ alt: "welcome advertise",
163
+ onClick: function onClick() {
164
+ (0, _commonUtil.jumpUrlConfig)(data.adObj);
165
+ },
166
+ src: data.url
167
+ }));
168
+ }
169
+
163
170
  return /*#__PURE__*/_react["default"].createElement("div", _extends({
164
171
  className: (0, _classnames["default"])('m-product-item-wrap', {
165
172
  fixHeight: fixHeight,
@@ -1,3 +1,10 @@
1
+ .m-product-item-advertise {
2
+ img {
3
+ width: 100%;
4
+ border-radius: 8px;
5
+ }
6
+ }
7
+
1
8
  .m-product-item-wrap {
2
9
  display: flex;
3
10
  flex-direction: column;
@@ -270,6 +270,54 @@ var LAYOUT_IMAGE_SIZE = {
270
270
  h: 110
271
271
  }
272
272
  };
273
+ /**
274
+ * 将第二个数组随机插入到第一个数组中
275
+ * @param {Array} array1 - 第一个数组
276
+ * @param {Array} array2 - 第二个数组
277
+ * @returns {Array} - 返回合并后的新数组
278
+ */
279
+
280
+ var insertArrayRandomly = function insertArrayRandomly(arr1, arr2) {
281
+ // 创建一个复制的第一个数组,以免修改原数组
282
+ var result = __spreadArrays(arr1); // 记录已插入元素的位置
283
+
284
+
285
+ var insertedIndices = [];
286
+
287
+ var _loop_1 = function _loop_1(i) {
288
+ var randomIndex; // 确保生成的随机索引与已插入的索引相隔至少两个位置
289
+
290
+ do {
291
+ randomIndex = Math.floor(Math.random() * (result.length + 1)); // eslint-disable-next-line no-loop-func
292
+ } while (insertedIndices.some(function (index) {
293
+ return Math.abs(index - randomIndex) < 2;
294
+ })); // 在随机位置插入第二个数组的元素
295
+
296
+
297
+ result.splice(randomIndex, 0, arr2[i]); // 记录已插入的位置
298
+
299
+ insertedIndices.push(randomIndex);
300
+ }; // 随机插入第二个数组的元素
301
+ // eslint-disable-next-line no-plusplus
302
+
303
+
304
+ for (var i = 0; i < arr2.length; i++) {
305
+ _loop_1(i);
306
+ }
307
+
308
+ return result;
309
+ };
310
+
311
+ var getRandomItemsAndRemove = function getRandomItemsAndRemove(arr, count) {
312
+ var result = []; // eslint-disable-next-line no-plusplus
313
+
314
+ for (var i = 0; i < count && arr.length > 0; i++) {
315
+ var randomIndex = Math.floor(Math.random() * arr.length);
316
+ result.push(arr.splice(randomIndex, 1)[0]);
317
+ }
318
+
319
+ return result;
320
+ };
273
321
 
274
322
  var RecommendMobile =
275
323
  /** @class */
@@ -279,6 +327,7 @@ function (_super) {
279
327
  function RecommendMobile() {
280
328
  var _this = _super !== null && _super.apply(this, arguments) || this;
281
329
 
330
+ _this.ads = [];
282
331
  _this.preData = {};
283
332
  _this.preLayout = '';
284
333
  _this.preContent = '';
@@ -328,16 +377,51 @@ function (_super) {
328
377
  }, '#CE1126') : '#CE1126';
329
378
  };
330
379
 
380
+ _this.getAdvertise = function () {
381
+ return __awaiter(_this, void 0, void 0, function () {
382
+ var res;
383
+ return __generator(this, function (_a) {
384
+ switch (_a.label) {
385
+ case 0:
386
+ return [4
387
+ /*yield*/
388
+ , (0, _commonUtil.commonFetch)('/designer/v1/h5/ad/today/valid/MagicDesignRecommendation/list', {}, 'GET')];
389
+
390
+ case 1:
391
+ res = _a.sent();
392
+
393
+ if (res === null || res === void 0 ? void 0 : res.length) {
394
+ return [2
395
+ /*return*/
396
+ , res.map(function (it) {
397
+ var _a, _b, _c;
398
+
399
+ return {
400
+ 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]
403
+ };
404
+ })];
405
+ }
406
+
407
+ return [2
408
+ /*return*/
409
+ , []];
410
+ }
411
+ });
412
+ });
413
+ };
414
+
331
415
  _this.getProductList = function (index) {
332
416
  return __awaiter(_this, void 0, void 0, function () {
333
- var panelProps, groupSource, recommendId, pageId, cache, _a, _b, sourceType, _c, prodIds, _d, prodType, _e, intelligentType, _f, intelligentValue, _g, maxProdNum, newData, params, res, res, e_1, _cache;
417
+ var panelProps, groupSource, recommendId, pageId, cache, _a, _b, sourceType, _c, prodIds, _d, prodType, _e, intelligentType, _f, intelligentValue, _g, maxProdNum, newData, params, res, res, e_1, _h, insertAds, _cache;
334
418
 
335
- var _h, _j, _k;
419
+ var _j, _k, _l;
336
420
 
337
421
  var _this = this;
338
422
 
339
- return __generator(this, function (_l) {
340
- switch (_l.label) {
423
+ return __generator(this, function (_m) {
424
+ switch (_m.label) {
341
425
  case 0:
342
426
  panelProps = this.props.panelProps;
343
427
  groupSource = this.state.groupSource;
@@ -349,7 +433,7 @@ function (_super) {
349
433
 
350
434
  if (cache) {
351
435
  if ("products" + index in cache) {
352
- this.setState((_h = {}, _h["products" + index] = cache["products" + index], _h), function () {
436
+ this.setState((_j = {}, _j["products" + index] = cache["products" + index], _j), function () {
353
437
  _this.resetLayout();
354
438
  });
355
439
  /** 如果数据未过期 */
@@ -363,10 +447,10 @@ function (_super) {
363
447
 
364
448
  _a = groupSource[index] || {}, _b = _a.sourceType, sourceType = _b === void 0 ? '' : _b, _c = _a.prodIds, prodIds = _c === void 0 ? '' : _c, _d = _a.prodType, prodType = _d === void 0 ? '' : _d, _e = _a.intelligentType, intelligentType = _e === void 0 ? '' : _e, _f = _a.intelligentValue, intelligentValue = _f === void 0 ? [] : _f, _g = _a.maxProdNum, maxProdNum = _g === void 0 ? 10 : _g;
365
449
  newData = [];
366
- _l.label = 1;
450
+ _m.label = 1;
367
451
 
368
452
  case 1:
369
- _l.trys.push([1, 9,, 10]);
453
+ _m.trys.push([1, 9,, 10]);
370
454
 
371
455
  if (!(groupSource.length > 0)) return [3
372
456
  /*break*/
@@ -392,7 +476,7 @@ function (_super) {
392
476
  , (0, _commonUtil.commonFetch)('/designer/v1/h5/products', params, 'GET')];
393
477
 
394
478
  case 2:
395
- res = _l.sent();
479
+ res = _m.sent();
396
480
  newData = __spreadArrays(res.list);
397
481
  return [3
398
482
  /*break*/
@@ -415,7 +499,7 @@ function (_super) {
415
499
  }, 'POST')];
416
500
 
417
501
  case 4:
418
- res = _l.sent();
502
+ res = _m.sent();
419
503
  newData = __spreadArrays(res.pageInfo.list);
420
504
  return [3
421
505
  /*break*/
@@ -423,7 +507,7 @@ function (_super) {
423
507
 
424
508
  case 5:
425
509
  newData = [];
426
- _l.label = 6;
510
+ _m.label = 6;
427
511
 
428
512
  case 6:
429
513
  return [3
@@ -432,7 +516,7 @@ function (_super) {
432
516
 
433
517
  case 7:
434
518
  newData = [];
435
- _l.label = 8;
519
+ _m.label = 8;
436
520
 
437
521
  case 8:
438
522
  return [3
@@ -440,19 +524,29 @@ function (_super) {
440
524
  , 10];
441
525
 
442
526
  case 9:
443
- e_1 = _l.sent();
527
+ e_1 = _m.sent();
444
528
  newData = [];
445
529
  return [3
446
530
  /*break*/
447
531
  , 10];
448
532
 
449
533
  case 10:
534
+ _h = this;
535
+ return [4
536
+ /*yield*/
537
+ , this.getAdvertise()];
538
+
539
+ case 11:
540
+ _h.ads = _m.sent();
541
+ insertAds = getRandomItemsAndRemove(this.ads, 2);
542
+ newData = insertArrayRandomly(newData, insertAds);
543
+
450
544
  if (!(0, _coreUtil.isDesignMode)()) {
451
545
  _cache = (0, _storeUtil.getMagicStore)("recommend_" + pageId + "_" + recommendId);
452
- (0, _storeUtil.setMagicStore)("recommend_" + pageId + "_" + recommendId, __assign(__assign({}, _cache), (_j = {}, _j["products" + index] = newData, _j.endTime = Date.now() + 3 * 60 * 1000, _j)));
546
+ (0, _storeUtil.setMagicStore)("recommend_" + pageId + "_" + recommendId, __assign(__assign({}, _cache), (_k = {}, _k["products" + index] = newData, _k.endTime = Date.now() + 3 * 60 * 1000, _k)));
453
547
  }
454
548
 
455
- this.setState((_k = {}, _k["products" + index] = newData, _k), function () {
549
+ this.setState((_l = {}, _l["products" + index] = newData, _l), function () {
456
550
  _this.resetLayout();
457
551
  });
458
552
  return [2
@@ -81,6 +81,10 @@ var Renderer = function Renderer(props) {
81
81
  pcProdCardModalState = _c[0],
82
82
  setPcProdCardModalState = _c[1];
83
83
 
84
+ var _d = (0, _react.useState)(_mobx.frameStore.toastState),
85
+ toastState = _d[0],
86
+ setToastState = _d[1];
87
+
84
88
  if (!noSetWindow) {
85
89
  setDesignConfig(props);
86
90
  }
@@ -137,6 +141,7 @@ var Renderer = function Renderer(props) {
137
141
  var disposer = (0, _mobx.autorun)(function () {
138
142
  setModalState(_mobx.frameStore.modalState);
139
143
  setPcProdCardModalState(_mobx.frameStore.pcProdCardModalState);
144
+ setToastState(_mobx.frameStore.toastState);
140
145
  });
141
146
  return function () {
142
147
  disposer();
@@ -164,6 +169,14 @@ var Renderer = function Renderer(props) {
164
169
  });
165
170
  };
166
171
 
172
+ var onCloseToast = function onCloseToast() {
173
+ _mobx.frameStore.setState({
174
+ toastState: {
175
+ visible: false
176
+ }
177
+ });
178
+ };
179
+
167
180
  var getRestStyle = function getRestStyle() {
168
181
  if (modalState.visible) {
169
182
  return {
@@ -211,6 +224,8 @@ var Renderer = function Renderer(props) {
211
224
  onClose: onCloseModal
212
225
  })), pcProdCardModalState.visible && /*#__PURE__*/_react["default"].createElement(_common.ProductCardModal, _extends({}, pcProdCardModalState, {
213
226
  onClose: onCloseProdCardModal
227
+ })), toastState.visible && /*#__PURE__*/_react["default"].createElement(_common.Toast, _extends({}, toastState, {
228
+ onClose: onCloseToast
214
229
  })));
215
230
  };
216
231
 
@@ -1,4 +1,5 @@
1
1
  {
2
+ "COLLECT_VOUCHER_SUCCESS": "Collect voucher success!",
2
3
  "LOGIN_BUTTON": "Login Button",
3
4
  "SEARCH_ICON": "Search Icon",
4
5
  "NAVIGATION": "Navigation",
@@ -1,4 +1,5 @@
1
1
  {
2
+ "COLLECT_VOUCHER_SUCCESS": "Collect voucher success!",
2
3
  "LOGIN_BUTTON": "Login Button",
3
4
  "SEARCH_ICON": "Search Icon",
4
5
  "NAVIGATION": "Navigation",
@@ -1,4 +1,5 @@
1
1
  {
2
+ "COLLECT_VOUCHER_SUCCESS": "Collect voucher success!",
2
3
  "LOGIN_BUTTON": "Login Button",
3
4
  "SEARCH_ICON": "Search Icon",
4
5
  "NAVIGATION": "Navigation",
package/es/mobx/Frame.js CHANGED
@@ -64,11 +64,17 @@ function () {
64
64
  visible: false,
65
65
  data: []
66
66
  };
67
+ this.toastState = {
68
+ visible: false,
69
+ message: '',
70
+ onClose: function onClose() {}
71
+ };
67
72
  (0, _mobx.makeObservable)(this, {
68
73
  confirmState: _mobx.observable,
69
74
  textModalState: _mobx.observable,
70
75
  modalState: _mobx.observable,
71
- pcProdCardModalState: _mobx.observable
76
+ pcProdCardModalState: _mobx.observable,
77
+ toastState: _mobx.observable
72
78
  });
73
79
  }
74
80
  /** 修改状态 */