n20-common-lib 3.2.4 → 3.2.5

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.
@@ -48,7 +48,9 @@ export default {
48
48
  data() {
49
49
  return {
50
50
  // 自适应模式下指示器的测量数据
51
- measuredIndicator: { width: 0, height: 0, translateX: 0 }
51
+ measuredIndicator: { width: 0, height: 0, translateX: 0 },
52
+ indicatorResizeObserver: null,
53
+ indicatorRaf: null
52
54
  }
53
55
  },
54
56
  computed: {
@@ -85,8 +87,8 @@ export default {
85
87
  // 自适应模式:基于 DOM 测量定位
86
88
  const { width, height, translateX } = this.measuredIndicator
87
89
  return {
88
- width: `${width - 2 * gap}px`,
89
- height: `${height - 2 * gap}px`,
90
+ width: `${Math.max(width - 2 * gap, 0)}px`,
91
+ height: `${Math.max(height - 2 * gap, 0)}px`,
90
92
  top: `${gap}px`,
91
93
  left: `${gap}px`,
92
94
  transform: `translateX(${translateX}px)`
@@ -95,17 +97,33 @@ export default {
95
97
  },
96
98
  watch: {
97
99
  value() {
98
- if (!this.isFixedWidth) this.$nextTick(this.updateIndicator)
100
+ if (!this.isFixedWidth) this.$nextTick(this.syncIndicatorObserver)
99
101
  },
100
102
  options: {
101
103
  deep: true,
102
104
  handler() {
103
- if (!this.isFixedWidth) this.$nextTick(this.updateIndicator)
105
+ if (!this.isFixedWidth) this.$nextTick(this.syncIndicatorObserver)
104
106
  }
107
+ },
108
+ itemWidth() {
109
+ this.$nextTick(this.syncIndicatorObserver)
110
+ },
111
+ itemHeight() {
112
+ if (!this.isFixedWidth) this.$nextTick(this.scheduleIndicatorUpdate)
105
113
  }
106
114
  },
107
115
  mounted() {
108
- if (!this.isFixedWidth) this.updateIndicator()
116
+ this.syncIndicatorObserver()
117
+ },
118
+ activated() {
119
+ if (!this.isFixedWidth) this.scheduleIndicatorUpdate()
120
+ },
121
+ beforeDestroy() {
122
+ this.destroyIndicatorObserver()
123
+ if (this.indicatorRaf) {
124
+ this.cancelIndicatorFrame(this.indicatorRaf)
125
+ this.indicatorRaf = null
126
+ }
109
127
  },
110
128
  methods: {
111
129
  // 统一尺寸格式化
@@ -113,6 +131,56 @@ export default {
113
131
  if (typeof val === 'number') return `${val}px`
114
132
  return isNaN(val) ? val : `${val}px`
115
133
  },
134
+ syncIndicatorObserver() {
135
+ this.destroyIndicatorObserver()
136
+ if (this.isFixedWidth) return
137
+ this.scheduleIndicatorUpdate()
138
+
139
+ if (typeof window === 'undefined' || typeof window.ResizeObserver === 'undefined') {
140
+ if (typeof window !== 'undefined') {
141
+ window.addEventListener('resize', this.scheduleIndicatorUpdate)
142
+ }
143
+ return
144
+ }
145
+
146
+ this.indicatorResizeObserver = new window.ResizeObserver(() => {
147
+ this.scheduleIndicatorUpdate()
148
+ })
149
+ const container = this.$refs.container
150
+ const items = this.$refs.items || []
151
+ const activeIndex = this.options.findIndex((item) => item.value === this.value)
152
+ if (container) this.indicatorResizeObserver.observe(container)
153
+ if (items[activeIndex]) this.indicatorResizeObserver.observe(items[activeIndex])
154
+ },
155
+ destroyIndicatorObserver() {
156
+ if (this.indicatorResizeObserver) {
157
+ this.indicatorResizeObserver.disconnect()
158
+ this.indicatorResizeObserver = null
159
+ }
160
+ if (typeof window !== 'undefined') {
161
+ window.removeEventListener('resize', this.scheduleIndicatorUpdate)
162
+ }
163
+ },
164
+ requestIndicatorFrame(callback) {
165
+ if (typeof window !== 'undefined' && typeof window.requestAnimationFrame === 'function') {
166
+ return window.requestAnimationFrame(callback)
167
+ }
168
+ return setTimeout(callback, 16)
169
+ },
170
+ cancelIndicatorFrame(frameId) {
171
+ if (typeof window !== 'undefined' && typeof window.cancelAnimationFrame === 'function') {
172
+ window.cancelAnimationFrame(frameId)
173
+ return
174
+ }
175
+ clearTimeout(frameId)
176
+ },
177
+ scheduleIndicatorUpdate() {
178
+ if (this.indicatorRaf) this.cancelIndicatorFrame(this.indicatorRaf)
179
+ this.indicatorRaf = this.requestIndicatorFrame(() => {
180
+ this.indicatorRaf = null
181
+ this.updateIndicator()
182
+ })
183
+ },
116
184
  // 自适应模式下测量激活项的位置
117
185
  updateIndicator() {
118
186
  const items = this.$refs.items
package/src/index.js CHANGED
@@ -137,6 +137,7 @@ import tableProV3 from './components/v3/TablePro/index.vue'
137
137
  import FileUploadTableV3 from './components/v3/UploadList/index.vue'
138
138
  import ViewToggle from './components/ViewToggle/index.vue'
139
139
  import WorkCard from './components/WorkCard/index.vue'
140
+ import InfoCard from './components/InfoCard/index.vue'
140
141
  import WornPagination from './components/WornPagination/index.vue'
141
142
  import VTableLoading from './directives/loading/index.js'
142
143
 
@@ -266,6 +267,7 @@ const components = [
266
267
  BusiDatePicker,
267
268
  TableTransfer,
268
269
  WorkCard,
270
+ InfoCard,
269
271
  UploadMsg,
270
272
  Tree,
271
273
  DateChoose,
@@ -436,6 +438,7 @@ export {
436
438
  Upload,
437
439
  UploadMsg,
438
440
  WorkCard,
441
+ InfoCard,
439
442
  WornPagination,
440
443
  /* v3组件*/
441
444
  tableProV3,