@kdcloudjs/table 1.1.3-canary.8 → 1.1.3-canary.9

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.
@@ -91,6 +91,8 @@ export function columnDrag() {
91
91
  var currentTarget = e.currentTarget;
92
92
  var rect = e.currentTarget.parentElement.getClientRects()[0];
93
93
  var startX = rect.left;
94
+ var mouseDownClientX = e.clientX;
95
+ var mouseDownClientY = e.clientY;
94
96
  var moveData = [];
95
97
  var allColumns = collectNodes(columns);
96
98
  var tableBodyClientRect = tableBody.getBoundingClientRect();
@@ -110,8 +112,6 @@ export function columnDrag() {
110
112
  }
111
113
  };
112
114
 
113
- var stopClickPropagationFlag = false;
114
-
115
115
  function handleMouseMove(e) {
116
116
  var client = {
117
117
  clientX: e.clientX,
@@ -125,12 +125,6 @@ export function columnDrag() {
125
125
  if (e.clientX - leftPosition < 20) {
126
126
  return;
127
127
  } else {
128
- // 阻止列头点击事件,防止拖动后触发列头过滤事件
129
- if (stopClickPropagationFlag === false) {
130
- stopClickPropagationFlag = true;
131
- currentTarget.addEventListener('click', stopClickPropagation);
132
- }
133
-
134
128
  e.stopPropagation();
135
129
  }
136
130
 
@@ -250,11 +244,15 @@ export function columnDrag() {
250
244
  e.stopPropagation();
251
245
  document.body.removeEventListener('mousemove', handleMouseMove);
252
246
  document.body.removeEventListener('mouseup', handleMouseUp);
253
- window.removeEventListener('selectstart', disableSelect);
247
+ window.removeEventListener('selectstart', disableSelect); // 阻止列头点击事件,防止拖动后触发列头过滤事件
248
+
249
+ if (_isMoveWhenClicking(mouseDownClientX, mouseDownClientY, e.clientX, e.clientY)) {
250
+ currentTarget.addEventListener('click', stopClickPropagation);
251
+ }
252
+
254
253
  window.requestAnimationFrame(function () {
255
254
  // 取消阻止列头点击事件
256
255
  currentTarget.removeEventListener('click', stopClickPropagation);
257
- stopClickPropagationFlag = false;
258
256
  currentTarget = null;
259
257
 
260
258
  var _moveData = moveData,
@@ -373,4 +371,15 @@ function moveAllChildren(cols, cloumnsTranslateData, width, isMinus) {
373
371
  moveAllChildren(children, cloumnsTranslateData, width);
374
372
  }
375
373
  });
374
+ }
375
+
376
+ function _isMoveWhenClicking(mouseDownClientX, mouseDownClientY, mouseUpClientX, mouseUpClientY) {
377
+ var xDiff = mouseUpClientX - mouseDownClientX;
378
+ var yDiff = mouseUpClientY - mouseDownClientY; // 鼠标点按和松开的偏移量大于5px,认为存在移动
379
+
380
+ if (Math.sqrt(xDiff * xDiff + yDiff * yDiff) > 5) {
381
+ return true;
382
+ }
383
+
384
+ return false;
376
385
  }
@@ -105,6 +105,8 @@ function columnDrag() {
105
105
  var currentTarget = e.currentTarget;
106
106
  var rect = e.currentTarget.parentElement.getClientRects()[0];
107
107
  var startX = rect.left;
108
+ var mouseDownClientX = e.clientX;
109
+ var mouseDownClientY = e.clientY;
108
110
  var moveData = [];
109
111
  var allColumns = (0, _utils.collectNodes)(columns);
110
112
  var tableBodyClientRect = tableBody.getBoundingClientRect();
@@ -124,8 +126,6 @@ function columnDrag() {
124
126
  }
125
127
  };
126
128
 
127
- var stopClickPropagationFlag = false;
128
-
129
129
  function handleMouseMove(e) {
130
130
  var client = {
131
131
  clientX: e.clientX,
@@ -139,12 +139,6 @@ function columnDrag() {
139
139
  if (e.clientX - leftPosition < 20) {
140
140
  return;
141
141
  } else {
142
- // 阻止列头点击事件,防止拖动后触发列头过滤事件
143
- if (stopClickPropagationFlag === false) {
144
- stopClickPropagationFlag = true;
145
- currentTarget.addEventListener('click', stopClickPropagation);
146
- }
147
-
148
142
  e.stopPropagation();
149
143
  }
150
144
 
@@ -264,11 +258,15 @@ function columnDrag() {
264
258
  e.stopPropagation();
265
259
  document.body.removeEventListener('mousemove', handleMouseMove);
266
260
  document.body.removeEventListener('mouseup', handleMouseUp);
267
- window.removeEventListener('selectstart', disableSelect);
261
+ window.removeEventListener('selectstart', disableSelect); // 阻止列头点击事件,防止拖动后触发列头过滤事件
262
+
263
+ if (_isMoveWhenClicking(mouseDownClientX, mouseDownClientY, e.clientX, e.clientY)) {
264
+ currentTarget.addEventListener('click', stopClickPropagation);
265
+ }
266
+
268
267
  window.requestAnimationFrame(function () {
269
268
  // 取消阻止列头点击事件
270
269
  currentTarget.removeEventListener('click', stopClickPropagation);
271
- stopClickPropagationFlag = false;
272
270
  currentTarget = null;
273
271
 
274
272
  var _moveData = moveData,
@@ -386,4 +384,15 @@ function moveAllChildren(cols, cloumnsTranslateData, width, isMinus) {
386
384
  moveAllChildren(children, cloumnsTranslateData, width);
387
385
  }
388
386
  });
387
+ }
388
+
389
+ function _isMoveWhenClicking(mouseDownClientX, mouseDownClientY, mouseUpClientX, mouseUpClientY) {
390
+ var xDiff = mouseUpClientX - mouseDownClientX;
391
+ var yDiff = mouseUpClientY - mouseDownClientY; // 鼠标点按和松开的偏移量大于5px,认为存在移动
392
+
393
+ if (Math.sqrt(xDiff * xDiff + yDiff * yDiff) > 5) {
394
+ return true;
395
+ }
396
+
397
+ return false;
389
398
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kdcloudjs/table",
3
- "version": "1.1.3-canary.8",
3
+ "version": "1.1.3-canary.9",
4
4
  "description": "金蝶 react table 组件",
5
5
  "title": "table",
6
6
  "keywords": [