vite-uni-dev-tool 0.0.6 → 0.0.8
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 +16 -0
- package/dev/components/Code/index.vue +227 -0
- package/dev/components/Connection/index.vue +11 -21
- package/dev/components/ConsoleList/Code.vue +1 -1
- package/dev/components/ConsoleList/ConsoleItem.vue +38 -12
- package/dev/components/ConsoleList/RunJSInput.vue +59 -0
- package/dev/components/ConsoleList/index.vue +24 -8
- package/dev/components/DevTool/index.vue +10 -9
- package/dev/components/DevToolButton/index.vue +10 -10
- package/dev/components/DevToolTitle/index.vue +21 -0
- package/dev/components/DevToolWindow/index.vue +62 -5
- package/dev/components/FilterInput/index.vue +1 -1
- package/dev/components/JsonPretty/components/CheckController/index.vue +22 -5
- package/dev/components/JsonPretty/components/TreeNode/index.vue +16 -15
- package/dev/components/JsonPretty/index.vue +77 -75
- package/dev/components/JsonPretty/type.ts +2 -0
- package/dev/components/NetworkList/NetworkDetail.vue +1 -1
- package/dev/components/RunJS/index.vue +128 -0
- package/dev/components/SettingList/index.vue +10 -20
- package/dev/components/UniEvent/UniEventItem.vue +124 -0
- package/dev/components/UniEvent/index.vue +94 -0
- package/dev/components/UploadList/UploadDetail.vue +1 -1
- package/dev/components/VirtualList/index.vue +112 -0
- package/dev/components/WebSocket/WebSocketList.vue +1 -1
- package/dev/const.ts +101 -28
- package/dev/core.ts +12 -3
- package/dev/devConsole/index.ts +21 -4
- package/dev/devEvent/index.ts +122 -8
- package/dev/devEventBus/index.ts +94 -0
- package/dev/devIntercept/index.ts +61 -18
- package/dev/devRunJS/index.ts +170 -0
- package/dev/devStore/index.ts +83 -0
- package/dev/index.d.ts +3 -2
- package/dev/index.js +1 -1
- package/dev/plugins/uniDevTool/uniDevTool.d.ts +2 -1
- package/dev/plugins/uniDevTool/uniDevTool.d.ts.map +1 -1
- package/dev/plugins/uniDevTool/uniDevTool.js +36 -38
- package/dev/plugins/uniGlobalComponents/uniGlobalComponents.d.ts +2 -1
- package/dev/plugins/uniGlobalComponents/uniGlobalComponents.d.ts.map +1 -1
- package/dev/plugins/uniGlobalComponents/uniGlobalComponents.js +7 -9
- package/dev/plugins/utils/index.d.ts +10 -2
- package/dev/plugins/utils/index.d.ts.map +1 -1
- package/dev/plugins/utils/index.js +1 -1
- package/dev/type.ts +58 -1
- package/dev/utils/index.ts +10 -1
- package/dev/utils/language.ts +53 -0
- package/dev/utils/object.ts +64 -1
- package/dev/utils/string.ts +5 -5
- package/package.json +2 -2
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="dev-tool-title" :style="style"> <slot /> </view>
|
|
3
|
+
</template>
|
|
4
|
+
<script lang="ts" setup>
|
|
5
|
+
defineProps<{ style?: any }>();
|
|
6
|
+
</script>
|
|
7
|
+
<style scoped>
|
|
8
|
+
.dev-tool-title {
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
height: 32px;
|
|
12
|
+
}
|
|
13
|
+
.dev-tool-title::before {
|
|
14
|
+
content: '';
|
|
15
|
+
margin-right: 8px;
|
|
16
|
+
width: 2px;
|
|
17
|
+
height: 18px;
|
|
18
|
+
border-radius: 2px;
|
|
19
|
+
background-color: var(--dev-tool-main-color);
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
v-model="searchConsole"
|
|
28
28
|
@choose="onConsoleChoose"
|
|
29
29
|
@search="onSearchConsole"
|
|
30
|
+
@run="onRunJS"
|
|
30
31
|
/>
|
|
31
32
|
<NetworkList
|
|
32
33
|
:currentNetworkType="currentNetworkType"
|
|
@@ -64,6 +65,15 @@
|
|
|
64
65
|
@search="onSearchRoute"
|
|
65
66
|
@routeRefresh="onRouteRefresh"
|
|
66
67
|
/>
|
|
68
|
+
<UniEvent
|
|
69
|
+
v-if="activeTab === 'UniEvent'"
|
|
70
|
+
:eventList="eventList"
|
|
71
|
+
:eventCount="eventCount"
|
|
72
|
+
:mode="mode"
|
|
73
|
+
:useDevSource="useDevSource"
|
|
74
|
+
:sourceFileServers="sourceFileServers"
|
|
75
|
+
@clear="onUniEventClear"
|
|
76
|
+
/>
|
|
67
77
|
<SettingList
|
|
68
78
|
v-if="activeTab === 'Setting'"
|
|
69
79
|
:devToolVisible="devToolVisible"
|
|
@@ -119,6 +129,8 @@ import DeviceInfo from '../DeviceInfo/index.vue';
|
|
|
119
129
|
import WindowInfo from '../WindowInfo/index.vue';
|
|
120
130
|
import WebSocket from '../WebSocket/index.vue';
|
|
121
131
|
import UploadList from '../UploadList/index.vue';
|
|
132
|
+
import UniEvent from '../UniEvent/index.vue';
|
|
133
|
+
import RunJS from '../RunJS/index.vue';
|
|
122
134
|
import {
|
|
123
135
|
DEV_BUTTON_SHOW_OR_HIDE,
|
|
124
136
|
DEV_CONSOLE_CLEAR,
|
|
@@ -141,9 +153,13 @@ import {
|
|
|
141
153
|
DEV_WEBSOCKET_CLEAR,
|
|
142
154
|
DEV_WINDOW_INFO,
|
|
143
155
|
DEV_APP_MESSAGE,
|
|
156
|
+
DEV_UNI_EVENT_CLEAR,
|
|
157
|
+
DEV_RUN_JS_CLEAR,
|
|
158
|
+
DEV_RUN_JS,
|
|
144
159
|
} from '../../const';
|
|
145
160
|
import { debounce, hightLight } from '../../utils/index';
|
|
146
161
|
import type { DevTool } from '../../type';
|
|
162
|
+
import { eventBus } from '../../core';
|
|
147
163
|
|
|
148
164
|
const items = [
|
|
149
165
|
{
|
|
@@ -171,12 +187,16 @@ const items = [
|
|
|
171
187
|
label: 'WebSocket',
|
|
172
188
|
value: 'WebSocket',
|
|
173
189
|
},
|
|
174
|
-
|
|
175
190
|
{
|
|
176
191
|
key: 'Route',
|
|
177
192
|
label: 'Route',
|
|
178
193
|
value: 'Route',
|
|
179
194
|
},
|
|
195
|
+
{
|
|
196
|
+
key: 'UniEvent',
|
|
197
|
+
label: 'UniEvent',
|
|
198
|
+
value: 'UniEvent',
|
|
199
|
+
},
|
|
180
200
|
{
|
|
181
201
|
key: 'Storage',
|
|
182
202
|
label: 'Storage',
|
|
@@ -222,6 +242,8 @@ const backup: {
|
|
|
222
242
|
wsList: DevTool.WS[];
|
|
223
243
|
uploadList: DevTool.UploadItem[];
|
|
224
244
|
routeList: DevTool.Page[];
|
|
245
|
+
eventList: DevTool.EventItem[];
|
|
246
|
+
runJSList: DevTool.RunJSItem[];
|
|
225
247
|
} = {
|
|
226
248
|
consoleList: [],
|
|
227
249
|
networkList: [],
|
|
@@ -229,6 +251,8 @@ const backup: {
|
|
|
229
251
|
wsList: [],
|
|
230
252
|
uploadList: [],
|
|
231
253
|
routeList: [],
|
|
254
|
+
eventList: [],
|
|
255
|
+
runJSList: [],
|
|
232
256
|
};
|
|
233
257
|
const consoleList = ref<DevTool.ConsoleItem[]>([]);
|
|
234
258
|
const networkList = ref<DevTool.NetworkItem[]>([]);
|
|
@@ -241,6 +265,9 @@ const piniaList = ref<Record<string, any>>({});
|
|
|
241
265
|
const systemInfo = ref<Record<string, any>>({});
|
|
242
266
|
const deviceInfo = ref<Record<string, any>>({});
|
|
243
267
|
const windowInfo = ref<Record<string, any>>({});
|
|
268
|
+
const eventList = ref<DevTool.EventItem[]>([]);
|
|
269
|
+
const eventCount = ref<DevTool.EventCount>();
|
|
270
|
+
|
|
244
271
|
const netWorkStatus = ref<{
|
|
245
272
|
isConnected?: boolean;
|
|
246
273
|
networkType?: string;
|
|
@@ -292,7 +319,7 @@ const listenPostMessage = (data: DevTool.WindowData) => {
|
|
|
292
319
|
})
|
|
293
320
|
.filter((item) => {
|
|
294
321
|
return (
|
|
295
|
-
item.args
|
|
322
|
+
item.args?.some((arg) => arg?.includes?.(searchConsole.value)) ||
|
|
296
323
|
item.position.includes(searchConsole.value) ||
|
|
297
324
|
item?.stack?.includes(searchConsole.value)
|
|
298
325
|
);
|
|
@@ -394,6 +421,13 @@ const listenPostMessage = (data: DevTool.WindowData) => {
|
|
|
394
421
|
});
|
|
395
422
|
backup.routeList = [...data.routeList];
|
|
396
423
|
}
|
|
424
|
+
if (data.eventList) {
|
|
425
|
+
eventList.value = [...data.eventList];
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (data.eventCount) {
|
|
429
|
+
eventCount.value = { ...data.eventCount };
|
|
430
|
+
}
|
|
397
431
|
|
|
398
432
|
if (data.vuexList) {
|
|
399
433
|
vuexList.value = data.vuexList;
|
|
@@ -439,11 +473,11 @@ onMounted(() => {
|
|
|
439
473
|
|
|
440
474
|
onLoad(() => {
|
|
441
475
|
isActive = true;
|
|
442
|
-
|
|
476
|
+
eventBus.on(DEV_APP_MESSAGE, listenPostMessage);
|
|
443
477
|
});
|
|
444
478
|
onUnload(() => {
|
|
445
479
|
isActive = false;
|
|
446
|
-
|
|
480
|
+
eventBus.off(DEV_APP_MESSAGE, listenPostMessage);
|
|
447
481
|
});
|
|
448
482
|
|
|
449
483
|
onShow(() => {
|
|
@@ -509,6 +543,15 @@ function onConsoleChoose(
|
|
|
509
543
|
setWindowInfo();
|
|
510
544
|
}
|
|
511
545
|
|
|
546
|
+
function onRunJS(code: string) {
|
|
547
|
+
basicSendMessage({
|
|
548
|
+
type: DEV_RUN_JS,
|
|
549
|
+
data: {
|
|
550
|
+
code,
|
|
551
|
+
},
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
|
|
512
555
|
function onSearchConsole(value: string) {
|
|
513
556
|
consoleList.value = backup.consoleList
|
|
514
557
|
.filter((item) => {
|
|
@@ -704,6 +747,20 @@ function onSearchStorage(value: string) {
|
|
|
704
747
|
});
|
|
705
748
|
}
|
|
706
749
|
|
|
750
|
+
function onUniEventClear() {
|
|
751
|
+
eventList.value = [];
|
|
752
|
+
eventCount.value = {
|
|
753
|
+
on: 0,
|
|
754
|
+
once: 0,
|
|
755
|
+
emit: 0,
|
|
756
|
+
off: 0,
|
|
757
|
+
};
|
|
758
|
+
basicSendMessage({
|
|
759
|
+
type: DEV_UNI_EVENT_CLEAR,
|
|
760
|
+
data: {},
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
|
|
707
764
|
function onGoTo(page: DevTool.Page) {
|
|
708
765
|
basicSendMessage({
|
|
709
766
|
type: DEV_PAGE_JUMP,
|
|
@@ -810,7 +867,7 @@ function onChangePinia(value: Record<string, any>) {
|
|
|
810
867
|
position: fixed;
|
|
811
868
|
top: 0;
|
|
812
869
|
left: 0;
|
|
813
|
-
z-index:
|
|
870
|
+
z-index: 1000;
|
|
814
871
|
/* #ifdef H5 */
|
|
815
872
|
padding: 50px 0;
|
|
816
873
|
/* #endif */
|
|
@@ -3,18 +3,34 @@
|
|
|
3
3
|
:class="`json-pretty-check-controller ${model ? 'is-checked' : ''}`"
|
|
4
4
|
@click="onClick"
|
|
5
5
|
>
|
|
6
|
-
<view
|
|
6
|
+
<!-- <view
|
|
7
|
+
:class="`json-pretty-check-controller-inner is-${uiType}`"
|
|
8
|
+
@click="onChange"
|
|
9
|
+
>
|
|
10
|
+
</view>
|
|
7
11
|
<input
|
|
8
12
|
:checked="model"
|
|
9
13
|
:class="`json-pretty-check-controller-original is-${uiType}`"
|
|
10
14
|
:type="uiType"
|
|
11
15
|
@change="onChange"
|
|
16
|
+
/> -->
|
|
17
|
+
|
|
18
|
+
<checkbox
|
|
19
|
+
v-if="uiType === 'checkbox'"
|
|
20
|
+
:checked="model"
|
|
21
|
+
style="transform: scale(0.6)"
|
|
22
|
+
@change="onChange"
|
|
23
|
+
/>
|
|
24
|
+
<radio
|
|
25
|
+
v-if="uiType === 'radio'"
|
|
26
|
+
:checked="model"
|
|
27
|
+
style="transform: scale(0.6)"
|
|
28
|
+
@change="onChange"
|
|
12
29
|
/>
|
|
13
30
|
</view>
|
|
14
31
|
</template>
|
|
15
32
|
<script lang="ts" setup>
|
|
16
33
|
import { computed } from 'vue';
|
|
17
|
-
// import "./style.less";
|
|
18
34
|
const props = defineProps<{ checked: boolean; isMultiple: boolean }>();
|
|
19
35
|
const emit = defineEmits<{
|
|
20
36
|
(e: 'change', value: boolean): void;
|
|
@@ -24,11 +40,11 @@ const emit = defineEmits<{
|
|
|
24
40
|
const uiType = computed(() => (props.isMultiple ? 'checkbox' : 'radio'));
|
|
25
41
|
const model = computed({
|
|
26
42
|
get: (): boolean => props.checked,
|
|
27
|
-
set: (val) => emit('update:modelValue', val)
|
|
43
|
+
set: (val) => emit('update:modelValue', val),
|
|
28
44
|
});
|
|
29
45
|
|
|
30
46
|
function onChange() {
|
|
31
|
-
emit('change', model.value);
|
|
47
|
+
emit('change', !model.value);
|
|
32
48
|
}
|
|
33
49
|
|
|
34
50
|
function onClick(e: MouseEvent) {
|
|
@@ -65,7 +81,8 @@ function onClick(e: MouseEvent) {
|
|
|
65
81
|
background-color: #fff;
|
|
66
82
|
z-index: 1;
|
|
67
83
|
cursor: pointer;
|
|
68
|
-
transition:
|
|
84
|
+
transition:
|
|
85
|
+
border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46),
|
|
69
86
|
background-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);
|
|
70
87
|
}
|
|
71
88
|
.json-pretty-check-controller .json-pretty-check-controller-inner:after {
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
@mouseover="handleNodeMouseover"
|
|
13
13
|
:style="style"
|
|
14
14
|
>
|
|
15
|
-
<view v-if="showLineNumber" class="json-pretty-node-index">
|
|
16
|
-
node.id + 1
|
|
17
|
-
|
|
15
|
+
<view v-if="showLineNumber" class="json-pretty-node-index">
|
|
16
|
+
{{ node.id + 1 }}
|
|
17
|
+
</view>
|
|
18
18
|
|
|
19
19
|
<CheckController
|
|
20
20
|
v-if="
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
<slot name="render-node-key" :node="props.node" :default-key="prettyKey">
|
|
47
47
|
{{ prettyKey }}
|
|
48
48
|
</slot>
|
|
49
|
-
<view class="json-pretty-colon">
|
|
50
|
-
`:${showKeyValueSpace ? ' ' : ''}`
|
|
51
|
-
|
|
49
|
+
<view class="json-pretty-colon">
|
|
50
|
+
{{ `:${showKeyValueSpace ? ' ' : ''}` }}
|
|
51
|
+
</view>
|
|
52
52
|
</view>
|
|
53
53
|
|
|
54
54
|
<view class="json-pretty-value-wrapper">
|
|
@@ -74,20 +74,19 @@
|
|
|
74
74
|
>
|
|
75
75
|
{{ defaultValue }}
|
|
76
76
|
</slot>
|
|
77
|
+
<text v-if="node.showComma">,</text>
|
|
77
78
|
</view>
|
|
78
79
|
</view>
|
|
79
80
|
|
|
80
|
-
<view v-if="node.showComma">,</view>
|
|
81
|
-
|
|
82
81
|
<view v-if="showLength && collapsed" class="json-pretty-comment">
|
|
83
82
|
// {{ node.length }} items
|
|
84
83
|
</view>
|
|
85
84
|
</view>
|
|
86
85
|
<view class="json-pretty-tree-node-actions" v-if="showNodeActions">
|
|
87
86
|
<slot name="render-node-actions" :copy="handleCopy">
|
|
88
|
-
<view @click="handleCopy" class="json-pretty-tree-node-actions-item"
|
|
89
|
-
|
|
90
|
-
>
|
|
87
|
+
<view @click="handleCopy" class="json-pretty-tree-node-actions-item">
|
|
88
|
+
copy
|
|
89
|
+
</view>
|
|
91
90
|
</slot>
|
|
92
91
|
</view>
|
|
93
92
|
</view>
|
|
@@ -165,7 +164,7 @@ const defaultValue = computed(() => {
|
|
|
165
164
|
} else if (value === undefined) {
|
|
166
165
|
value = 'undefined';
|
|
167
166
|
}
|
|
168
|
-
return dataType.value === 'string' ? `"${value}"` : value
|
|
167
|
+
return dataType.value === 'string' ? `"${value}"` : value?.toString();
|
|
169
168
|
});
|
|
170
169
|
|
|
171
170
|
const handleBracketsClick = () => {
|
|
@@ -231,7 +230,7 @@ const handleCopy = () => {
|
|
|
231
230
|
<style scoped>
|
|
232
231
|
.json-pretty-tree-node {
|
|
233
232
|
display: flex;
|
|
234
|
-
align-items: center;
|
|
233
|
+
/* align-items: center; */
|
|
235
234
|
position: relative;
|
|
236
235
|
line-height: 20px;
|
|
237
236
|
}
|
|
@@ -314,8 +313,10 @@ const handleCopy = () => {
|
|
|
314
313
|
align-items: center;
|
|
315
314
|
}
|
|
316
315
|
.json-pretty-value {
|
|
317
|
-
|
|
318
|
-
white-space:
|
|
316
|
+
word-break: break-all;
|
|
317
|
+
white-space: normal;
|
|
318
|
+
/* white-space: pre-line; */
|
|
319
|
+
/* white-space: nowrap; */
|
|
319
320
|
}
|
|
320
321
|
.json-pretty-value-null {
|
|
321
322
|
color: var(--json-pretty-color-null);
|
|
@@ -16,62 +16,51 @@
|
|
|
16
16
|
: style
|
|
17
17
|
"
|
|
18
18
|
>
|
|
19
|
-
<
|
|
20
|
-
v-if="
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
:style="{ height: `${height}px` }"
|
|
25
|
-
@scroll="handleTreeScroll"
|
|
26
|
-
ref="treeRef"
|
|
19
|
+
<VirtualList
|
|
20
|
+
v-if="autoVirtual"
|
|
21
|
+
:height="state.height"
|
|
22
|
+
:itemHeight="itemHeight"
|
|
23
|
+
:data="flatData"
|
|
27
24
|
>
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
itemHeight && itemHeight !== 20
|
|
68
|
-
? { lineHeight: `${itemHeight}px` }
|
|
69
|
-
: {}
|
|
70
|
-
"
|
|
71
|
-
/>
|
|
72
|
-
</view>
|
|
73
|
-
</view>
|
|
74
|
-
</scroll-view>
|
|
25
|
+
<template v-slot="{ list }">
|
|
26
|
+
<TreeNode
|
|
27
|
+
v-for="item in list"
|
|
28
|
+
:key="item.id"
|
|
29
|
+
:data="data"
|
|
30
|
+
:rootPath="rootPath"
|
|
31
|
+
:indent="indent"
|
|
32
|
+
:node="item"
|
|
33
|
+
:collapsed="!!state.hiddenPaths[item.path]"
|
|
34
|
+
:theme="theme"
|
|
35
|
+
:showDoubleQuotes="showDoubleQuotes"
|
|
36
|
+
:showLength="showLength"
|
|
37
|
+
:checked="selectedPaths.includes(item.path)"
|
|
38
|
+
:selectableType="selectableType"
|
|
39
|
+
:showLine="showLine"
|
|
40
|
+
:showLineNumber="showLineNumber"
|
|
41
|
+
:showSelectController="showSelectController"
|
|
42
|
+
:selectOnClickNode="selectOnClickNode"
|
|
43
|
+
:nodeSelectable="nodeSelectable"
|
|
44
|
+
:highlightSelectedNode="highlightSelectedNode"
|
|
45
|
+
:editable="editable"
|
|
46
|
+
:editableTrigger="editableTrigger"
|
|
47
|
+
:showIcon="showIcon"
|
|
48
|
+
:showKeyValueSpace="showKeyValueSpace"
|
|
49
|
+
:showNodeActions="showNodeActions"
|
|
50
|
+
@nodeClick="handleNodeClick"
|
|
51
|
+
@nodeMouseover="handleNodeMouseover"
|
|
52
|
+
@bracketsClick="handleBracketsClick"
|
|
53
|
+
@iconClick="handleIconClick"
|
|
54
|
+
@selectedChange="handleSelectedChange"
|
|
55
|
+
@valueChange="handleValueChange"
|
|
56
|
+
:style="
|
|
57
|
+
itemHeight && itemHeight !== 20
|
|
58
|
+
? { lineHeight: `${itemHeight}px` }
|
|
59
|
+
: {}
|
|
60
|
+
"
|
|
61
|
+
/>
|
|
62
|
+
</template>
|
|
63
|
+
</VirtualList>
|
|
75
64
|
<template v-else>
|
|
76
65
|
<TreeNode
|
|
77
66
|
v-for="item in state?.visibleData"
|
|
@@ -115,7 +104,6 @@
|
|
|
115
104
|
|
|
116
105
|
<script setup lang="ts">
|
|
117
106
|
import {
|
|
118
|
-
ref,
|
|
119
107
|
reactive,
|
|
120
108
|
computed,
|
|
121
109
|
watchEffect,
|
|
@@ -127,6 +115,8 @@ import {
|
|
|
127
115
|
} from 'vue';
|
|
128
116
|
import TreeNode from './components/TreeNode/index.vue';
|
|
129
117
|
|
|
118
|
+
import VirtualList from '../VirtualList/index.vue';
|
|
119
|
+
|
|
130
120
|
import { emitError, jsonFlatten, cloneDeep, isFunction } from './utils';
|
|
131
121
|
|
|
132
122
|
import type { NodeDataType, ScrollEvent, Tree } from './type';
|
|
@@ -170,9 +160,6 @@ const props = withDefaults(defineProps<Tree>(), {
|
|
|
170
160
|
});
|
|
171
161
|
const emits = defineEmits<Emits>();
|
|
172
162
|
|
|
173
|
-
// 初始化数据
|
|
174
|
-
const treeRef = ref<HTMLElement | null>(null);
|
|
175
|
-
|
|
176
163
|
const originFlatData = computed(() => jsonFlatten(props.data, props.rootPath));
|
|
177
164
|
|
|
178
165
|
// 初始化折叠路径
|
|
@@ -203,12 +190,14 @@ interface State {
|
|
|
203
190
|
translateY: number;
|
|
204
191
|
visibleData: NodeDataType[] | null;
|
|
205
192
|
hiddenPaths: Record<string, 1>;
|
|
193
|
+
height: number;
|
|
206
194
|
}
|
|
207
195
|
|
|
208
196
|
const state = reactive<State>({
|
|
209
197
|
translateY: 0,
|
|
210
198
|
visibleData: [],
|
|
211
199
|
hiddenPaths: initHiddenPaths(props.deep, props.collapsedNodeLength),
|
|
200
|
+
height: props.height ?? 400,
|
|
212
201
|
});
|
|
213
202
|
|
|
214
203
|
// 计算属性
|
|
@@ -263,12 +252,22 @@ const propsErrorMessage = computed(() => {
|
|
|
263
252
|
: '';
|
|
264
253
|
});
|
|
265
254
|
|
|
255
|
+
const autoVirtual = computed(() => {
|
|
256
|
+
if (props.virtual) return true;
|
|
257
|
+
if (typeof props.autoVirtualRow === 'number') {
|
|
258
|
+
if (flatData.value.length > props.autoVirtualRow) {
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return false;
|
|
263
|
+
});
|
|
264
|
+
|
|
266
265
|
// 更新可见数据
|
|
266
|
+
// 优化 虚拟列表,每项高度自适应
|
|
267
267
|
const updateVisibleData = (scrollTop: number = 0) => {
|
|
268
268
|
const flatDataValue = flatData.value ?? [];
|
|
269
|
-
if (
|
|
269
|
+
if (autoVirtual.value) {
|
|
270
270
|
const visibleCount = props.height / props.itemHeight;
|
|
271
|
-
// const scrollTop = treeRef.value?.scrollTop || 0;
|
|
272
271
|
const scrollCount = Math.floor(scrollTop / props.itemHeight);
|
|
273
272
|
let start =
|
|
274
273
|
scrollCount < 0
|
|
@@ -336,6 +335,10 @@ const updateCollapsedPaths = (collapsed: boolean, path: string) => {
|
|
|
336
335
|
delete newPaths[path];
|
|
337
336
|
state.hiddenPaths = newPaths;
|
|
338
337
|
}
|
|
338
|
+
|
|
339
|
+
if (path === props.rootPath) {
|
|
340
|
+
state.height = collapsed ? props.itemHeight : props.height;
|
|
341
|
+
}
|
|
339
342
|
};
|
|
340
343
|
|
|
341
344
|
const handleBracketsClick = (collapsed: boolean, node: NodeDataType) => {
|
|
@@ -386,6 +389,19 @@ watch(
|
|
|
386
389
|
},
|
|
387
390
|
);
|
|
388
391
|
|
|
392
|
+
// 监听是否折叠,默认不折叠
|
|
393
|
+
watch(
|
|
394
|
+
() => props.collapsed,
|
|
395
|
+
(val) => {
|
|
396
|
+
if (val) {
|
|
397
|
+
updateCollapsedPaths(true, props.rootPath);
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
immediate: true,
|
|
402
|
+
},
|
|
403
|
+
);
|
|
404
|
+
|
|
389
405
|
// 生命周期钩子
|
|
390
406
|
onMounted(() => {
|
|
391
407
|
updateVisibleData();
|
|
@@ -443,20 +459,6 @@ onUnmounted(() => {
|
|
|
443
459
|
white-space: nowrap;
|
|
444
460
|
}
|
|
445
461
|
|
|
446
|
-
.json-pretty-tree-list {
|
|
447
|
-
overflow: auto;
|
|
448
|
-
position: relative;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
.json-pretty-tree-list-holder {
|
|
452
|
-
position: relative;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
.json-pretty-tree-list-holder-inner {
|
|
456
|
-
position: absolute;
|
|
457
|
-
width: 100%;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
462
|
.dark {
|
|
461
463
|
/* 深色主题样式 */
|
|
462
464
|
}
|