@fonixtree/magic-design 1.0.205 → 1.0.207

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.
@@ -128,6 +128,7 @@ function (_super) {
128
128
  return /*#__PURE__*/_react["default"].createElement("img", _extends({
129
129
  ref: this.imageRef,
130
130
  alt: "",
131
+ draggable: "false",
131
132
  className: (0, _classnames["default"])('new-img-container', className),
132
133
  src: isShow ? src : '',
133
134
  style: __assign({
@@ -83,7 +83,11 @@ function (_super) {
83
83
 
84
84
  _this.state = {
85
85
  carouseIndex: 0,
86
- hoverState: false
86
+ hoverState: false,
87
+ isDragging: false,
88
+ startX: 0,
89
+ startY: 0,
90
+ hasDragged: false
87
91
  };
88
92
  _this.carouselRef = /*#__PURE__*/_react["default"].createRef();
89
93
  _this.destroy = null;
@@ -136,6 +140,161 @@ function (_super) {
136
140
  if ((_b = data.setting.navigation) === null || _b === void 0 ? void 0 : _b.size) {
137
141
  e.target.style.fontSize = data.setting.navigation.size;
138
142
  }
143
+ }; // 鼠标拖拽相关方法
144
+
145
+
146
+ _this.handleMouseDown = function (e) {
147
+ var _a; // 设计器模式下禁用拖拽
148
+
149
+
150
+ if ((0, _coreUtil.isDesignMode)() && ((_a = window.magicDesign) === null || _a === void 0 ? void 0 : _a.mode) !== 'renderer') {
151
+ return;
152
+ }
153
+
154
+ _this.setState({
155
+ isDragging: true,
156
+ startX: e.clientX,
157
+ startY: e.clientY
158
+ });
159
+ };
160
+
161
+ _this.handleMouseMove = function (e) {
162
+ if (!_this.state.isDragging) return; // 防止默认行为,避免选中文本
163
+
164
+ e.preventDefault(); // 如果移动距离超过阈值,标记为已拖拽
165
+
166
+ var _a = _this.state,
167
+ startX = _a.startX,
168
+ startY = _a.startY;
169
+ var deltaX = Math.abs(e.clientX - startX);
170
+ var deltaY = Math.abs(e.clientY - startY);
171
+
172
+ if (deltaX > 5 || deltaY > 5) {
173
+ _this.setState({
174
+ hasDragged: true
175
+ });
176
+ }
177
+ };
178
+
179
+ _this.handleMouseUp = function (e) {
180
+ _this.processMouseUp(e.clientX, e.clientY);
181
+ };
182
+
183
+ _this.handleGlobalMouseMove = function (e) {
184
+ if (!_this.state.isDragging) return; // 防止默认行为,避免选中文本
185
+
186
+ e.preventDefault(); // 如果移动距离超过阈值,标记为已拖拽
187
+
188
+ var _a = _this.state,
189
+ startX = _a.startX,
190
+ startY = _a.startY;
191
+ var deltaX = Math.abs(e.clientX - startX);
192
+ var deltaY = Math.abs(e.clientY - startY);
193
+
194
+ if (deltaX > 5 || deltaY > 5) {
195
+ _this.setState({
196
+ hasDragged: true
197
+ });
198
+ }
199
+ };
200
+
201
+ _this.handleGlobalMouseUp = function (e) {
202
+ if (!_this.state.isDragging) return;
203
+
204
+ _this.processMouseUp(e.clientX, e.clientY);
205
+ };
206
+
207
+ _this.processMouseUp = function (endX, endY) {
208
+ var _a, _b;
209
+
210
+ if (!_this.state.isDragging) return;
211
+ var _c = _this.state,
212
+ startX = _c.startX,
213
+ startY = _c.startY,
214
+ hasDragged = _c.hasDragged;
215
+ var deltaX = startX - endX;
216
+ var deltaY = startY - endY; // 判断是否为水平滑动(水平距离大于垂直距离,且水平距离超过阈值)
217
+
218
+ var minSwipeDistance = 50; // 最小滑动距离阈值
219
+
220
+ if (Math.abs(deltaX) > Math.abs(deltaY) && Math.abs(deltaX) > minSwipeDistance) {
221
+ if (deltaX > 0) {
222
+ // 向左滑动,切换到下一页
223
+ (_a = _this.carouselRef.current) === null || _a === void 0 ? void 0 : _a.next();
224
+ } else {
225
+ // 向右滑动,切换到上一页
226
+ (_b = _this.carouselRef.current) === null || _b === void 0 ? void 0 : _b.prev();
227
+ }
228
+ } // 如果发生了拖拽,延迟重置以便阻止点击事件
229
+ // 如果没有拖拽,立即重置,允许点击事件正常触发
230
+
231
+
232
+ if (hasDragged) {
233
+ setTimeout(function () {
234
+ _this.setState({
235
+ isDragging: false,
236
+ startX: 0,
237
+ startY: 0,
238
+ hasDragged: false
239
+ });
240
+ }, 100);
241
+ } else {
242
+ // 没有拖拽,立即重置,允许点击
243
+ _this.setState({
244
+ isDragging: false,
245
+ startX: 0,
246
+ startY: 0,
247
+ hasDragged: false
248
+ });
249
+ }
250
+ };
251
+
252
+ _this.handleMouseLeave = function () {
253
+ // 鼠标离开时重置拖拽状态
254
+ if (_this.state.isDragging) {
255
+ var hasDragged = _this.state.hasDragged;
256
+
257
+ if (hasDragged) {
258
+ setTimeout(function () {
259
+ _this.setState({
260
+ isDragging: false,
261
+ startX: 0,
262
+ startY: 0,
263
+ hasDragged: false
264
+ });
265
+ }, 100);
266
+ } else {
267
+ // 没有拖拽,立即重置
268
+ _this.setState({
269
+ isDragging: false,
270
+ startX: 0,
271
+ startY: 0,
272
+ hasDragged: false
273
+ });
274
+ }
275
+ }
276
+ }; // 阻止拖拽后的点击事件 - 使用捕获阶段
277
+
278
+
279
+ _this.handleClickCapture = function (e) {
280
+ // 只有在真正发生拖拽时才阻止点击
281
+ if (_this.state.hasDragged) {
282
+ e.preventDefault();
283
+ e.stopPropagation(); // 阻止所有子元素的点击事件
284
+
285
+ e.nativeEvent.stopImmediatePropagation();
286
+ }
287
+ }; // 阻止拖拽后的点击事件
288
+
289
+
290
+ _this.handleClick = function (e) {
291
+ // 只有在真正发生拖拽时才阻止点击
292
+ if (_this.state.hasDragged) {
293
+ e.preventDefault();
294
+ e.stopPropagation(); // 阻止所有子元素的点击事件
295
+
296
+ e.nativeEvent.stopImmediatePropagation();
297
+ }
139
298
  }; // padding用统一设置
140
299
 
141
300
 
@@ -195,9 +354,16 @@ function (_super) {
195
354
  BannerPc.prototype.componentDidMount = function () {
196
355
  var _this = this;
197
356
 
357
+ var _a;
358
+
198
359
  this.destroy = (0, _mobx.autorun)(function () {
199
360
  _this.bannerGoto(_this.props.data.groupSource);
200
- });
361
+ }); // 添加全局鼠标事件监听,处理鼠标移出元素的情况
362
+
363
+ if (!(0, _coreUtil.isDesignMode)() || ((_a = window.magicDesign) === null || _a === void 0 ? void 0 : _a.mode) === 'renderer') {
364
+ document.addEventListener('mousemove', this.handleGlobalMouseMove);
365
+ document.addEventListener('mouseup', this.handleGlobalMouseUp);
366
+ }
201
367
  };
202
368
 
203
369
  BannerPc.prototype.componentWillReceiveProps = function (nextProps) {
@@ -205,7 +371,10 @@ function (_super) {
205
371
  };
206
372
 
207
373
  BannerPc.prototype.componentWillUnmount = function () {
208
- this.destroy();
374
+ this.destroy(); // 移除全局鼠标事件监听
375
+
376
+ document.removeEventListener('mousemove', this.handleGlobalMouseMove);
377
+ document.removeEventListener('mouseup', this.handleGlobalMouseUp);
209
378
  };
210
379
 
211
380
  BannerPc.prototype.render = function () {
@@ -250,17 +419,31 @@ function (_super) {
250
419
  autoplaySpeed: data.setting.autoplay.interval * 1000,
251
420
  dots: false
252
421
  }, data.groupSource.map(function (item, index) {
253
- var _a, _b;
422
+ var _a, _b, _c;
254
423
 
255
424
  return /*#__PURE__*/_react["default"].createElement("div", {
256
425
  key: item.id
257
426
  }, /*#__PURE__*/_react["default"].createElement("div", {
258
427
  style: _this.getBackgroundStyle(item)
259
428
  }, /*#__PURE__*/_react["default"].createElement("div", {
260
- className: "carouselItem",
429
+ className: (0, _classnames["default"])('carouselItem', {
430
+ dragging: _this.state.isDragging,
431
+ 'no-click': _this.state.hasDragged
432
+ }),
261
433
  onMouseEnter: _this.mouseEnterWrap,
262
- onMouseLeave: _this.mouseLeaveWrap,
263
- style: _this.getItemStyle(item)
434
+ onMouseLeave: function onMouseLeave(e) {
435
+ _this.mouseLeaveWrap();
436
+
437
+ _this.handleMouseLeave();
438
+ },
439
+ onMouseDown: _this.handleMouseDown,
440
+ onMouseMove: _this.handleMouseMove,
441
+ onMouseUp: _this.handleMouseUp,
442
+ onClick: _this.handleClick,
443
+ onClickCapture: _this.handleClickCapture,
444
+ style: __assign(__assign({}, _this.getItemStyle(item)), {
445
+ cursor: _this.state.isDragging ? 'grabbing' : !(0, _coreUtil.isDesignMode)() || ((_a = window.magicDesign) === null || _a === void 0 ? void 0 : _a.mode) === 'renderer' ? 'grab' : 'default'
446
+ })
264
447
  }, /*#__PURE__*/_react["default"].createElement(_components.MetaImage, {
265
448
  data: item.image,
266
449
  GAData: __assign(__assign({}, GAData), {
@@ -296,7 +479,7 @@ function (_super) {
296
479
  className: "btn-wrap",
297
480
  style: {
298
481
  justifyContent: _AlignSelector.alignItemMap[item.customize.align],
299
- width: Math.max((_a = item.title.content) === null || _a === void 0 ? void 0 : _a.pcWidth, (_b = item.text.content) === null || _b === void 0 ? void 0 : _b.pcWidth) + "%"
482
+ width: Math.max((_b = item.title.content) === null || _b === void 0 ? void 0 : _b.pcWidth, (_c = item.text.content) === null || _c === void 0 ? void 0 : _c.pcWidth) + "%"
300
483
  }
301
484
  }, item.button.open && /*#__PURE__*/_react["default"].createElement(_components.MetaButton, {
302
485
  className: "btn",
@@ -41,17 +41,34 @@
41
41
  }
42
42
 
43
43
  .leftBtn {
44
- left: 20px;
44
+ left: 70px;
45
45
  }
46
46
 
47
47
  .rightBtn {
48
- right: 20px;
48
+ right: 70px;
49
49
  }
50
50
 
51
51
  .carouselItem {
52
52
  // height: 360px;
53
53
  display: flex;
54
54
  position: relative;
55
+ // 拖拽相关样式
56
+ -webkit-user-select: none;
57
+ -moz-user-select: none;
58
+ -ms-user-select: none;
59
+ user-select: none;
60
+ -webkit-touch-callout: none;
61
+
62
+ &.dragging {
63
+ cursor: grabbing !important;
64
+ }
65
+
66
+ // 拖拽时禁用子元素的点击事件
67
+ &.no-click {
68
+ * {
69
+ pointer-events: none !important;
70
+ }
71
+ }
55
72
 
56
73
  .carouseContent {
57
74
  padding: 0 80px;
@@ -7,6 +7,8 @@ exports["default"] = void 0;
7
7
 
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
 
10
+ var _classnames = _interopRequireDefault(require("classnames"));
11
+
10
12
  require("./index.less");
11
13
 
12
14
  var _lodash = _interopRequireDefault(require("lodash.throttle"));
@@ -307,7 +309,11 @@ function (_super) {
307
309
  now: '',
308
310
  isWill: false,
309
311
  scrollToLeftDisabled: true,
310
- scrollToRightDisabled: true
312
+ scrollToRightDisabled: true,
313
+ isDragging: false,
314
+ startX: 0,
315
+ startScrollLeft: 0,
316
+ hasDragged: false
311
317
  };
312
318
 
313
319
  _this.getFlashData = function (pageSize, campaign) {
@@ -424,6 +430,171 @@ function (_super) {
424
430
  if (scrollDom.scrollLeft > 0) {
425
431
  scrollDom.scrollTo(scrollDom.scrollLeft - scrollDom.clientWidth, 0);
426
432
  }
433
+ }; // 鼠标拖拽滚动相关方法
434
+
435
+
436
+ _this.handleMouseDown = function (e) {
437
+ var _a; // 设计器模式下禁用拖拽
438
+
439
+
440
+ if ((0, _coreUtil.isDesignMode)() && ((_a = window.magicDesign) === null || _a === void 0 ? void 0 : _a.mode) !== 'renderer') {
441
+ return;
442
+ }
443
+
444
+ var scrollDom = _this.scrollRef.current;
445
+ if (!scrollDom) return;
446
+
447
+ _this.setState({
448
+ isDragging: true,
449
+ startX: e.clientX,
450
+ startScrollLeft: scrollDom.scrollLeft
451
+ });
452
+ };
453
+
454
+ _this.handleMouseMove = function (e) {
455
+ if (!_this.state.isDragging) return;
456
+ e.preventDefault(); // 如果移动距离超过阈值,标记为已拖拽
457
+
458
+ var startX = _this.state.startX;
459
+ var deltaX = Math.abs(e.clientX - startX);
460
+
461
+ if (deltaX > 5) {
462
+ _this.setState({
463
+ hasDragged: true
464
+ });
465
+ }
466
+
467
+ _this.updateScrollPosition(e.clientX);
468
+ };
469
+
470
+ _this.handleGlobalMouseMove = function (e) {
471
+ if (!_this.state.isDragging) return;
472
+ e.preventDefault(); // 如果移动距离超过阈值,标记为已拖拽
473
+
474
+ var startX = _this.state.startX;
475
+ var deltaX = Math.abs(e.clientX - startX);
476
+
477
+ if (deltaX > 5) {
478
+ _this.setState({
479
+ hasDragged: true
480
+ });
481
+ }
482
+
483
+ _this.updateScrollPosition(e.clientX);
484
+ };
485
+
486
+ _this.handleGlobalMouseUp = function (e) {
487
+ if (!_this.state.isDragging) return;
488
+ var hasDragged = _this.state.hasDragged; // 如果发生了拖拽,延迟重置以便阻止点击事件
489
+ // 如果没有拖拽,立即重置,允许点击事件正常触发
490
+
491
+ if (hasDragged) {
492
+ setTimeout(function () {
493
+ _this.setState({
494
+ isDragging: false,
495
+ startX: 0,
496
+ startScrollLeft: 0,
497
+ hasDragged: false
498
+ });
499
+ }, 100);
500
+ } else {
501
+ // 没有拖拽,立即重置,允许点击
502
+ _this.setState({
503
+ isDragging: false,
504
+ startX: 0,
505
+ startScrollLeft: 0,
506
+ hasDragged: false
507
+ });
508
+ }
509
+ };
510
+
511
+ _this.handleMouseUp = function (e) {
512
+ if (!_this.state.isDragging) return;
513
+ var hasDragged = _this.state.hasDragged; // 如果发生了拖拽,延迟重置以便阻止点击事件
514
+ // 如果没有拖拽,立即重置,允许点击事件正常触发
515
+
516
+ if (hasDragged) {
517
+ setTimeout(function () {
518
+ _this.setState({
519
+ isDragging: false,
520
+ startX: 0,
521
+ startScrollLeft: 0,
522
+ hasDragged: false
523
+ });
524
+ }, 100);
525
+ } else {
526
+ // 没有拖拽,立即重置,允许点击
527
+ _this.setState({
528
+ isDragging: false,
529
+ startX: 0,
530
+ startScrollLeft: 0,
531
+ hasDragged: false
532
+ });
533
+ }
534
+ };
535
+
536
+ _this.handleMouseLeave = function () {
537
+ // 鼠标离开时重置拖拽状态
538
+ if (_this.state.isDragging) {
539
+ var hasDragged = _this.state.hasDragged;
540
+
541
+ if (hasDragged) {
542
+ setTimeout(function () {
543
+ _this.setState({
544
+ isDragging: false,
545
+ startX: 0,
546
+ startScrollLeft: 0,
547
+ hasDragged: false
548
+ });
549
+ }, 100);
550
+ } else {
551
+ // 没有拖拽,立即重置
552
+ _this.setState({
553
+ isDragging: false,
554
+ startX: 0,
555
+ startScrollLeft: 0,
556
+ hasDragged: false
557
+ });
558
+ }
559
+ }
560
+ }; // 阻止拖拽后的点击事件 - 使用捕获阶段
561
+
562
+
563
+ _this.handleClickCapture = function (e) {
564
+ // 只有在真正发生拖拽时才阻止点击
565
+ if (_this.state.hasDragged) {
566
+ e.preventDefault();
567
+ e.stopPropagation(); // 阻止所有子元素的点击事件
568
+
569
+ e.nativeEvent.stopImmediatePropagation();
570
+ }
571
+ }; // 阻止拖拽后的点击事件
572
+
573
+
574
+ _this.handleClick = function (e) {
575
+ // 只有在真正发生拖拽时才阻止点击
576
+ if (_this.state.hasDragged) {
577
+ e.preventDefault();
578
+ e.stopPropagation(); // 阻止所有子元素的点击事件
579
+
580
+ e.nativeEvent.stopImmediatePropagation();
581
+ }
582
+ };
583
+
584
+ _this.updateScrollPosition = function (currentX) {
585
+ var scrollDom = _this.scrollRef.current;
586
+ if (!scrollDom) return;
587
+ var _a = _this.state,
588
+ startX = _a.startX,
589
+ startScrollLeft = _a.startScrollLeft;
590
+ var deltaX = currentX - startX;
591
+ var newScrollLeft = startScrollLeft - deltaX; // 限制滚动范围
592
+
593
+ var maxScrollLeft = scrollDom.scrollWidth - scrollDom.clientWidth;
594
+ var clampedScrollLeft = Math.max(0, Math.min(newScrollLeft, maxScrollLeft));
595
+ scrollDom.scrollLeft = clampedScrollLeft;
596
+
597
+ _this.setScrollDisabled(scrollDom);
427
598
  };
428
599
 
429
600
  return _this;
@@ -432,6 +603,8 @@ function (_super) {
432
603
  FlashDealPc.prototype.componentDidMount = function () {
433
604
  var _this = this;
434
605
 
606
+ var _a;
607
+
435
608
  this.sortType = this.props.panelProps.content.sortType;
436
609
  this.getNextFlashSale();
437
610
  setTimeout(function () {
@@ -444,7 +617,12 @@ function (_super) {
444
617
  _this.setScrollDisabled(scrollDom);
445
618
  }, 500);
446
619
  }
447
- }, 0);
620
+ }, 0); // 添加全局鼠标事件监听,处理鼠标拖拽滚动
621
+
622
+ if (!(0, _coreUtil.isDesignMode)() || ((_a = window.magicDesign) === null || _a === void 0 ? void 0 : _a.mode) === 'renderer') {
623
+ document.addEventListener('mousemove', this.handleGlobalMouseMove);
624
+ document.addEventListener('mouseup', this.handleGlobalMouseUp);
625
+ }
448
626
  };
449
627
 
450
628
  FlashDealPc.prototype.componentWillReceiveProps = function (nextProps) {
@@ -471,20 +649,26 @@ function (_super) {
471
649
  }
472
650
  };
473
651
 
652
+ FlashDealPc.prototype.componentWillUnmount = function () {
653
+ // 移除全局鼠标事件监听
654
+ document.removeEventListener('mousemove', this.handleGlobalMouseMove);
655
+ document.removeEventListener('mouseup', this.handleGlobalMouseUp);
656
+ };
657
+
474
658
  FlashDealPc.prototype.render = function () {
475
659
  var _this = this;
476
660
 
477
- var _a, _b;
661
+ var _a, _b, _c;
478
662
 
479
663
  var panelProps = this.props.panelProps;
480
- var _c = this.state,
481
- list = _c.list,
482
- effDate = _c.effDate,
483
- expDate = _c.expDate,
484
- now = _c.now,
485
- isWill = _c.isWill,
486
- scrollToLeftDisabled = _c.scrollToLeftDisabled,
487
- scrollToRightDisabled = _c.scrollToRightDisabled;
664
+ var _d = this.state,
665
+ list = _d.list,
666
+ effDate = _d.effDate,
667
+ expDate = _d.expDate,
668
+ now = _d.now,
669
+ isWill = _d.isWill,
670
+ scrollToLeftDisabled = _d.scrollToLeftDisabled,
671
+ scrollToRightDisabled = _d.scrollToRightDisabled;
488
672
 
489
673
  var _list = list.length === 0 && (0, _coreUtil.isDesignMode)() ? defaultData : list;
490
674
 
@@ -526,7 +710,18 @@ function (_super) {
526
710
  type: "icon-outlined-left"
527
711
  })), /*#__PURE__*/_react["default"].createElement("div", {
528
712
  ref: this.scrollRef,
529
- className: "flash-deal-list"
713
+ className: (0, _classnames["default"])('flash-deal-list', {
714
+ 'no-click': this.state.hasDragged
715
+ }),
716
+ onMouseDown: this.handleMouseDown,
717
+ onMouseMove: this.handleMouseMove,
718
+ onMouseUp: this.handleMouseUp,
719
+ onMouseLeave: this.handleMouseLeave,
720
+ onClick: this.handleClick,
721
+ onClickCapture: this.handleClickCapture,
722
+ style: {
723
+ cursor: this.state.isDragging ? 'grabbing' : !(0, _coreUtil.isDesignMode)() || ((_c = window.magicDesign) === null || _c === void 0 ? void 0 : _c.mode) === 'renderer' ? 'grab' : 'default'
724
+ }
530
725
  }, _list.map(function (item) {
531
726
  return /*#__PURE__*/_react["default"].createElement(_ProductItem["default"], {
532
727
  key: item.id,
@@ -93,6 +93,30 @@
93
93
  position: relative;
94
94
  flex: 1;
95
95
  gap: 40px;
96
+ // 拖拽相关样式
97
+ -webkit-user-select: none;
98
+ -moz-user-select: none;
99
+ -ms-user-select: none;
100
+ user-select: none;
101
+ -webkit-touch-callout: none;
102
+ // 隐藏滚动条但保持滚动功能
103
+ scrollbar-width: none; /* Firefox */
104
+ -ms-overflow-style: none; /* IE and Edge */
105
+
106
+ &::-webkit-scrollbar {
107
+ display: none; /* Chrome, Safari, Opera */
108
+ }
109
+
110
+ &.dragging {
111
+ cursor: grabbing !important;
112
+ }
113
+
114
+ // 拖拽时禁用子元素的点击事件
115
+ &.no-click {
116
+ * {
117
+ pointer-events: none !important;
118
+ }
119
+ }
96
120
  }
97
121
  }
98
122
 
@@ -128,6 +128,7 @@ function (_super) {
128
128
  return /*#__PURE__*/_react["default"].createElement("img", _extends({
129
129
  ref: this.imageRef,
130
130
  alt: "",
131
+ draggable: "false",
131
132
  className: (0, _classnames["default"])('new-img-container', className),
132
133
  src: isShow ? src : '',
133
134
  style: __assign({
@@ -83,7 +83,11 @@ function (_super) {
83
83
 
84
84
  _this.state = {
85
85
  carouseIndex: 0,
86
- hoverState: false
86
+ hoverState: false,
87
+ isDragging: false,
88
+ startX: 0,
89
+ startY: 0,
90
+ hasDragged: false
87
91
  };
88
92
  _this.carouselRef = /*#__PURE__*/_react["default"].createRef();
89
93
  _this.destroy = null;
@@ -136,6 +140,161 @@ function (_super) {
136
140
  if ((_b = data.setting.navigation) === null || _b === void 0 ? void 0 : _b.size) {
137
141
  e.target.style.fontSize = data.setting.navigation.size;
138
142
  }
143
+ }; // 鼠标拖拽相关方法
144
+
145
+
146
+ _this.handleMouseDown = function (e) {
147
+ var _a; // 设计器模式下禁用拖拽
148
+
149
+
150
+ if ((0, _coreUtil.isDesignMode)() && ((_a = window.magicDesign) === null || _a === void 0 ? void 0 : _a.mode) !== 'renderer') {
151
+ return;
152
+ }
153
+
154
+ _this.setState({
155
+ isDragging: true,
156
+ startX: e.clientX,
157
+ startY: e.clientY
158
+ });
159
+ };
160
+
161
+ _this.handleMouseMove = function (e) {
162
+ if (!_this.state.isDragging) return; // 防止默认行为,避免选中文本
163
+
164
+ e.preventDefault(); // 如果移动距离超过阈值,标记为已拖拽
165
+
166
+ var _a = _this.state,
167
+ startX = _a.startX,
168
+ startY = _a.startY;
169
+ var deltaX = Math.abs(e.clientX - startX);
170
+ var deltaY = Math.abs(e.clientY - startY);
171
+
172
+ if (deltaX > 5 || deltaY > 5) {
173
+ _this.setState({
174
+ hasDragged: true
175
+ });
176
+ }
177
+ };
178
+
179
+ _this.handleMouseUp = function (e) {
180
+ _this.processMouseUp(e.clientX, e.clientY);
181
+ };
182
+
183
+ _this.handleGlobalMouseMove = function (e) {
184
+ if (!_this.state.isDragging) return; // 防止默认行为,避免选中文本
185
+
186
+ e.preventDefault(); // 如果移动距离超过阈值,标记为已拖拽
187
+
188
+ var _a = _this.state,
189
+ startX = _a.startX,
190
+ startY = _a.startY;
191
+ var deltaX = Math.abs(e.clientX - startX);
192
+ var deltaY = Math.abs(e.clientY - startY);
193
+
194
+ if (deltaX > 5 || deltaY > 5) {
195
+ _this.setState({
196
+ hasDragged: true
197
+ });
198
+ }
199
+ };
200
+
201
+ _this.handleGlobalMouseUp = function (e) {
202
+ if (!_this.state.isDragging) return;
203
+
204
+ _this.processMouseUp(e.clientX, e.clientY);
205
+ };
206
+
207
+ _this.processMouseUp = function (endX, endY) {
208
+ var _a, _b;
209
+
210
+ if (!_this.state.isDragging) return;
211
+ var _c = _this.state,
212
+ startX = _c.startX,
213
+ startY = _c.startY,
214
+ hasDragged = _c.hasDragged;
215
+ var deltaX = startX - endX;
216
+ var deltaY = startY - endY; // 判断是否为水平滑动(水平距离大于垂直距离,且水平距离超过阈值)
217
+
218
+ var minSwipeDistance = 50; // 最小滑动距离阈值
219
+
220
+ if (Math.abs(deltaX) > Math.abs(deltaY) && Math.abs(deltaX) > minSwipeDistance) {
221
+ if (deltaX > 0) {
222
+ // 向左滑动,切换到下一页
223
+ (_a = _this.carouselRef.current) === null || _a === void 0 ? void 0 : _a.next();
224
+ } else {
225
+ // 向右滑动,切换到上一页
226
+ (_b = _this.carouselRef.current) === null || _b === void 0 ? void 0 : _b.prev();
227
+ }
228
+ } // 如果发生了拖拽,延迟重置以便阻止点击事件
229
+ // 如果没有拖拽,立即重置,允许点击事件正常触发
230
+
231
+
232
+ if (hasDragged) {
233
+ setTimeout(function () {
234
+ _this.setState({
235
+ isDragging: false,
236
+ startX: 0,
237
+ startY: 0,
238
+ hasDragged: false
239
+ });
240
+ }, 100);
241
+ } else {
242
+ // 没有拖拽,立即重置,允许点击
243
+ _this.setState({
244
+ isDragging: false,
245
+ startX: 0,
246
+ startY: 0,
247
+ hasDragged: false
248
+ });
249
+ }
250
+ };
251
+
252
+ _this.handleMouseLeave = function () {
253
+ // 鼠标离开时重置拖拽状态
254
+ if (_this.state.isDragging) {
255
+ var hasDragged = _this.state.hasDragged;
256
+
257
+ if (hasDragged) {
258
+ setTimeout(function () {
259
+ _this.setState({
260
+ isDragging: false,
261
+ startX: 0,
262
+ startY: 0,
263
+ hasDragged: false
264
+ });
265
+ }, 100);
266
+ } else {
267
+ // 没有拖拽,立即重置
268
+ _this.setState({
269
+ isDragging: false,
270
+ startX: 0,
271
+ startY: 0,
272
+ hasDragged: false
273
+ });
274
+ }
275
+ }
276
+ }; // 阻止拖拽后的点击事件 - 使用捕获阶段
277
+
278
+
279
+ _this.handleClickCapture = function (e) {
280
+ // 只有在真正发生拖拽时才阻止点击
281
+ if (_this.state.hasDragged) {
282
+ e.preventDefault();
283
+ e.stopPropagation(); // 阻止所有子元素的点击事件
284
+
285
+ e.nativeEvent.stopImmediatePropagation();
286
+ }
287
+ }; // 阻止拖拽后的点击事件
288
+
289
+
290
+ _this.handleClick = function (e) {
291
+ // 只有在真正发生拖拽时才阻止点击
292
+ if (_this.state.hasDragged) {
293
+ e.preventDefault();
294
+ e.stopPropagation(); // 阻止所有子元素的点击事件
295
+
296
+ e.nativeEvent.stopImmediatePropagation();
297
+ }
139
298
  }; // padding用统一设置
140
299
 
141
300
 
@@ -195,9 +354,16 @@ function (_super) {
195
354
  BannerPc.prototype.componentDidMount = function () {
196
355
  var _this = this;
197
356
 
357
+ var _a;
358
+
198
359
  this.destroy = (0, _mobx.autorun)(function () {
199
360
  _this.bannerGoto(_this.props.data.groupSource);
200
- });
361
+ }); // 添加全局鼠标事件监听,处理鼠标移出元素的情况
362
+
363
+ if (!(0, _coreUtil.isDesignMode)() || ((_a = window.magicDesign) === null || _a === void 0 ? void 0 : _a.mode) === 'renderer') {
364
+ document.addEventListener('mousemove', this.handleGlobalMouseMove);
365
+ document.addEventListener('mouseup', this.handleGlobalMouseUp);
366
+ }
201
367
  };
202
368
 
203
369
  BannerPc.prototype.componentWillReceiveProps = function (nextProps) {
@@ -205,7 +371,10 @@ function (_super) {
205
371
  };
206
372
 
207
373
  BannerPc.prototype.componentWillUnmount = function () {
208
- this.destroy();
374
+ this.destroy(); // 移除全局鼠标事件监听
375
+
376
+ document.removeEventListener('mousemove', this.handleGlobalMouseMove);
377
+ document.removeEventListener('mouseup', this.handleGlobalMouseUp);
209
378
  };
210
379
 
211
380
  BannerPc.prototype.render = function () {
@@ -250,17 +419,31 @@ function (_super) {
250
419
  autoplaySpeed: data.setting.autoplay.interval * 1000,
251
420
  dots: false
252
421
  }, data.groupSource.map(function (item, index) {
253
- var _a, _b;
422
+ var _a, _b, _c;
254
423
 
255
424
  return /*#__PURE__*/_react["default"].createElement("div", {
256
425
  key: item.id
257
426
  }, /*#__PURE__*/_react["default"].createElement("div", {
258
427
  style: _this.getBackgroundStyle(item)
259
428
  }, /*#__PURE__*/_react["default"].createElement("div", {
260
- className: "carouselItem",
429
+ className: (0, _classnames["default"])('carouselItem', {
430
+ dragging: _this.state.isDragging,
431
+ 'no-click': _this.state.hasDragged
432
+ }),
261
433
  onMouseEnter: _this.mouseEnterWrap,
262
- onMouseLeave: _this.mouseLeaveWrap,
263
- style: _this.getItemStyle(item)
434
+ onMouseLeave: function onMouseLeave(e) {
435
+ _this.mouseLeaveWrap();
436
+
437
+ _this.handleMouseLeave();
438
+ },
439
+ onMouseDown: _this.handleMouseDown,
440
+ onMouseMove: _this.handleMouseMove,
441
+ onMouseUp: _this.handleMouseUp,
442
+ onClick: _this.handleClick,
443
+ onClickCapture: _this.handleClickCapture,
444
+ style: __assign(__assign({}, _this.getItemStyle(item)), {
445
+ cursor: _this.state.isDragging ? 'grabbing' : !(0, _coreUtil.isDesignMode)() || ((_a = window.magicDesign) === null || _a === void 0 ? void 0 : _a.mode) === 'renderer' ? 'grab' : 'default'
446
+ })
264
447
  }, /*#__PURE__*/_react["default"].createElement(_components.MetaImage, {
265
448
  data: item.image,
266
449
  GAData: __assign(__assign({}, GAData), {
@@ -296,7 +479,7 @@ function (_super) {
296
479
  className: "btn-wrap",
297
480
  style: {
298
481
  justifyContent: _AlignSelector.alignItemMap[item.customize.align],
299
- width: Math.max((_a = item.title.content) === null || _a === void 0 ? void 0 : _a.pcWidth, (_b = item.text.content) === null || _b === void 0 ? void 0 : _b.pcWidth) + "%"
482
+ width: Math.max((_b = item.title.content) === null || _b === void 0 ? void 0 : _b.pcWidth, (_c = item.text.content) === null || _c === void 0 ? void 0 : _c.pcWidth) + "%"
300
483
  }
301
484
  }, item.button.open && /*#__PURE__*/_react["default"].createElement(_components.MetaButton, {
302
485
  className: "btn",
@@ -41,17 +41,34 @@
41
41
  }
42
42
 
43
43
  .leftBtn {
44
- left: 20px;
44
+ left: 70px;
45
45
  }
46
46
 
47
47
  .rightBtn {
48
- right: 20px;
48
+ right: 70px;
49
49
  }
50
50
 
51
51
  .carouselItem {
52
52
  // height: 360px;
53
53
  display: flex;
54
54
  position: relative;
55
+ // 拖拽相关样式
56
+ -webkit-user-select: none;
57
+ -moz-user-select: none;
58
+ -ms-user-select: none;
59
+ user-select: none;
60
+ -webkit-touch-callout: none;
61
+
62
+ &.dragging {
63
+ cursor: grabbing !important;
64
+ }
65
+
66
+ // 拖拽时禁用子元素的点击事件
67
+ &.no-click {
68
+ * {
69
+ pointer-events: none !important;
70
+ }
71
+ }
55
72
 
56
73
  .carouseContent {
57
74
  padding: 0 80px;
@@ -7,6 +7,8 @@ exports["default"] = void 0;
7
7
 
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
 
10
+ var _classnames = _interopRequireDefault(require("classnames"));
11
+
10
12
  require("./index.less");
11
13
 
12
14
  var _lodash = _interopRequireDefault(require("lodash.throttle"));
@@ -307,7 +309,11 @@ function (_super) {
307
309
  now: '',
308
310
  isWill: false,
309
311
  scrollToLeftDisabled: true,
310
- scrollToRightDisabled: true
312
+ scrollToRightDisabled: true,
313
+ isDragging: false,
314
+ startX: 0,
315
+ startScrollLeft: 0,
316
+ hasDragged: false
311
317
  };
312
318
 
313
319
  _this.getFlashData = function (pageSize, campaign) {
@@ -424,6 +430,171 @@ function (_super) {
424
430
  if (scrollDom.scrollLeft > 0) {
425
431
  scrollDom.scrollTo(scrollDom.scrollLeft - scrollDom.clientWidth, 0);
426
432
  }
433
+ }; // 鼠标拖拽滚动相关方法
434
+
435
+
436
+ _this.handleMouseDown = function (e) {
437
+ var _a; // 设计器模式下禁用拖拽
438
+
439
+
440
+ if ((0, _coreUtil.isDesignMode)() && ((_a = window.magicDesign) === null || _a === void 0 ? void 0 : _a.mode) !== 'renderer') {
441
+ return;
442
+ }
443
+
444
+ var scrollDom = _this.scrollRef.current;
445
+ if (!scrollDom) return;
446
+
447
+ _this.setState({
448
+ isDragging: true,
449
+ startX: e.clientX,
450
+ startScrollLeft: scrollDom.scrollLeft
451
+ });
452
+ };
453
+
454
+ _this.handleMouseMove = function (e) {
455
+ if (!_this.state.isDragging) return;
456
+ e.preventDefault(); // 如果移动距离超过阈值,标记为已拖拽
457
+
458
+ var startX = _this.state.startX;
459
+ var deltaX = Math.abs(e.clientX - startX);
460
+
461
+ if (deltaX > 5) {
462
+ _this.setState({
463
+ hasDragged: true
464
+ });
465
+ }
466
+
467
+ _this.updateScrollPosition(e.clientX);
468
+ };
469
+
470
+ _this.handleGlobalMouseMove = function (e) {
471
+ if (!_this.state.isDragging) return;
472
+ e.preventDefault(); // 如果移动距离超过阈值,标记为已拖拽
473
+
474
+ var startX = _this.state.startX;
475
+ var deltaX = Math.abs(e.clientX - startX);
476
+
477
+ if (deltaX > 5) {
478
+ _this.setState({
479
+ hasDragged: true
480
+ });
481
+ }
482
+
483
+ _this.updateScrollPosition(e.clientX);
484
+ };
485
+
486
+ _this.handleGlobalMouseUp = function (e) {
487
+ if (!_this.state.isDragging) return;
488
+ var hasDragged = _this.state.hasDragged; // 如果发生了拖拽,延迟重置以便阻止点击事件
489
+ // 如果没有拖拽,立即重置,允许点击事件正常触发
490
+
491
+ if (hasDragged) {
492
+ setTimeout(function () {
493
+ _this.setState({
494
+ isDragging: false,
495
+ startX: 0,
496
+ startScrollLeft: 0,
497
+ hasDragged: false
498
+ });
499
+ }, 100);
500
+ } else {
501
+ // 没有拖拽,立即重置,允许点击
502
+ _this.setState({
503
+ isDragging: false,
504
+ startX: 0,
505
+ startScrollLeft: 0,
506
+ hasDragged: false
507
+ });
508
+ }
509
+ };
510
+
511
+ _this.handleMouseUp = function (e) {
512
+ if (!_this.state.isDragging) return;
513
+ var hasDragged = _this.state.hasDragged; // 如果发生了拖拽,延迟重置以便阻止点击事件
514
+ // 如果没有拖拽,立即重置,允许点击事件正常触发
515
+
516
+ if (hasDragged) {
517
+ setTimeout(function () {
518
+ _this.setState({
519
+ isDragging: false,
520
+ startX: 0,
521
+ startScrollLeft: 0,
522
+ hasDragged: false
523
+ });
524
+ }, 100);
525
+ } else {
526
+ // 没有拖拽,立即重置,允许点击
527
+ _this.setState({
528
+ isDragging: false,
529
+ startX: 0,
530
+ startScrollLeft: 0,
531
+ hasDragged: false
532
+ });
533
+ }
534
+ };
535
+
536
+ _this.handleMouseLeave = function () {
537
+ // 鼠标离开时重置拖拽状态
538
+ if (_this.state.isDragging) {
539
+ var hasDragged = _this.state.hasDragged;
540
+
541
+ if (hasDragged) {
542
+ setTimeout(function () {
543
+ _this.setState({
544
+ isDragging: false,
545
+ startX: 0,
546
+ startScrollLeft: 0,
547
+ hasDragged: false
548
+ });
549
+ }, 100);
550
+ } else {
551
+ // 没有拖拽,立即重置
552
+ _this.setState({
553
+ isDragging: false,
554
+ startX: 0,
555
+ startScrollLeft: 0,
556
+ hasDragged: false
557
+ });
558
+ }
559
+ }
560
+ }; // 阻止拖拽后的点击事件 - 使用捕获阶段
561
+
562
+
563
+ _this.handleClickCapture = function (e) {
564
+ // 只有在真正发生拖拽时才阻止点击
565
+ if (_this.state.hasDragged) {
566
+ e.preventDefault();
567
+ e.stopPropagation(); // 阻止所有子元素的点击事件
568
+
569
+ e.nativeEvent.stopImmediatePropagation();
570
+ }
571
+ }; // 阻止拖拽后的点击事件
572
+
573
+
574
+ _this.handleClick = function (e) {
575
+ // 只有在真正发生拖拽时才阻止点击
576
+ if (_this.state.hasDragged) {
577
+ e.preventDefault();
578
+ e.stopPropagation(); // 阻止所有子元素的点击事件
579
+
580
+ e.nativeEvent.stopImmediatePropagation();
581
+ }
582
+ };
583
+
584
+ _this.updateScrollPosition = function (currentX) {
585
+ var scrollDom = _this.scrollRef.current;
586
+ if (!scrollDom) return;
587
+ var _a = _this.state,
588
+ startX = _a.startX,
589
+ startScrollLeft = _a.startScrollLeft;
590
+ var deltaX = currentX - startX;
591
+ var newScrollLeft = startScrollLeft - deltaX; // 限制滚动范围
592
+
593
+ var maxScrollLeft = scrollDom.scrollWidth - scrollDom.clientWidth;
594
+ var clampedScrollLeft = Math.max(0, Math.min(newScrollLeft, maxScrollLeft));
595
+ scrollDom.scrollLeft = clampedScrollLeft;
596
+
597
+ _this.setScrollDisabled(scrollDom);
427
598
  };
428
599
 
429
600
  return _this;
@@ -432,6 +603,8 @@ function (_super) {
432
603
  FlashDealPc.prototype.componentDidMount = function () {
433
604
  var _this = this;
434
605
 
606
+ var _a;
607
+
435
608
  this.sortType = this.props.panelProps.content.sortType;
436
609
  this.getNextFlashSale();
437
610
  setTimeout(function () {
@@ -444,7 +617,12 @@ function (_super) {
444
617
  _this.setScrollDisabled(scrollDom);
445
618
  }, 500);
446
619
  }
447
- }, 0);
620
+ }, 0); // 添加全局鼠标事件监听,处理鼠标拖拽滚动
621
+
622
+ if (!(0, _coreUtil.isDesignMode)() || ((_a = window.magicDesign) === null || _a === void 0 ? void 0 : _a.mode) === 'renderer') {
623
+ document.addEventListener('mousemove', this.handleGlobalMouseMove);
624
+ document.addEventListener('mouseup', this.handleGlobalMouseUp);
625
+ }
448
626
  };
449
627
 
450
628
  FlashDealPc.prototype.componentWillReceiveProps = function (nextProps) {
@@ -471,20 +649,26 @@ function (_super) {
471
649
  }
472
650
  };
473
651
 
652
+ FlashDealPc.prototype.componentWillUnmount = function () {
653
+ // 移除全局鼠标事件监听
654
+ document.removeEventListener('mousemove', this.handleGlobalMouseMove);
655
+ document.removeEventListener('mouseup', this.handleGlobalMouseUp);
656
+ };
657
+
474
658
  FlashDealPc.prototype.render = function () {
475
659
  var _this = this;
476
660
 
477
- var _a, _b;
661
+ var _a, _b, _c;
478
662
 
479
663
  var panelProps = this.props.panelProps;
480
- var _c = this.state,
481
- list = _c.list,
482
- effDate = _c.effDate,
483
- expDate = _c.expDate,
484
- now = _c.now,
485
- isWill = _c.isWill,
486
- scrollToLeftDisabled = _c.scrollToLeftDisabled,
487
- scrollToRightDisabled = _c.scrollToRightDisabled;
664
+ var _d = this.state,
665
+ list = _d.list,
666
+ effDate = _d.effDate,
667
+ expDate = _d.expDate,
668
+ now = _d.now,
669
+ isWill = _d.isWill,
670
+ scrollToLeftDisabled = _d.scrollToLeftDisabled,
671
+ scrollToRightDisabled = _d.scrollToRightDisabled;
488
672
 
489
673
  var _list = list.length === 0 && (0, _coreUtil.isDesignMode)() ? defaultData : list;
490
674
 
@@ -526,7 +710,18 @@ function (_super) {
526
710
  type: "icon-outlined-left"
527
711
  })), /*#__PURE__*/_react["default"].createElement("div", {
528
712
  ref: this.scrollRef,
529
- className: "flash-deal-list"
713
+ className: (0, _classnames["default"])('flash-deal-list', {
714
+ 'no-click': this.state.hasDragged
715
+ }),
716
+ onMouseDown: this.handleMouseDown,
717
+ onMouseMove: this.handleMouseMove,
718
+ onMouseUp: this.handleMouseUp,
719
+ onMouseLeave: this.handleMouseLeave,
720
+ onClick: this.handleClick,
721
+ onClickCapture: this.handleClickCapture,
722
+ style: {
723
+ cursor: this.state.isDragging ? 'grabbing' : !(0, _coreUtil.isDesignMode)() || ((_c = window.magicDesign) === null || _c === void 0 ? void 0 : _c.mode) === 'renderer' ? 'grab' : 'default'
724
+ }
530
725
  }, _list.map(function (item) {
531
726
  return /*#__PURE__*/_react["default"].createElement(_ProductItem["default"], {
532
727
  key: item.id,
@@ -93,6 +93,30 @@
93
93
  position: relative;
94
94
  flex: 1;
95
95
  gap: 40px;
96
+ // 拖拽相关样式
97
+ -webkit-user-select: none;
98
+ -moz-user-select: none;
99
+ -ms-user-select: none;
100
+ user-select: none;
101
+ -webkit-touch-callout: none;
102
+ // 隐藏滚动条但保持滚动功能
103
+ scrollbar-width: none; /* Firefox */
104
+ -ms-overflow-style: none; /* IE and Edge */
105
+
106
+ &::-webkit-scrollbar {
107
+ display: none; /* Chrome, Safari, Opera */
108
+ }
109
+
110
+ &.dragging {
111
+ cursor: grabbing !important;
112
+ }
113
+
114
+ // 拖拽时禁用子元素的点击事件
115
+ &.no-click {
116
+ * {
117
+ pointer-events: none !important;
118
+ }
119
+ }
96
120
  }
97
121
  }
98
122
 
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.205",
4
+ "version": "1.0.207",
5
5
  "description": "Magic Design",
6
6
  "license": "MIT",
7
7
  "module": "es/index.js",