vite-uni-dev-tool 0.0.11 → 0.0.13

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.
Files changed (180) hide show
  1. package/README.md +55 -1
  2. package/dist/const.d.ts +133 -0
  3. package/dist/const.d.ts.map +1 -0
  4. package/dist/const.js +36 -0
  5. package/dist/core.d.ts +52 -0
  6. package/dist/core.d.ts.map +1 -0
  7. package/dist/core.js +80 -0
  8. package/dist/devConsole/index.d.ts +169 -0
  9. package/dist/devConsole/index.d.ts.map +1 -0
  10. package/dist/devConsole/index.js +270 -0
  11. package/dist/devEvent/index.d.ts +286 -0
  12. package/dist/devEvent/index.d.ts.map +1 -0
  13. package/dist/devEvent/index.js +435 -0
  14. package/dist/devEventBus/index.d.ts +42 -0
  15. package/dist/devEventBus/index.d.ts.map +1 -0
  16. package/dist/devEventBus/index.js +70 -0
  17. package/dist/devIntercept/index.d.ts +119 -0
  18. package/dist/devIntercept/index.d.ts.map +1 -0
  19. package/dist/devIntercept/index.js +582 -0
  20. package/dist/devRunJS/index.d.ts +67 -0
  21. package/dist/devRunJS/index.d.ts.map +1 -0
  22. package/dist/devStore/index.d.ts +178 -0
  23. package/dist/devStore/index.d.ts.map +1 -0
  24. package/dist/devStore/index.js +395 -0
  25. package/dist/devToolInfo/index.d.ts +17 -0
  26. package/dist/devToolInfo/index.d.ts.map +1 -0
  27. package/dist/devToolInfo/index.js +15 -0
  28. package/{dev → dist}/plugins/uniDevTool/uniDevTool.d.ts +15 -1
  29. package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +1 -0
  30. package/dist/plugins/uniDevTool/uniDevTool.js +35 -0
  31. package/{dev → dist}/plugins/uniGlobalComponents/uniGlobalComponents.js +7 -7
  32. package/{dev → dist}/plugins/utils/index.d.ts +3 -0
  33. package/{dev → dist}/plugins/utils/index.d.ts.map +1 -1
  34. package/dist/plugins/utils/index.js +1 -0
  35. package/dist/type.d.ts +264 -0
  36. package/dist/type.d.ts.map +1 -0
  37. package/dist/utils/array.d.ts +2 -0
  38. package/dist/utils/array.d.ts.map +1 -0
  39. package/dist/utils/array.js +12 -0
  40. package/dist/utils/date.d.ts +19 -0
  41. package/dist/utils/date.d.ts.map +1 -0
  42. package/dist/utils/date.js +40 -0
  43. package/dist/utils/file.d.ts +11 -0
  44. package/dist/utils/file.d.ts.map +1 -0
  45. package/dist/utils/file.js +87 -0
  46. package/dist/utils/function.d.ts +28 -0
  47. package/dist/utils/function.d.ts.map +1 -0
  48. package/dist/utils/function.js +46 -0
  49. package/dist/utils/index.d.ts +11 -0
  50. package/dist/utils/index.d.ts.map +1 -0
  51. package/dist/utils/index.js +55 -0
  52. package/dist/utils/ip.d.ts +5 -0
  53. package/dist/utils/ip.d.ts.map +1 -0
  54. package/dist/utils/ip.js +21 -0
  55. package/dist/utils/language.d.ts +29 -0
  56. package/dist/utils/language.d.ts.map +1 -0
  57. package/dist/utils/language.js +50 -0
  58. package/dist/utils/object.d.ts +49 -0
  59. package/dist/utils/object.d.ts.map +1 -0
  60. package/dist/utils/object.js +118 -0
  61. package/dist/utils/page.d.ts +7 -0
  62. package/dist/utils/page.d.ts.map +1 -0
  63. package/dist/utils/page.js +7 -0
  64. package/dist/utils/platform.d.ts +4 -0
  65. package/dist/utils/platform.d.ts.map +1 -0
  66. package/dist/utils/platform.js +14 -0
  67. package/dist/utils/string.d.ts +45 -0
  68. package/dist/utils/string.d.ts.map +1 -0
  69. package/dist/utils/string.js +88 -0
  70. package/dist/utils/utils.d.ts +16 -0
  71. package/dist/utils/utils.d.ts.map +1 -0
  72. package/dist/v2/AutoSizer/utils.d.ts +5 -0
  73. package/dist/v2/AutoSizer/utils.d.ts.map +1 -0
  74. package/dist/v2/JsonPretty/hooks/useClipboard.d.ts +4 -0
  75. package/dist/v2/JsonPretty/hooks/useClipboard.d.ts.map +1 -0
  76. package/dist/v2/JsonPretty/hooks/useError.d.ts +8 -0
  77. package/dist/v2/JsonPretty/hooks/useError.d.ts.map +1 -0
  78. package/dist/v2/JsonPretty/type.d.ts +93 -0
  79. package/dist/v2/JsonPretty/type.d.ts.map +1 -0
  80. package/dist/v3/AutoSizer/utils.d.ts +5 -0
  81. package/dist/v3/AutoSizer/utils.d.ts.map +1 -0
  82. package/dist/v3/ConsoleList/staticTips.d.ts +13 -0
  83. package/dist/v3/ConsoleList/staticTips.d.ts.map +1 -0
  84. package/dist/v3/JsonPretty/hooks/useClipboard.d.ts +4 -0
  85. package/dist/v3/JsonPretty/hooks/useClipboard.d.ts.map +1 -0
  86. package/dist/v3/JsonPretty/hooks/useError.d.ts +8 -0
  87. package/dist/v3/JsonPretty/hooks/useError.d.ts.map +1 -0
  88. package/dist/v3/JsonPretty/type.d.ts +93 -0
  89. package/dist/v3/JsonPretty/type.d.ts.map +1 -0
  90. package/dist/v3/JsonPretty/utils/index.d.ts +10 -0
  91. package/dist/v3/JsonPretty/utils/index.d.ts.map +1 -0
  92. package/package.json +5 -5
  93. package/dev/components/AppInfo/index.vue +0 -36
  94. package/dev/components/AutoSizer/index.vue +0 -193
  95. package/dev/components/AutoSizer/index1.vue +0 -186
  96. package/dev/components/AutoSizer/utils.ts +0 -49
  97. package/dev/components/Button/index.vue +0 -34
  98. package/dev/components/CaptureScreen/index.vue +0 -62
  99. package/dev/components/Checkbox/index.vue +0 -40
  100. package/dev/components/CloseButton/index.vue +0 -26
  101. package/dev/components/Code/index.vue +0 -230
  102. package/dev/components/Connection/index.vue +0 -88
  103. package/dev/components/ConsoleList/Code.vue +0 -227
  104. package/dev/components/ConsoleList/ConsoleItem.vue +0 -186
  105. package/dev/components/ConsoleList/RunJSInput.vue +0 -235
  106. package/dev/components/ConsoleList/index.vue +0 -130
  107. package/dev/components/ConsoleList/staticTips.ts +0 -1145
  108. package/dev/components/DevTool/index.vue +0 -182
  109. package/dev/components/DevToolButton/index.vue +0 -213
  110. package/dev/components/DevToolTitle/index.vue +0 -21
  111. package/dev/components/DevToolWindow/index.vue +0 -1037
  112. package/dev/components/DeviceInfo/index.vue +0 -32
  113. package/dev/components/Empty/empty.png +0 -0
  114. package/dev/components/Empty/index.vue +0 -28
  115. package/dev/components/FilterInput/index.vue +0 -86
  116. package/dev/components/JsonPretty/components/Brackets/index.vue +0 -23
  117. package/dev/components/JsonPretty/components/Carets/index.vue +0 -59
  118. package/dev/components/JsonPretty/components/CheckController/index.vue +0 -125
  119. package/dev/components/JsonPretty/components/TreeNode/index.vue +0 -349
  120. package/dev/components/JsonPretty/hooks/useClipboard.ts +0 -21
  121. package/dev/components/JsonPretty/hooks/useError.ts +0 -21
  122. package/dev/components/JsonPretty/index.vue +0 -474
  123. package/dev/components/JsonPretty/type.ts +0 -125
  124. package/dev/components/JsonPretty/utils/index.ts +0 -172
  125. package/dev/components/NetworkList/NetworkDetail.vue +0 -197
  126. package/dev/components/NetworkList/NetworkItem.vue +0 -106
  127. package/dev/components/NetworkList/index.vue +0 -115
  128. package/dev/components/PiniaList/index.vue +0 -64
  129. package/dev/components/RouteList/index.vue +0 -110
  130. package/dev/components/RunJS/index.vue +0 -128
  131. package/dev/components/SettingList/index.vue +0 -225
  132. package/dev/components/StorageList/index.vue +0 -170
  133. package/dev/components/SystemInfo/index.vue +0 -34
  134. package/dev/components/Tabs/index.vue +0 -123
  135. package/dev/components/Tag/index.vue +0 -89
  136. package/dev/components/UniEvent/UniEventItem.vue +0 -124
  137. package/dev/components/UniEvent/index.vue +0 -94
  138. package/dev/components/UploadList/UploadDetail.vue +0 -208
  139. package/dev/components/UploadList/UploadItem.vue +0 -111
  140. package/dev/components/UploadList/index.vue +0 -104
  141. package/dev/components/VirtualList/index.vue +0 -112
  142. package/dev/components/VirtualListPro/AutoSize.vue +0 -43
  143. package/dev/components/VirtualListPro/index.vue +0 -175
  144. package/dev/components/VirtualListPro/readme.md +0 -40
  145. package/dev/components/VuexList/index.vue +0 -54
  146. package/dev/components/WebSocket/WebSocketItem.vue +0 -98
  147. package/dev/components/WebSocket/WebSocketList.vue +0 -176
  148. package/dev/components/WebSocket/index.vue +0 -111
  149. package/dev/components/WindowInfo/index.vue +0 -33
  150. package/dev/const.ts +0 -166
  151. package/dev/core.ts +0 -118
  152. package/dev/devConsole/index.ts +0 -350
  153. package/dev/devEvent/index.ts +0 -806
  154. package/dev/devEventBus/index.ts +0 -94
  155. package/dev/devIntercept/index.ts +0 -745
  156. package/dev/devRunJS/index.ts +0 -170
  157. package/dev/devStore/index.ts +0 -718
  158. package/dev/plugins/uniDevTool/uniDevTool.d.ts.map +0 -1
  159. package/dev/plugins/uniDevTool/uniDevTool.js +0 -36
  160. package/dev/plugins/utils/index.js +0 -1
  161. package/dev/shims-uni.d.ts +0 -43
  162. package/dev/type.ts +0 -264
  163. package/dev/utils/array.ts +0 -15
  164. package/dev/utils/date.ts +0 -75
  165. package/dev/utils/file.ts +0 -121
  166. package/dev/utils/function.ts +0 -192
  167. package/dev/utils/index.d.ts +0 -6
  168. package/dev/utils/index.ts +0 -46
  169. package/dev/utils/ip.ts +0 -79
  170. package/dev/utils/language.ts +0 -72
  171. package/dev/utils/object.ts +0 -298
  172. package/dev/utils/page.ts +0 -13
  173. package/dev/utils/platform.ts +0 -14
  174. package/dev/utils/string.ts +0 -133
  175. package/dev/utils/utils.ts +0 -198
  176. /package/{dev → dist}/index.d.ts +0 -0
  177. /package/{dev → dist}/index.d.ts.map +0 -0
  178. /package/{dev → dist}/index.js +0 -0
  179. /package/{dev → dist}/plugins/uniGlobalComponents/uniGlobalComponents.d.ts +0 -0
  180. /package/{dev → dist}/plugins/uniGlobalComponents/uniGlobalComponents.d.ts.map +0 -0
@@ -1,111 +0,0 @@
1
- <template>
2
- <view class="upload-item">
3
- <view class="upload-url-row">
4
- <Tag mode="info">POST</Tag>
5
- <view class="upload-url" v-html="upload.url" />
6
- <Tag
7
- mode="main"
8
- class="upload-detail-icon"
9
- @click="showDetail = !showDetail"
10
- >详情</Tag
11
- >
12
- </view>
13
- <view class="upload-info">
14
- <view>
15
- <Tag v-if="upload.status === 'pending'" mode="info">
16
- {{ upload.status }}
17
- </Tag>
18
- <Tag v-if="upload.status === 'uploading'" mode="warn">
19
- {{ upload.status }}
20
- </Tag>
21
- <Tag v-if="upload.status === 'success'" mode="success">
22
- {{ upload.status }}
23
- </Tag>
24
- <Tag v-if="upload.status === 'error'" mode="error">
25
- {{ upload.status }}
26
- </Tag>
27
- </view>
28
- <view>进度: {{ upload.progress }}%</view>
29
- <view>
30
- 开始:
31
- {{ upload.startTime ? formatDate(upload.startTime, ' HH:mm:ss') : '-' }}
32
- </view>
33
- <view>
34
- 结束:
35
- {{ upload.endTime ? formatDate(upload.endTime, ' HH:mm:ss') : '-' }}
36
- </view>
37
- </view>
38
- </view>
39
- <!-- <Transition name="slide-fade"> -->
40
- <UploadDetail v-if="showDetail" :upload="upload" @close="onClose" />
41
- <!-- </Transition> -->
42
- </template>
43
-
44
- <script lang="ts" setup>
45
- import { ref } from 'vue';
46
- import Tag from '../Tag/index.vue';
47
- import UploadDetail from './UploadDetail.vue';
48
- import { formatDate } from '../../utils';
49
- import type { DevTool } from '../../type';
50
- defineProps<{
51
- upload: DevTool.UploadItem;
52
- }>();
53
- const showDetail = ref(false);
54
-
55
- function onClose() {
56
- showDetail.value = false;
57
- }
58
- </script>
59
- <style scoped>
60
- .upload-item {
61
- padding: 16px;
62
- border-bottom: 1px solid var(--dev-tool-border-color);
63
- font-size: var(--dev-tool-base-font-size);
64
- }
65
- .upload-item .upload-url-row {
66
- display: flex;
67
- align-items: center;
68
- word-break: break-all;
69
- }
70
- .websocket-item .websocket-url-row .websocket-url {
71
- margin-left: 4px;
72
- flex: 1;
73
- white-space: nowrap;
74
- overflow: hidden;
75
- text-overflow: ellipsis;
76
- }
77
-
78
- .upload-item .upload-url-row .upload-detail-icon {
79
- flex-shrink: 0;
80
- margin-left: auto;
81
- }
82
- .upload-url {
83
- margin-left: 4px;
84
- flex: 1;
85
- white-space: nowrap;
86
- overflow: hidden;
87
- text-overflow: ellipsis;
88
- }
89
- .upload-item .upload-url-row .upload-detail-active {
90
- transform: rotate(135deg);
91
- }
92
- .upload-item .upload-info {
93
- display: flex;
94
- align-items: center;
95
- justify-content: space-between;
96
- margin-top: 4px;
97
- color: #616161;
98
- }
99
-
100
- .slide-fade-enter-active {
101
- transition: all 0.8s ease-out;
102
- }
103
- .slide-fade-leave-active {
104
- transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
105
- }
106
- .slide-fade-enter-from,
107
- .slide-fade-leave-to {
108
- transform: translateY(20px);
109
- opacity: 0;
110
- }
111
- </style>
@@ -1,104 +0,0 @@
1
- <template>
2
- <view class="upload-content">
3
- <view class="upload-control">
4
- <FilterInput
5
- :modelValue="modelValue"
6
- placeholder="查询url"
7
- @search="emit('search', $event)"
8
- @update:modelValue="emit('update:modelValue', $event)"
9
- />
10
- <Tag
11
- v-for="item in uploadFilterItems"
12
- :mode="item.mode"
13
- :key="item.value"
14
- :active="item.value === currentUploadType"
15
- @click="onChoose(item.value)"
16
- >
17
- {{ item.label }}
18
- </Tag>
19
- </view>
20
- <VirtualListPro :data="uploadList" :pageSize="10" className="upload-list">
21
- <template v-slot="{ list, start }">
22
- <AutoSize
23
- v-for="(item, index) in list"
24
- :index="start + index"
25
- :key="start + index"
26
- >
27
- <UploadItem :upload="item" />
28
- </AutoSize>
29
- <Empty v-if="!uploadList || uploadList.length === 0" />
30
- </template>
31
- </VirtualListPro>
32
- </view>
33
- </template>
34
- <script lang="ts" setup>
35
- import Tag from '../Tag/index.vue';
36
- import UploadItem from './UploadItem.vue';
37
- import Empty from '../Empty/index.vue';
38
- import FilterInput from '../FilterInput/index.vue';
39
- import type { DevTool } from '../../type';
40
- import VirtualListPro from '../VirtualListPro/index.vue';
41
- import AutoSize from '../VirtualListPro/AutoSize.vue';
42
-
43
- defineProps<{
44
- currentUploadType: string;
45
- uploadList: DevTool.UploadItem[];
46
- modelValue: string;
47
- }>();
48
-
49
- const emit = defineEmits<{
50
- (e: 'choose', type: string): void;
51
- (e: 'update:modelValue', value: string): void;
52
- (e: 'search', value: string): void;
53
- }>();
54
- const uploadFilterItems = [
55
- {
56
- label: '全部',
57
- value: 'all',
58
- mode: 'all',
59
- },
60
- {
61
- label: 'pending',
62
- value: 'pending',
63
- mode: 'info',
64
- },
65
- {
66
- label: 'success',
67
- value: 'success',
68
- mode: 'success',
69
- },
70
- {
71
- label: 'error',
72
- value: 'error',
73
- mode: 'error',
74
- },
75
- {
76
- label: '清除',
77
- value: 'clear',
78
- mode: 'clear',
79
- },
80
- ];
81
-
82
- function onChoose(type: string) {
83
- emit('choose', type);
84
- }
85
- </script>
86
- <style scoped>
87
- .upload-content {
88
- height: 100%;
89
- font-size: var(--dev-tool-base-font-size);
90
- }
91
- .upload-list {
92
- height: calc(100% - 32px);
93
- }
94
- .upload-control {
95
- display: flex;
96
- align-items: center;
97
- justify-content: space-between;
98
- gap: 8px;
99
- padding: 0 16px;
100
- height: 32px;
101
- border-bottom: 1px solid var(--dev-tool-border-color);
102
- box-sizing: border-box;
103
- }
104
- </style>
@@ -1,112 +0,0 @@
1
- <template>
2
- <scroll-view
3
- v-if="autoVirtual"
4
- scroll-y
5
- class="virtual-list"
6
- :style="{
7
- height: `${props.height}px`,
8
- }"
9
- @scroll="onVirtualScroll"
10
- >
11
- <view
12
- class="virtual-list-holder"
13
- :style="{
14
- height: `${props.data.length * props.itemHeight}px`,
15
- }"
16
- >
17
- <view
18
- class="virtual-list-holder-inner"
19
- :style="{
20
- transform: `translateY(${state.translateY}px)`,
21
- }"
22
- >
23
- <slot :list="state.visibleData"></slot>
24
- </view>
25
- </view>
26
- </scroll-view>
27
- <view
28
- v-else
29
- class="normal-list"
30
- :style="{
31
- height: `${props.height}px`,
32
- }"
33
- >
34
- <slot :list="state.visibleData"></slot>
35
- </view>
36
- </template>
37
- <script lang="ts" setup>
38
- import { computed, onMounted, reactive, watchEffect } from 'vue';
39
- const props = defineProps<{
40
- /** 虚拟列表高度 */
41
- height: number;
42
- /** 每一项高度 */
43
- itemHeight: number;
44
- /** 渲染的数据列表 */
45
- data: any[];
46
- /** 虚拟列表自动开启行数 */
47
- autoVirtualRow?: number;
48
- }>();
49
-
50
- const state = reactive<{ translateY: number; visibleData: any[] }>({
51
- translateY: 0,
52
- visibleData: [],
53
- });
54
-
55
- const autoVirtual = computed(() => {
56
- if (typeof props.autoVirtualRow === 'number') {
57
- if (props.data.length > props.autoVirtualRow) {
58
- return true;
59
- }
60
- return false;
61
- }
62
- return true;
63
- });
64
-
65
- function updateVisibleData(scrollTop: number = 0) {
66
- const flatDataValue = props.data ?? [];
67
- if (autoVirtual.value) {
68
- const visibleCount = props.height / props.itemHeight;
69
- const scrollCount = Math.floor(scrollTop / props.itemHeight);
70
- let start =
71
- scrollCount < 0
72
- ? 0
73
- : scrollCount + visibleCount > flatDataValue.length
74
- ? flatDataValue.length - visibleCount
75
- : scrollCount;
76
- if (start < 0) {
77
- start = 0;
78
- }
79
- const end = start + visibleCount;
80
- state.translateY = start * props.itemHeight;
81
- state.visibleData = state.visibleData = props.data.slice(start, end);
82
- } else {
83
- state.visibleData = flatDataValue;
84
- }
85
- }
86
-
87
- function onVirtualScroll(e: { detail: { scrollTop: number } }) {
88
- updateVisibleData(e?.detail?.scrollTop ?? 0);
89
- }
90
-
91
- watchEffect(() => {
92
- if (props.data) {
93
- updateVisibleData();
94
- }
95
- });
96
-
97
- onMounted(() => {
98
- updateVisibleData();
99
- });
100
- </script>
101
- <style scoped>
102
- .normal-list,
103
- .virtual-list {
104
- position: relative;
105
- width: 100%;
106
- overflow: auto;
107
- }
108
-
109
- .virtual-list-holder {
110
- position: relative;
111
- }
112
- </style>
@@ -1,43 +0,0 @@
1
- <template>
2
- <view :class="className">
3
- <slot></slot>
4
- </view>
5
- </template>
6
- <script lang="ts" setup>
7
- import { getCurrentInstance, onMounted, inject, nextTick } from 'vue';
8
- import { uniqueId } from '../../utils';
9
-
10
- const props = defineProps<{
11
- index: number;
12
- }>();
13
-
14
- const className = uniqueId('virtual-');
15
-
16
- const instance = getCurrentInstance();
17
-
18
- const query = uni.createSelectorQuery().in(instance);
19
-
20
- const onSizeChange =
21
- inject<(index: number, height: number) => void>('onSizeChange');
22
-
23
- const itemsHeight = inject<number[]>('itemsHeight');
24
-
25
- onMounted(() => {
26
- // TODO 可能会存在异步高度的问题
27
- // TODO image 加载完成之后获取高度
28
-
29
- if (itemsHeight?.[props.index]) return;
30
-
31
- nextTick(() => {
32
- query
33
- .select('.' + className)
34
- .boundingClientRect((rect) => {
35
- if (Array.isArray(rect)) return;
36
- onSizeChange?.(props.index, rect.height ?? 0);
37
- })
38
- .exec();
39
- });
40
- });
41
- </script>
42
-
43
- <style scoped></style>
@@ -1,175 +0,0 @@
1
- <template>
2
- <scroll-view
3
- :lower-threshold="preLodeHeight"
4
- :scroll-into-view="scrollIntoView"
5
- :scroll-with-animation="scrollWithAnimation"
6
- :class="['virtual-list', className]"
7
- scroll-y
8
- @scroll="onScroll"
9
- @scrolltolower="onScrollToLower"
10
- >
11
- <!-- 阈值判断 -->
12
- <view :style="{ height: `${state.currentHeight}px` }"></view>
13
- <view>
14
- <!-- 将可视数据传入到slot -->
15
- <slot
16
- :list="state.visitableData"
17
- :current="state.current"
18
- :start="(state.current - 1) * props.pageSize"
19
- ></slot>
20
- </view>
21
- </scroll-view>
22
- </template>
23
- <script lang="ts" setup>
24
- import { reactive, watch, onBeforeMount, provide } from 'vue';
25
-
26
- const props = withDefaults(
27
- defineProps<{
28
- /** 渲染数据 */
29
- data: any[];
30
- /** 虚拟列表高度 */
31
- height?: number;
32
- /**
33
- * 将对传入的data进行分页
34
- * 如何获取pageSize?
35
- * 虚拟列表高度 / 预估每条的最小高度 +
36
- */
37
- pageSize?: number;
38
- /** 预加载高度 */
39
- preLodeHeight?: number;
40
- /** 类名 */
41
- className?: string;
42
- /** 滚动到指定元素 */
43
- scrollIntoView?: string;
44
- /** 滚动动画 */
45
- scrollWithAnimation?: boolean;
46
- }>(),
47
- {
48
- height: 400,
49
- pageSize: 10,
50
- preLodeHeight: 50,
51
- },
52
- );
53
-
54
- const state = reactive<{
55
- /** 加载次数 */
56
- current: number;
57
- visitableData: any[];
58
- currentHeight: number;
59
- height: number;
60
- }>({
61
- height: 0,
62
- current: 1,
63
- visitableData: [],
64
- currentHeight: 0,
65
- });
66
- /**
67
- * 每一项的高度
68
- */
69
- const itemsHeight: number[] = [];
70
-
71
- provide('itemsHeight', itemsHeight);
72
-
73
- onBeforeMount(() => {
74
- // 初始渲染数据
75
- state.visitableData = props.data.slice(0, props.pageSize * 2);
76
- });
77
-
78
- // 数据更新时重置
79
- watch(
80
- () => [props.data, props.pageSize],
81
- () => {
82
- state.visitableData = props.data.slice(0, props.pageSize * 2);
83
- },
84
- );
85
-
86
- /** 向上滚动和向下滚动 */
87
- function updateVisitableData(direction: 'up' | 'down') {
88
- let tempList = [...state.visitableData];
89
-
90
- if (direction === 'down') {
91
- // 将最前面的内容进行隐藏
92
- tempList.splice(0, props.pageSize);
93
-
94
- // 处理下一页内容
95
- const start = props.pageSize * state.current;
96
- let end = props.pageSize * (state.current + 1);
97
-
98
- if (start >= props.data.length) {
99
- return;
100
- }
101
-
102
- if (end > props.data.length) {
103
- end = props.data.length;
104
- }
105
-
106
- const newData = props.data.slice(start, end);
107
-
108
- tempList.push(...newData);
109
- } else {
110
- // 将最末尾的部分进行隐藏
111
- const delCount =
112
- tempList.length - props.pageSize > 0
113
- ? props.pageSize
114
- : tempList.length - props.pageSize;
115
-
116
- tempList.splice(props.pageSize, delCount);
117
-
118
- // 处理上一页内容
119
- let start = props.pageSize * (state.current - 1);
120
-
121
- const end = props.pageSize * state.current;
122
-
123
- if (end < 0) return;
124
-
125
- if (start < 0) {
126
- start = 0;
127
- }
128
- const newData = props.data.slice(start, end);
129
- tempList.unshift(...newData);
130
- }
131
- state.visitableData = tempList;
132
- }
133
-
134
- /** 计算合并的高度 */
135
- function updateCurrentHeight() {
136
- const total = itemsHeight
137
- .slice(0, state.current * props.pageSize)
138
- ?.reduce((acc, cur) => acc + cur, 0);
139
-
140
- state.currentHeight = total;
141
- }
142
-
143
- /** 滚动到底部 */
144
- function onScrollToLower() {
145
- if ((state.current + 1) * props.pageSize < props.data.length) {
146
- state.current++;
147
-
148
- updateVisitableData('down');
149
-
150
- updateCurrentHeight();
151
- }
152
- }
153
-
154
- /** 滚动监听,是否小于合并高度 */
155
- function onScroll(e: { detail: { scrollTop: number } }) {
156
- if (
157
- state.current > 0 &&
158
- state.currentHeight > 0 &&
159
- e.detail.scrollTop - props.preLodeHeight < state.currentHeight
160
- ) {
161
- state.current--;
162
-
163
- updateVisitableData('up');
164
-
165
- updateCurrentHeight();
166
- }
167
- }
168
-
169
- /** 暴露给子组件获取子组件容器的高度 */
170
- function onSizeChange(index: number, height: number) {
171
- itemsHeight[index] = height;
172
- }
173
- provide('onSizeChange', onSizeChange);
174
- </script>
175
- <style scoped></style>
@@ -1,40 +0,0 @@
1
- # VirtualListAutoHeight
2
-
3
- 自适应高度虚拟列表
4
-
5
- ## 核心
6
-
7
- - 初始加载两页数据
8
- - 初始获取当前加载的渲染列表的数据 ,得到第一页高度
9
- - scroll-view
10
- - 滚动到底部(顶部)current + 1
11
- - createIntersectionObserver
12
- - 辅助反向监听节点是否出现再可视范围之内
13
- - current - 1
14
- - 数据分页之后确定每页高度,采用合并高度支撑滚动条
15
- - 合并高度计算逻辑: 第一页高度 = 第一页高度
16
- - 后续页高度 = 前面所有高度 + 当前页高度.
17
-
18
-
19
- 一页两条
20
-
21
- pageSize = 2
22
- current = 2
23
- visibleDate = [3,4,5,6]
24
-
25
- visibleDate.splice(1*2, visibleDate.length - 1*2)
26
-
27
- const start = cur
28
-
29
-
30
- 1
31
- 2
32
-
33
- 3
34
- 4
35
-
36
- 5
37
- 6
38
-
39
- current = 1
40
- visibleDate = [1,2,3,4]
@@ -1,54 +0,0 @@
1
- <template>
2
- <view class="vuex-content">
3
- <JsonPretty
4
- :data="vuexList"
5
- showLength
6
- editable
7
- v-if="showJson"
8
- @update:data="onUpdateData"
9
- @nodeClick="onNodeClick"
10
- />
11
- <Empty v-else />
12
- </view>
13
- </template>
14
- <script lang="ts" setup>
15
- import { computed, ref } from 'vue';
16
- import JsonPretty from '../JsonPretty/index.vue';
17
- import Empty from '../Empty/index.vue';
18
- const props = defineProps<{
19
- vuexList: Record<string, any>;
20
- }>();
21
- const emit = defineEmits<{
22
- (e: 'update:vuexList', data: Record<string, any>): void;
23
- (e: 'diffValue', value: any): void;
24
- }>();
25
- const showJson = computed(() => {
26
- try {
27
- const str = JSON.stringify(props.vuexList);
28
- if (typeof props.vuexList === 'object' && (str === '' || str === '{}')) {
29
- return false;
30
- }
31
- return true;
32
- } catch (error) {
33
- return false;
34
- }
35
- });
36
-
37
- let currentSelect: any;
38
- function onUpdateData(data: Record<string, any>) {
39
- const firstKey = currentSelect?.path.split('.')?.slice(1)?.[0];
40
- emit('update:vuexList', data);
41
- emit('diffValue', {
42
- [firstKey]: data[firstKey]
43
- });
44
- }
45
- function onNodeClick(node: any) {
46
- currentSelect = node;
47
- }
48
- </script>
49
- <style scoped>
50
- .vuex-content {
51
- padding: 16px;
52
- font-size: var(--dev-tool-base-font-size);
53
- }
54
- </style>