vite-uni-dev-tool 0.0.18 → 0.0.19

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/README.md CHANGED
@@ -197,6 +197,10 @@ optimizeDeps: {
197
197
 
198
198
  ## 更新日志
199
199
 
200
+ ### 0.0.19
201
+
202
+ - 修复 VirtualListPro 向上滚动
203
+
200
204
  ### 0.0.18
201
205
 
202
206
  - Network Send 兼容微信小程序
@@ -164,43 +164,22 @@ export default {
164
164
  }
165
165
  },
166
166
  // 更新可视区域数据
167
- updateVisitableData(direction) {
168
- let tempList = [...this.visitableData];
167
+ updateVisitableData() {
168
+ const tempList = [...this.visitableData];
169
169
  const pageSize = this.pageSize;
170
170
  const current = this.current;
171
171
 
172
- if (direction === 'down') {
173
- // 向下滚动:移除最前面的一页,添加新的一页
174
- tempList.splice(0, pageSize);
175
- const start = pageSize * current;
176
- let end = pageSize * (current + 1);
177
- end = end > this.dataSource.length ? this.dataSource.length : end;
178
- const newData = this.dataSource.slice(start, end);
179
- tempList.push(...newData);
180
- } else {
181
- // 向上滚动:移除最后面的多余数据,添加前面的一页
182
- // 将最末尾的部分进行隐藏
183
- const delCount =
184
- tempList.length - pageSize > 0
185
- ? pageSize
186
- : tempList.length - pageSize;
172
+ // 计算新的起始和结束索引
187
173
 
188
- tempList.splice(pageSize, delCount);
174
+ const currentSub1 = current - 1 < 0 ? 0 : current - 1;
175
+ const currentAdd1 = current + 1;
189
176
 
190
- // 处理上一页内容
191
- let start = pageSize * (current - 1);
177
+ const startIndex = currentSub1 * pageSize;
178
+ const endIndex = Math.min(currentAdd1 * pageSize, data.length);
192
179
 
193
- start = start < 0 ? 0 : start;
180
+ // 更新可见数据
194
181
 
195
- const end = pageSize * current;
196
-
197
- if (end < 0) return;
198
-
199
- const newData = this.dataSource.slice(start, end);
200
- tempList.unshift(...newData);
201
- }
202
-
203
- this.visitableData = tempList;
182
+ this.visitableData = tempList.slice(startIndex, endIndex);
204
183
  },
205
184
  // 更新总高度(累加已加载项的高度)
206
185
  updateCurrentHeight() {
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <view class="setting-content">
3
3
  <view class="setting-item">
4
- <DevToolTitle>DevTool(v0.0.18-vue3)</DevToolTitle>
4
+ <DevToolTitle>DevTool(v0.0.19-vue3)</DevToolTitle>
5
5
  <view class="setting-item-content">
6
6
  <view class="setting-row">
7
7
  <view>显示调试按钮:</view>
@@ -76,7 +76,7 @@ const state = reactive<{
76
76
  scrollTop: number;
77
77
  }>({
78
78
  height: 0,
79
- current: 1,
79
+ current: 0,
80
80
  visitableData: [],
81
81
  currentHeight: 0,
82
82
  scrollTop: 0,
@@ -118,51 +118,20 @@ watch(
118
118
  );
119
119
 
120
120
  /** 向上滚动和向下滚动 */
121
- function updateVisitableData(direction: 'up' | 'down') {
122
- let tempList = [...state.visitableData];
121
+ function updateVisitableData() {
122
+ const { pageSize, data } = props;
123
+ const { current } = state;
123
124
 
124
- if (direction === 'down') {
125
- // 将最前面的内容进行隐藏
126
- tempList.splice(0, props.pageSize);
125
+ // 计算新的起始和结束索引
127
126
 
128
- // 处理下一页内容
129
- const start = props.pageSize * state.current;
130
- let end = props.pageSize * (state.current + 1);
127
+ const currentSub1 = current - 1 < 0 ? 0 : current - 1;
128
+ const currentAdd1 = current + 1;
131
129
 
132
- if (start >= props.data.length) {
133
- return;
134
- }
130
+ const startIndex = currentSub1 * pageSize;
131
+ const endIndex = Math.min(currentAdd1 * pageSize, data.length);
135
132
 
136
- if (end > props.data.length) {
137
- end = props.data.length;
138
- }
139
-
140
- const newData = props.data.slice(start, end);
141
-
142
- tempList.push(...newData);
143
- } else {
144
- // 将最末尾的部分进行隐藏
145
- const delCount =
146
- tempList.length - props.pageSize > 0
147
- ? props.pageSize
148
- : tempList.length - props.pageSize;
149
-
150
- tempList.splice(props.pageSize, delCount);
151
-
152
- // 处理上一页内容
153
- let start = props.pageSize * (state.current - 1);
154
-
155
- const end = props.pageSize * state.current;
156
-
157
- if (end < 0) return;
158
-
159
- if (start < 0) {
160
- start = 0;
161
- }
162
- const newData = props.data.slice(start, end);
163
- tempList.unshift(...newData);
164
- }
165
- state.visitableData = tempList;
133
+ // 更新可见数据
134
+ state.visitableData = data.slice(startIndex, endIndex);
166
135
  }
167
136
 
168
137
  /** 计算合并的高度 */
@@ -179,7 +148,7 @@ function onScrollToLower() {
179
148
  if ((state.current + 1) * props.pageSize < props.data.length) {
180
149
  state.current++;
181
150
 
182
- updateVisitableData('down');
151
+ updateVisitableData();
183
152
 
184
153
  updateCurrentHeight();
185
154
  }
@@ -194,7 +163,7 @@ function onScroll(e: { detail: { scrollTop: number } }) {
194
163
  ) {
195
164
  state.current--;
196
165
 
197
- updateVisitableData('up');
166
+ updateVisitableData();
198
167
 
199
168
  updateCurrentHeight();
200
169
  }
@@ -213,7 +182,7 @@ function onBackTop() {
213
182
  nextTick(() => {
214
183
  state.current = 1;
215
184
  state.currentHeight = 0;
216
- updateVisitableData('up');
185
+ updateVisitableData();
217
186
 
218
187
  toView.value = '';
219
188
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-uni-dev-tool",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "description": "vite-uni-dev-tool, debug, uni-app, 一处编写,到处调试",
5
5
  "keywords": [
6
6
  "vite",