vite-uni-dev-tool 0.0.19 → 0.0.21

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.
@@ -6,6 +6,7 @@
6
6
  :style="style"
7
7
  :scroll-into-view="innerScrollIntoView"
8
8
  scroll-y
9
+ :scrollX="scrollX"
9
10
  @scroll="onScroll"
10
11
  @scrolltolower="onScrollToLower"
11
12
  >
@@ -34,7 +35,7 @@
34
35
  </template>
35
36
  <script lang="ts" setup>
36
37
  import { nextTick } from 'vue';
37
- import { uniqueId } from '../../utils';
38
+ import { debounce, uniqueId } from '../../utils';
38
39
  import { reactive, watch, onBeforeMount, provide, computed, ref } from 'vue';
39
40
 
40
41
  const props = withDefaults(
@@ -59,11 +60,15 @@ const props = withDefaults(
59
60
  scrollWithAnimation?: boolean;
60
61
  /** 返回顶部 */
61
62
  showBackTop?: boolean;
63
+ /** 默认当前页 */
64
+ defaultCurrent?: number;
65
+ scrollX?: boolean;
62
66
  }>(),
63
67
  {
64
68
  height: 400,
65
69
  pageSize: 10,
66
70
  preLodeHeight: 50,
71
+ defaultCurrent: 1,
67
72
  },
68
73
  );
69
74
 
@@ -76,7 +81,7 @@ const state = reactive<{
76
81
  scrollTop: number;
77
82
  }>({
78
83
  height: 0,
79
- current: 0,
84
+ current: 1,
80
85
  visitableData: [],
81
86
  currentHeight: 0,
82
87
  scrollTop: 0,
@@ -106,14 +111,47 @@ const innerScrollIntoView = computed(() => {
106
111
 
107
112
  onBeforeMount(() => {
108
113
  // 初始渲染数据
109
- state.visitableData = props.data.slice(0, props.pageSize * 2);
114
+ state.visitableData = props.data.slice(
115
+ (props.defaultCurrent - 1) * props.pageSize,
116
+ props.pageSize * 2,
117
+ );
118
+
119
+ state.currentHeight = itemsHeight
120
+ .slice(0, (props.defaultCurrent - 1) * props.pageSize)
121
+ ?.reduce((acc, cur) => acc + cur, 0);
110
122
  });
111
123
 
112
124
  // 数据更新时重置
113
125
  watch(
114
- () => [props.data, props.pageSize],
126
+ () => [props.data, props.pageSize, props.defaultCurrent],
115
127
  () => {
116
- state.visitableData = props.data.slice(0, props.pageSize * 2);
128
+ // state.visitableData = props.data.slice(
129
+ // (props.defaultCurrent - 1) * props.pageSize,
130
+ // props.pageSize * 2,
131
+ // );
132
+
133
+ // console.log(' state.visitableData: ', state.visitableData);
134
+
135
+ // state.currentHeight = itemsHeight
136
+ // .slice(0, (props.defaultCurrent - 1) * props.pageSize)
137
+ // ?.reduce((acc, cur) => acc + cur, 0);
138
+
139
+ const { pageSize, data, defaultCurrent } = props;
140
+
141
+ // 计算新的起始和结束索引
142
+
143
+ const currentSub1 = defaultCurrent - 1 < 0 ? 0 : defaultCurrent - 1;
144
+ const currentAdd1 = defaultCurrent + 1;
145
+
146
+ const startIndex = currentSub1 * pageSize;
147
+ const endIndex = Math.min(currentAdd1 * pageSize, data.length);
148
+
149
+ // 更新可见数据
150
+ state.visitableData = data.slice(startIndex, endIndex);
151
+
152
+ state.currentHeight = itemsHeight
153
+ .slice(0, currentSub1 * pageSize)
154
+ ?.reduce((acc, cur) => acc + cur, 0);
117
155
  },
118
156
  );
119
157
 
@@ -136,8 +174,12 @@ function updateVisitableData() {
136
174
 
137
175
  /** 计算合并的高度 */
138
176
  function updateCurrentHeight() {
177
+ const { pageSize } = props;
178
+ const { current } = state;
179
+ const currentSub1 = current - 1 < 0 ? 0 : current - 1;
180
+
139
181
  const total = itemsHeight
140
- .slice(0, state.current * props.pageSize)
182
+ .slice(0, currentSub1 * pageSize)
141
183
  ?.reduce((acc, cur) => acc + cur, 0);
142
184
 
143
185
  state.currentHeight = total;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-uni-dev-tool",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "vite-uni-dev-tool, debug, uni-app, 一处编写,到处调试",
5
5
  "keywords": [
6
6
  "vite",