@liuzengwei/element-ui 2.15.5-xn.21 → 2.15.5-xn.22

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/lib/table.js CHANGED
@@ -694,6 +694,13 @@ var render = function() {
694
694
  [_vm._t("default")],
695
695
  2
696
696
  ),
697
+ _vm.showHeader && _vm.stickyHeader !== false
698
+ ? _c("div", {
699
+ ref: "headerPlaceholder",
700
+ staticClass: "el-table__header-placeholder",
701
+ style: { height: "0px", visibility: "hidden" }
702
+ })
703
+ : _vm._e(),
697
704
  _vm.showHeader
698
705
  ? _c(
699
706
  "div",
@@ -4473,6 +4480,13 @@ var tablevue_type_script_lang_js_extends = Object.assign || function (target) {
4473
4480
  //
4474
4481
  //
4475
4482
  //
4483
+ //
4484
+ //
4485
+ //
4486
+ //
4487
+ //
4488
+ //
4489
+ //
4476
4490
 
4477
4491
 
4478
4492
 
@@ -4763,6 +4777,101 @@ var tableIdSeed = 1;
4763
4777
  },
4764
4778
  toggleAllSelection: function toggleAllSelection() {
4765
4779
  this.store.commit('toggleAllSelection');
4780
+ },
4781
+
4782
+
4783
+ // 初始化 sticky 滚动处理
4784
+ initStickyScroll: function initStickyScroll() {
4785
+ var _this = this;
4786
+
4787
+ if (this.stickyHeader === false) return;
4788
+
4789
+ this.$nextTick(function () {
4790
+ var headerWrapper = _this.$refs.headerWrapper;
4791
+ var headerPlaceholder = _this.$refs.headerPlaceholder;
4792
+ if (!headerWrapper) return;
4793
+
4794
+ _this.stickyScrollHandler = function () {
4795
+ var tableRect = _this.$el.getBoundingClientRect();
4796
+ var stickyOffset = typeof _this.stickyHeader === 'number' ? _this.stickyHeader : 0;
4797
+
4798
+ // 判断是否应该吸顶
4799
+ var shouldStick = tableRect.top <= stickyOffset;
4800
+ var shouldUnstick = tableRect.bottom <= headerWrapper.offsetHeight + stickyOffset;
4801
+
4802
+ if (shouldStick && !shouldUnstick) {
4803
+ // 需要吸顶
4804
+ if (!headerWrapper.classList.contains('is-fixed')) {
4805
+ // 设置占位符高度,防止页面跳动
4806
+ if (headerPlaceholder) {
4807
+ headerPlaceholder.style.height = headerWrapper.offsetHeight + 'px';
4808
+ headerPlaceholder.style.visibility = 'visible';
4809
+ }
4810
+
4811
+ headerWrapper.classList.add('is-fixed');
4812
+ headerWrapper.style.position = 'fixed';
4813
+ headerWrapper.style.top = stickyOffset + 'px';
4814
+ headerWrapper.style.left = tableRect.left + 'px';
4815
+ headerWrapper.style.width = tableRect.width + 'px';
4816
+ headerWrapper.style.zIndex = '2000';
4817
+ headerWrapper.style.backgroundColor = '#fff';
4818
+ } else {
4819
+ // 更新位置(处理水平滚动)
4820
+ headerWrapper.style.left = tableRect.left + 'px';
4821
+ }
4822
+ } else {
4823
+ // 不需要吸顶,恢复原状
4824
+ if (headerWrapper.classList.contains('is-fixed')) {
4825
+ headerWrapper.classList.remove('is-fixed');
4826
+ headerWrapper.style.position = '';
4827
+ headerWrapper.style.top = '';
4828
+ headerWrapper.style.left = '';
4829
+ headerWrapper.style.width = '';
4830
+ headerWrapper.style.zIndex = '';
4831
+ headerWrapper.style.backgroundColor = '';
4832
+
4833
+ // 隐藏占位符
4834
+ if (headerPlaceholder) {
4835
+ headerPlaceholder.style.height = '0px';
4836
+ headerPlaceholder.style.visibility = 'hidden';
4837
+ }
4838
+ }
4839
+ }
4840
+ };
4841
+
4842
+ // 监听 window 滚动
4843
+ window.addEventListener('scroll', _this.stickyScrollHandler, { passive: true });
4844
+ // 监听 window resize
4845
+ window.addEventListener('resize', _this.stickyScrollHandler, { passive: true });
4846
+ });
4847
+ },
4848
+
4849
+
4850
+ // 销毁 sticky 滚动处理
4851
+ destroyStickyScroll: function destroyStickyScroll() {
4852
+ if (this.stickyScrollHandler) {
4853
+ window.removeEventListener('scroll', this.stickyScrollHandler);
4854
+ window.removeEventListener('resize', this.stickyScrollHandler);
4855
+
4856
+ // 清理样式
4857
+ var headerWrapper = this.$refs.headerWrapper;
4858
+ var headerPlaceholder = this.$refs.headerPlaceholder;
4859
+ if (headerWrapper && headerWrapper.classList.contains('is-fixed')) {
4860
+ headerWrapper.classList.remove('is-fixed');
4861
+ headerWrapper.style.position = '';
4862
+ headerWrapper.style.top = '';
4863
+ headerWrapper.style.left = '';
4864
+ headerWrapper.style.width = '';
4865
+ headerWrapper.style.zIndex = '';
4866
+ headerWrapper.style.backgroundColor = '';
4867
+ }
4868
+ if (headerPlaceholder) {
4869
+ headerPlaceholder.style.height = '0px';
4870
+ headerPlaceholder.style.visibility = 'hidden';
4871
+ }
4872
+
4873
+ this.stickyScrollHandler = null;
4874
+ }
4766
4875
  }
4767
4876
  },
4768
4877
 
@@ -4916,15 +5025,15 @@ var tableIdSeed = 1;
4916
5025
  },
4917
5026
 
4918
5027
  created: function created() {
4919
- var _this = this;
5028
+ var _this2 = this;
4920
5029
 
4921
5030
  this.tableId = 'el-table_' + tableIdSeed++;
4922
5031
  this.debouncedUpdateLayout = Object(external_throttle_debounce_["debounce"])(50, function () {
4923
- return _this.doLayout();
5032
+ return _this2.doLayout();
4924
5033
  });
4925
5034
  },
4926
5035
  mounted: function mounted() {
4927
- var _this2 = this;
5036
+ var _this3 = this;
4928
5037
 
4929
5038
  this.bindEvents();
4930
5039
  this.store.updateColumns();
@@ -4938,7 +5047,7 @@ var tableIdSeed = 1;
4938
5047
  // init filters
4939
5048
  this.store.states.columns.forEach(function (column) {
4940
5049
  if (column.filteredValue && column.filteredValue.length) {
4941
- _this2.store.commit('filterChange', {
5050
+ _this3.store.commit('filterChange', {
4942
5051
  column: column,
4943
5052
  values: column.filteredValue,
4944
5053
  silent: true
@@ -4946,10 +5055,16 @@ var tableIdSeed = 1;
4946
5055
  }
4947
5056
  });
4948
5057
 
5058
+ // 初始化滚动容器检测
5059
+ if (this.stickyHeader !== false) {
5060
+ this.initStickyScroll();
5061
+ }
5062
+
4949
5063
  this.$ready = true;
4950
5064
  },
4951
5065
  destroyed: function destroyed() {
4952
5066
  this.unbindEvents();
5067
+ this.destroyStickyScroll();
4953
5068
  },
4954
5069
  data: function data() {
4955
5070
  var _treeProps = this.treeProps,
@@ -4985,7 +5100,9 @@ var tableIdSeed = 1;
4985
5100
  },
4986
5101
  // 是否拥有多级表头
4987
5102
  isGroup: false,
4988
- scrollPosition: 'left'
5103
+ scrollPosition: 'left',
5104
+ // sticky 滚动处理函数
5105
+ stickyScrollHandler: null
4989
5106
  };
4990
5107
  }
4991
5108
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liuzengwei/element-ui",
3
- "version": "2.15.5-xn.21",
3
+ "version": "2.15.5-xn.22",
4
4
  "description": "A Component Library for Vue.js (Fork of Element UI).",
5
5
  "main": "lib/element-ui.common.js",
6
6
  "files": [
@@ -290,14 +290,14 @@
290
290
  handleInputChange(value) {
291
291
  // 使用 parser 解析格式化的值
292
292
  let parsedValue = value;
293
-
293
+
294
294
  // 先移除千分符
295
295
  if (this.thousandSeparator && value !== '') {
296
296
  const separator = this.thousandSeparator === true ? ',' : this.thousandSeparator;
297
297
  // 移除所有千分符
298
298
  parsedValue = parsedValue.split(separator).join('');
299
299
  }
300
-
300
+
301
301
  // 再应用自定义 parser
302
302
  if (this.parser && parsedValue !== '') {
303
303
  parsedValue = this.parser(parsedValue);
@@ -15,6 +15,13 @@
15
15
  }, tableSize ? `el-table--${ tableSize }` : '']"
16
16
  @mouseleave="handleMouseLeave($event)">
17
17
  <div class="hidden-columns" ref="hiddenColumns"><slot></slot></div>
18
+ <!-- sticky header 占位符 -->
19
+ <div
20
+ v-if="showHeader && stickyHeader !== false"
21
+ class="el-table__header-placeholder"
22
+ ref="headerPlaceholder"
23
+ :style="{ height: '0px', visibility: 'hidden' }">
24
+ </div>
18
25
  <div
19
26
  v-if="showHeader"
20
27
  v-mousewheel="handleHeaderFooterMousewheel"
@@ -505,6 +512,97 @@
505
512
 
506
513
  toggleAllSelection() {
507
514
  this.store.commit('toggleAllSelection');
515
+ },
516
+
517
+ // 初始化 sticky 滚动处理
518
+ initStickyScroll() {
519
+ if (this.stickyHeader === false) return;
520
+
521
+ this.$nextTick(() => {
522
+ const headerWrapper = this.$refs.headerWrapper;
523
+ const headerPlaceholder = this.$refs.headerPlaceholder;
524
+ if (!headerWrapper) return;
525
+
526
+ this.stickyScrollHandler = () => {
527
+ const tableRect = this.$el.getBoundingClientRect();
528
+ const stickyOffset = typeof this.stickyHeader === 'number' ? this.stickyHeader : 0;
529
+
530
+ // 判断是否应该吸顶
531
+ const shouldStick = tableRect.top <= stickyOffset;
532
+ const shouldUnstick = tableRect.bottom <= headerWrapper.offsetHeight + stickyOffset;
533
+
534
+ if (shouldStick && !shouldUnstick) {
535
+ // 需要吸顶
536
+ if (!headerWrapper.classList.contains('is-fixed')) {
537
+ // 设置占位符高度,防止页面跳动
538
+ if (headerPlaceholder) {
539
+ headerPlaceholder.style.height = `${headerWrapper.offsetHeight}px`;
540
+ headerPlaceholder.style.visibility = 'visible';
541
+ }
542
+
543
+ headerWrapper.classList.add('is-fixed');
544
+ headerWrapper.style.position = 'fixed';
545
+ headerWrapper.style.top = `${stickyOffset}px`;
546
+ headerWrapper.style.left = `${tableRect.left}px`;
547
+ headerWrapper.style.width = `${tableRect.width}px`;
548
+ headerWrapper.style.zIndex = '2000';
549
+ headerWrapper.style.backgroundColor = '#fff';
550
+ } else {
551
+ // 更新位置(处理水平滚动)
552
+ headerWrapper.style.left = `${tableRect.left}px`;
553
+ }
554
+ } else {
555
+ // 不需要吸顶,恢复原状
556
+ if (headerWrapper.classList.contains('is-fixed')) {
557
+ headerWrapper.classList.remove('is-fixed');
558
+ headerWrapper.style.position = '';
559
+ headerWrapper.style.top = '';
560
+ headerWrapper.style.left = '';
561
+ headerWrapper.style.width = '';
562
+ headerWrapper.style.zIndex = '';
563
+ headerWrapper.style.backgroundColor = '';
564
+
565
+ // 隐藏占位符
566
+ if (headerPlaceholder) {
567
+ headerPlaceholder.style.height = '0px';
568
+ headerPlaceholder.style.visibility = 'hidden';
569
+ }
570
+ }
571
+ }
572
+ };
573
+
574
+ // 监听 window 滚动
575
+ window.addEventListener('scroll', this.stickyScrollHandler, { passive: true });
576
+ // 监听 window resize
577
+ window.addEventListener('resize', this.stickyScrollHandler, { passive: true });
578
+ });
579
+ },
580
+
581
+ // 销毁 sticky 滚动处理
582
+ destroyStickyScroll() {
583
+ if (this.stickyScrollHandler) {
584
+ window.removeEventListener('scroll', this.stickyScrollHandler);
585
+ window.removeEventListener('resize', this.stickyScrollHandler);
586
+
587
+ // 清理样式
588
+ const headerWrapper = this.$refs.headerWrapper;
589
+ const headerPlaceholder = this.$refs.headerPlaceholder;
590
+ if (headerWrapper && headerWrapper.classList.contains('is-fixed')) {
591
+ headerWrapper.classList.remove('is-fixed');
592
+ headerWrapper.style.position = '';
593
+ headerWrapper.style.top = '';
594
+ headerWrapper.style.left = '';
595
+ headerWrapper.style.width = '';
596
+ headerWrapper.style.zIndex = '';
597
+ headerWrapper.style.backgroundColor = '';
598
+ }
599
+ if (headerPlaceholder) {
600
+ headerPlaceholder.style.height = '0px';
601
+ headerPlaceholder.style.visibility = 'hidden';
602
+ }
603
+
604
+ this.stickyScrollHandler = null;
605
+ }
508
606
  }
509
607
 
510
608
  },
@@ -691,11 +789,17 @@
691
789
  }
692
790
  });
693
791
 
792
+ // 初始化滚动容器检测
793
+ if (this.stickyHeader !== false) {
794
+ this.initStickyScroll();
795
+ }
796
+
694
797
  this.$ready = true;
695
798
  },
696
799
 
697
800
  destroyed() {
698
801
  this.unbindEvents();
802
+ this.destroyStickyScroll();
699
803
  },
700
804
 
701
805
  data() {
@@ -727,7 +831,9 @@
727
831
  },
728
832
  // 是否拥有多级表头
729
833
  isGroup: false,
730
- scrollPosition: 'left'
834
+ scrollPosition: 'left',
835
+ // sticky 滚动处理函数
836
+ stickyScrollHandler: null
731
837
  };
732
838
  }
733
839
  };
package/src/index.js CHANGED
@@ -216,7 +216,7 @@ if (typeof window !== 'undefined' && window.Vue) {
216
216
  }
217
217
 
218
218
  export default {
219
- version: '2.15.5-xn.21',
219
+ version: '2.15.5-xn.22',
220
220
  locale: locale.use,
221
221
  i18n: locale.i18n,
222
222
  install,