vite-uni-dev-tool 0.0.13 → 0.0.14
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/dist/v2/AppInfo/index.vue +41 -0
- package/dist/v2/AutoSizer/index.vue +189 -0
- package/dist/v2/AutoSizer/index1.vue +193 -0
- package/dist/v2/AutoSizer/utils.ts +49 -0
- package/dist/v2/CaptureScreen/index.vue +78 -0
- package/dist/v2/CloseButton/index.vue +32 -0
- package/dist/v2/Connection/index.vue +94 -0
- package/dist/v2/ConsoleList/ConsoleItem.vue +235 -0
- package/dist/v2/ConsoleList/RunJSInput.vue +243 -0
- package/dist/v2/ConsoleList/index.vue +164 -0
- package/dist/v2/ConsoleList/staticTips.js +1144 -0
- package/dist/v2/DevTool/index.vue +162 -0
- package/dist/v2/DevToolButton/index.vue +228 -0
- package/dist/v2/DevToolTitle/index.vue +28 -0
- package/dist/v2/DevToolWindow/index.vue +1051 -0
- package/dist/v2/DeviceInfo/index.vue +48 -0
- package/dist/v2/Empty/empty.png +0 -0
- package/dist/v2/Empty/index.vue +40 -0
- package/dist/v2/FilterInput/index.vue +100 -0
- package/dist/v2/JsonPretty/components/Brackets/index.vue +30 -0
- package/dist/v2/JsonPretty/components/Carets/index.vue +65 -0
- package/dist/v2/JsonPretty/components/CheckController/index.vue +127 -0
- package/dist/v2/JsonPretty/components/TreeNode/index.vue +417 -0
- package/dist/v2/JsonPretty/hooks/useClipboard.ts +21 -0
- package/dist/v2/JsonPretty/hooks/useError.ts +21 -0
- package/dist/v2/JsonPretty/index.vue +531 -0
- package/dist/v2/JsonPretty/type.ts +125 -0
- package/dist/v2/JsonPretty/utils/index.js +211 -0
- package/dist/v2/NetworkList/NetworkDetail.vue +215 -0
- package/dist/v2/NetworkList/NetworkItem.vue +135 -0
- package/dist/v2/NetworkList/index.vue +148 -0
- package/dist/v2/PiniaList/index.vue +79 -0
- package/dist/v2/RouteList/index.vue +137 -0
- package/dist/v2/RunJS/index.vue +128 -0
- package/dist/v2/SettingList/index.vue +318 -0
- package/dist/v2/SourceCode/index.vue +237 -0
- package/dist/v2/StorageList/index.vue +165 -0
- package/dist/v2/SystemInfo/index.vue +49 -0
- package/dist/v2/Tabs/index.vue +127 -0
- package/dist/v2/Tag/index.vue +91 -0
- package/dist/v2/UniEvent/UniEventItem.vue +157 -0
- package/dist/v2/UniEvent/index.vue +127 -0
- package/dist/v2/UploadList/UploadDetail.vue +204 -0
- package/dist/v2/UploadList/UploadItem.vue +134 -0
- package/dist/v2/UploadList/index.vue +143 -0
- package/dist/v2/VirtualList/index.vue +140 -0
- package/dist/v2/VirtualListPro/AutoSize.vue +50 -0
- package/dist/v2/VirtualListPro/index.vue +255 -0
- package/dist/v2/VirtualListPro/readme.md +40 -0
- package/dist/v2/VuexList/index.vue +80 -0
- package/dist/v2/WebSocket/WebSocketItem.vue +129 -0
- package/dist/v2/WebSocket/WebSocketList.vue +183 -0
- package/dist/v2/WebSocket/index.vue +155 -0
- package/dist/v2/WindowInfo/index.vue +49 -0
- package/dist/v3/AppInfo/index.vue +35 -0
- package/dist/v3/AutoSizer/index.vue +193 -0
- package/dist/v3/AutoSizer/index1.vue +186 -0
- package/dist/v3/AutoSizer/utils.ts +49 -0
- package/dist/v3/CaptureScreen/index.vue +62 -0
- package/dist/v3/CloseButton/index.vue +29 -0
- package/dist/v3/Connection/index.vue +88 -0
- package/dist/v3/ConsoleList/ConsoleItem.vue +208 -0
- package/dist/v3/ConsoleList/RunJSInput.vue +240 -0
- package/dist/v3/ConsoleList/index.vue +139 -0
- package/dist/v3/ConsoleList/staticTips.ts +1145 -0
- package/dist/v3/DevTool/index.vue +217 -0
- package/dist/v3/DevToolButton/index.vue +210 -0
- package/dist/v3/DevToolTitle/index.vue +21 -0
- package/dist/v3/DevToolWindow/index.vue +1116 -0
- package/dist/v3/DeviceInfo/index.vue +32 -0
- package/dist/v3/Empty/empty.png +0 -0
- package/dist/v3/Empty/index.vue +28 -0
- package/dist/v3/FilterInput/index.vue +87 -0
- package/dist/v3/JsonPretty/components/Brackets/index.vue +23 -0
- package/dist/v3/JsonPretty/components/Carets/index.vue +59 -0
- package/dist/v3/JsonPretty/components/CheckController/index.vue +125 -0
- package/dist/v3/JsonPretty/components/TreeNode/index.vue +349 -0
- package/dist/v3/JsonPretty/hooks/useClipboard.ts +21 -0
- package/dist/v3/JsonPretty/hooks/useError.ts +21 -0
- package/dist/v3/JsonPretty/index.vue +476 -0
- package/dist/v3/JsonPretty/type.ts +125 -0
- package/dist/v3/JsonPretty/utils/index.ts +172 -0
- package/dist/v3/NetworkList/NetworkDetail.vue +194 -0
- package/dist/v3/NetworkList/NetworkItem.vue +120 -0
- package/dist/v3/NetworkList/index.vue +128 -0
- package/dist/v3/PiniaList/index.vue +64 -0
- package/dist/v3/RouteList/index.vue +121 -0
- package/dist/v3/RunJS/index.vue +128 -0
- package/dist/v3/SettingList/index.vue +313 -0
- package/dist/v3/SourceCode/index.vue +231 -0
- package/dist/v3/StorageList/index.vue +170 -0
- package/dist/v3/SystemInfo/index.vue +34 -0
- package/dist/v3/Tabs/index.vue +123 -0
- package/dist/v3/Tag/index.vue +89 -0
- package/dist/v3/UniEvent/UniEventItem.vue +126 -0
- package/dist/v3/UniEvent/index.vue +98 -0
- package/dist/v3/UploadList/UploadDetail.vue +192 -0
- package/dist/v3/UploadList/UploadItem.vue +117 -0
- package/dist/v3/UploadList/index.vue +117 -0
- package/dist/v3/VirtualList/index.vue +112 -0
- package/dist/v3/VirtualListPro/AutoSize.vue +43 -0
- package/dist/v3/VirtualListPro/index.vue +238 -0
- package/dist/v3/VirtualListPro/readme.md +40 -0
- package/dist/v3/VuexList/index.vue +54 -0
- package/dist/v3/WebSocket/WebSocketItem.vue +103 -0
- package/dist/v3/WebSocket/WebSocketList.vue +161 -0
- package/dist/v3/WebSocket/index.vue +124 -0
- package/dist/v3/WindowInfo/index.vue +33 -0
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
|
|
3
|
+
export function useClipboard() {
|
|
4
|
+
const copied = ref(false);
|
|
5
|
+
|
|
6
|
+
const copy = async (source: string) => {
|
|
7
|
+
try {
|
|
8
|
+
await navigator.clipboard.writeText(source);
|
|
9
|
+
copied.value = true;
|
|
10
|
+
setTimeout(() => {
|
|
11
|
+
copied.value = false;
|
|
12
|
+
}, 300);
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.error("[json-pretty] Copy failed: ", err);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
copy
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { watchEffect } from "vue";
|
|
2
|
+
|
|
3
|
+
type UseErrorOptions = {
|
|
4
|
+
emitListener: boolean;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export function useError(message: string, { emitListener }: UseErrorOptions) {
|
|
8
|
+
const emit = () => {
|
|
9
|
+
throw new Error(`[VueJsonPretty] ${message}`);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
watchEffect(() => {
|
|
13
|
+
if (emitListener) {
|
|
14
|
+
emit();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
emit
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
:class="{
|
|
4
|
+
'json-pretty-tree': true,
|
|
5
|
+
'is-virtual': virtual,
|
|
6
|
+
dark: theme === 'dark',
|
|
7
|
+
}"
|
|
8
|
+
:style="
|
|
9
|
+
showLineNumber
|
|
10
|
+
? {
|
|
11
|
+
paddingLeft: `${
|
|
12
|
+
Number(originFlatData.length.toString().length) * 12
|
|
13
|
+
}px`,
|
|
14
|
+
...style,
|
|
15
|
+
}
|
|
16
|
+
: style
|
|
17
|
+
"
|
|
18
|
+
>
|
|
19
|
+
<VirtualListPro
|
|
20
|
+
v-if="autoVirtual"
|
|
21
|
+
:height="state.height"
|
|
22
|
+
:pageSize="pageSize"
|
|
23
|
+
:data="flatData"
|
|
24
|
+
scroll-with-animation
|
|
25
|
+
showBackTop
|
|
26
|
+
>
|
|
27
|
+
<template v-slot="{ list, start }">
|
|
28
|
+
<AutoSize
|
|
29
|
+
v-for="(item, index) in list"
|
|
30
|
+
:index="start + index"
|
|
31
|
+
:key="start + index"
|
|
32
|
+
>
|
|
33
|
+
<TreeNode
|
|
34
|
+
:data="data"
|
|
35
|
+
:rootPath="rootPath"
|
|
36
|
+
:indent="indent"
|
|
37
|
+
:node="item"
|
|
38
|
+
:collapsed="!!state.hiddenPaths[item.path]"
|
|
39
|
+
:theme="theme"
|
|
40
|
+
:showDoubleQuotes="showDoubleQuotes"
|
|
41
|
+
:showLength="showLength"
|
|
42
|
+
:checked="selectedPaths.includes(item.path)"
|
|
43
|
+
:selectableType="selectableType"
|
|
44
|
+
:showLine="showLine"
|
|
45
|
+
:showLineNumber="showLineNumber"
|
|
46
|
+
:showSelectController="showSelectController"
|
|
47
|
+
:selectOnClickNode="selectOnClickNode"
|
|
48
|
+
:nodeSelectable="nodeSelectable"
|
|
49
|
+
:highlightSelectedNode="highlightSelectedNode"
|
|
50
|
+
:editable="editable"
|
|
51
|
+
:editableTrigger="editableTrigger"
|
|
52
|
+
:showIcon="showIcon"
|
|
53
|
+
:showKeyValueSpace="showKeyValueSpace"
|
|
54
|
+
:showNodeActions="showNodeActions"
|
|
55
|
+
@nodeClick="handleNodeClick"
|
|
56
|
+
@nodeMouseover="handleNodeMouseover"
|
|
57
|
+
@bracketsClick="handleBracketsClick"
|
|
58
|
+
@iconClick="handleIconClick"
|
|
59
|
+
@selectedChange="handleSelectedChange"
|
|
60
|
+
@valueChange="handleValueChange"
|
|
61
|
+
:style="
|
|
62
|
+
itemHeight && itemHeight !== 20
|
|
63
|
+
? { lineHeight: `${itemHeight}px` }
|
|
64
|
+
: {}
|
|
65
|
+
"
|
|
66
|
+
/>
|
|
67
|
+
</AutoSize>
|
|
68
|
+
</template>
|
|
69
|
+
</VirtualListPro>
|
|
70
|
+
<template v-else>
|
|
71
|
+
<TreeNode
|
|
72
|
+
v-for="item in flatData"
|
|
73
|
+
:key="item.id"
|
|
74
|
+
:data="data"
|
|
75
|
+
:rootPath="rootPath"
|
|
76
|
+
:indent="indent"
|
|
77
|
+
:node="item"
|
|
78
|
+
:collapsed="!!state.hiddenPaths[item.path]"
|
|
79
|
+
:theme="theme"
|
|
80
|
+
:showDoubleQuotes="showDoubleQuotes"
|
|
81
|
+
:showLength="showLength"
|
|
82
|
+
:checked="selectedPaths.includes(item.path)"
|
|
83
|
+
:selectableType="selectableType"
|
|
84
|
+
:showLine="showLine"
|
|
85
|
+
:showLineNumber="showLineNumber"
|
|
86
|
+
:showSelectController="showSelectController"
|
|
87
|
+
:selectOnClickNode="selectOnClickNode"
|
|
88
|
+
:nodeSelectable="nodeSelectable"
|
|
89
|
+
:highlightSelectedNode="highlightSelectedNode"
|
|
90
|
+
:editable="editable"
|
|
91
|
+
:editableTrigger="editableTrigger"
|
|
92
|
+
:showIcon="showIcon"
|
|
93
|
+
:showKeyValueSpace="showKeyValueSpace"
|
|
94
|
+
:showNodeActions="showNodeActions"
|
|
95
|
+
@nodeClick="handleNodeClick"
|
|
96
|
+
@nodeMouseover="handleNodeMouseover"
|
|
97
|
+
@bracketsClick="handleBracketsClick"
|
|
98
|
+
@iconClick="handleIconClick"
|
|
99
|
+
@selectedChange="handleSelectedChange"
|
|
100
|
+
@valueChange="handleValueChange"
|
|
101
|
+
:style="
|
|
102
|
+
itemHeight && itemHeight !== 20
|
|
103
|
+
? { lineHeight: `${itemHeight}px` }
|
|
104
|
+
: {}
|
|
105
|
+
"
|
|
106
|
+
/>
|
|
107
|
+
</template>
|
|
108
|
+
</view>
|
|
109
|
+
</template>
|
|
110
|
+
|
|
111
|
+
<script setup lang="ts">
|
|
112
|
+
import {
|
|
113
|
+
reactive,
|
|
114
|
+
computed,
|
|
115
|
+
watchEffect,
|
|
116
|
+
watch,
|
|
117
|
+
defineEmits,
|
|
118
|
+
onMounted,
|
|
119
|
+
onUpdated,
|
|
120
|
+
onUnmounted,
|
|
121
|
+
} from 'vue';
|
|
122
|
+
import TreeNode from './components/TreeNode/index.vue';
|
|
123
|
+
|
|
124
|
+
import VirtualListPro from '../VirtualListPro/index.vue';
|
|
125
|
+
import AutoSize from '../VirtualListPro/AutoSize.vue';
|
|
126
|
+
|
|
127
|
+
import { emitError, jsonFlatten, cloneDeep, isFunction } from './utils';
|
|
128
|
+
|
|
129
|
+
import type { NodeDataType, ScrollEvent, Tree } from './type';
|
|
130
|
+
import { setValueByPath } from '../../utils';
|
|
131
|
+
|
|
132
|
+
// 定义 emits 类型
|
|
133
|
+
type Emits = {
|
|
134
|
+
(event: 'nodeClick', node: NodeDataType): void;
|
|
135
|
+
(event: 'nodeMouseover', node: NodeDataType): void;
|
|
136
|
+
(event: 'bracketsClick', collapsed: boolean, node: NodeDataType): void;
|
|
137
|
+
(event: 'iconClick', collapsed: boolean, node: NodeDataType): void;
|
|
138
|
+
(
|
|
139
|
+
event: 'selectedChange',
|
|
140
|
+
newVal: string | string[],
|
|
141
|
+
oldVal: string | string[],
|
|
142
|
+
): void;
|
|
143
|
+
(event: 'update:selectedValue', value: string | string[]): void;
|
|
144
|
+
(event: 'update:data', data: any): void;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// 定义 props 和 emits
|
|
148
|
+
const props = withDefaults(defineProps<Tree>(), {
|
|
149
|
+
fontSize: '12px',
|
|
150
|
+
itemHeight: 20,
|
|
151
|
+
height: 400,
|
|
152
|
+
deep: Infinity,
|
|
153
|
+
collapsedNodeLength: Infinity,
|
|
154
|
+
collapsedOnClickBrackets: true,
|
|
155
|
+
pathCollapsible: () => false,
|
|
156
|
+
nodeSelectable: () => false,
|
|
157
|
+
|
|
158
|
+
rootPath: 'root',
|
|
159
|
+
indent: 2,
|
|
160
|
+
showDoubleQuotes: true,
|
|
161
|
+
showLine: true,
|
|
162
|
+
selectOnClickNode: true,
|
|
163
|
+
highlightSelectedNode: true,
|
|
164
|
+
theme: 'light',
|
|
165
|
+
showKeyValueSpace: true,
|
|
166
|
+
editableTrigger: 'click',
|
|
167
|
+
});
|
|
168
|
+
const emits = defineEmits<Emits>();
|
|
169
|
+
|
|
170
|
+
const originFlatData = computed(() => jsonFlatten(props.data, props.rootPath));
|
|
171
|
+
|
|
172
|
+
const pageSize = computed(() => {
|
|
173
|
+
return Math.ceil(props.height / props.itemHeight) + 5;
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// 初始化折叠路径
|
|
177
|
+
const initHiddenPaths = (
|
|
178
|
+
deep: number,
|
|
179
|
+
collapsedNodeLength: number,
|
|
180
|
+
): Record<string, 1> => {
|
|
181
|
+
return originFlatData.value.reduce((acc, item) => {
|
|
182
|
+
const doCollapse = item.level >= deep || item.length >= collapsedNodeLength;
|
|
183
|
+
const pathComparison =
|
|
184
|
+
isFunction(props?.pathCollapsible) &&
|
|
185
|
+
props?.pathCollapsible?.(item as NodeDataType);
|
|
186
|
+
if (
|
|
187
|
+
(item.type === 'objectStart' || item.type === 'arrayStart') &&
|
|
188
|
+
(doCollapse || pathComparison)
|
|
189
|
+
) {
|
|
190
|
+
return {
|
|
191
|
+
...acc,
|
|
192
|
+
[item.path]: 1,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
return acc;
|
|
196
|
+
}, {});
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
// 响应式状态
|
|
200
|
+
interface State {
|
|
201
|
+
translateY: number;
|
|
202
|
+
visibleData: NodeDataType[] | null;
|
|
203
|
+
hiddenPaths: Record<string, 1>;
|
|
204
|
+
height: number;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const state = reactive<State>({
|
|
208
|
+
translateY: 0,
|
|
209
|
+
visibleData: [],
|
|
210
|
+
hiddenPaths: initHiddenPaths(props.deep, props.collapsedNodeLength),
|
|
211
|
+
height: props.height ?? 400,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// 计算属性
|
|
215
|
+
const flatData = computed(() => {
|
|
216
|
+
let startHiddenItem: null | NodeDataType = null;
|
|
217
|
+
const data: NodeDataType[] = [];
|
|
218
|
+
const length = originFlatData.value.length;
|
|
219
|
+
for (let i = 0; i < length; i++) {
|
|
220
|
+
const cur = originFlatData.value[i];
|
|
221
|
+
const item: NodeDataType = {
|
|
222
|
+
...cur,
|
|
223
|
+
id: i,
|
|
224
|
+
};
|
|
225
|
+
const isHidden = state.hiddenPaths[item.path];
|
|
226
|
+
if (startHiddenItem && startHiddenItem.path === item.path) {
|
|
227
|
+
const isObject = startHiddenItem.type === 'objectStart';
|
|
228
|
+
const mergeItem: NodeDataType = {
|
|
229
|
+
...item,
|
|
230
|
+
...startHiddenItem,
|
|
231
|
+
showComma: item.showComma,
|
|
232
|
+
content: isObject ? '{...}' : '[...]',
|
|
233
|
+
type: isObject ? 'objectCollapsed' : 'arrayCollapsed',
|
|
234
|
+
};
|
|
235
|
+
startHiddenItem = null;
|
|
236
|
+
data.push(mergeItem);
|
|
237
|
+
} else if (isHidden && !startHiddenItem) {
|
|
238
|
+
startHiddenItem = item;
|
|
239
|
+
continue;
|
|
240
|
+
} else {
|
|
241
|
+
if (startHiddenItem) continue;
|
|
242
|
+
else data.push(item);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return data;
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
const selectedPaths = computed(() => {
|
|
249
|
+
const value = props.selectedValue;
|
|
250
|
+
if (value && props.selectableType === 'multiple' && Array.isArray(value)) {
|
|
251
|
+
return value;
|
|
252
|
+
}
|
|
253
|
+
return [value];
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
const propsErrorMessage = computed(() => {
|
|
257
|
+
const error =
|
|
258
|
+
props.selectableType &&
|
|
259
|
+
!props.selectOnClickNode &&
|
|
260
|
+
!props.showSelectController;
|
|
261
|
+
return error
|
|
262
|
+
? 'When selectableType is not null, selectOnClickNode and showSelectController cannot be false at the same time, because this will cause the selection to fail.'
|
|
263
|
+
: '';
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
const autoVirtual = computed(() => {
|
|
267
|
+
if (props.virtual) return true;
|
|
268
|
+
if (typeof props.autoVirtualRow === 'number') {
|
|
269
|
+
if (flatData.value.length > props.autoVirtualRow) {
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return false;
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
// 更新可见数据
|
|
277
|
+
// 优化 虚拟列表,每项高度自适应
|
|
278
|
+
const updateVisibleData = (scrollTop: number = 0) => {
|
|
279
|
+
const flatDataValue = flatData.value ?? [];
|
|
280
|
+
if (autoVirtual.value) {
|
|
281
|
+
const visibleCount = props.height / props.itemHeight;
|
|
282
|
+
const scrollCount = Math.floor(scrollTop / props.itemHeight);
|
|
283
|
+
let start =
|
|
284
|
+
scrollCount < 0
|
|
285
|
+
? 0
|
|
286
|
+
: scrollCount + visibleCount > flatDataValue.length
|
|
287
|
+
? flatDataValue.length - visibleCount
|
|
288
|
+
: scrollCount;
|
|
289
|
+
if (start < 0) {
|
|
290
|
+
start = 0;
|
|
291
|
+
}
|
|
292
|
+
const end = start + visibleCount;
|
|
293
|
+
state.translateY = start * props.itemHeight;
|
|
294
|
+
state.visibleData = flatDataValue.filter(
|
|
295
|
+
(item, index) => index >= start && index < end,
|
|
296
|
+
);
|
|
297
|
+
} else {
|
|
298
|
+
state.visibleData = flatDataValue;
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// 事件处理
|
|
303
|
+
// const handleTreeScroll = (e: ScrollEvent) => {
|
|
304
|
+
// // updateVisibleData(e?.detail?.scrollTop ?? 0);
|
|
305
|
+
// };
|
|
306
|
+
|
|
307
|
+
const handleSelectedChange = ({ path }: NodeDataType) => {
|
|
308
|
+
const type = props.selectableType;
|
|
309
|
+
if (type === 'multiple') {
|
|
310
|
+
const index = selectedPaths.value.findIndex((item) => item === path);
|
|
311
|
+
const newVal = [...selectedPaths.value];
|
|
312
|
+
if (index !== -1) {
|
|
313
|
+
newVal.splice(index, 1);
|
|
314
|
+
} else {
|
|
315
|
+
newVal.push(path);
|
|
316
|
+
}
|
|
317
|
+
emits('update:selectedValue', newVal);
|
|
318
|
+
|
|
319
|
+
emits('selectedChange', newVal, [...selectedPaths.value]);
|
|
320
|
+
} else if (type === 'single') {
|
|
321
|
+
if (selectedPaths.value[0] !== path) {
|
|
322
|
+
const [oldVal] = selectedPaths.value;
|
|
323
|
+
const newVal = path;
|
|
324
|
+
emits('update:selectedValue', newVal);
|
|
325
|
+
emits('selectedChange', newVal, oldVal);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
const handleNodeClick = (node: NodeDataType) => {
|
|
331
|
+
emits('nodeClick', node);
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
const handleNodeMouseover = (node: NodeDataType) => {
|
|
335
|
+
emits('nodeMouseover', node);
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
const updateCollapsedPaths = (collapsed: boolean, path: string) => {
|
|
339
|
+
if (collapsed) {
|
|
340
|
+
state.hiddenPaths = {
|
|
341
|
+
...state.hiddenPaths,
|
|
342
|
+
[path]: 1,
|
|
343
|
+
};
|
|
344
|
+
} else {
|
|
345
|
+
const newPaths = { ...state.hiddenPaths };
|
|
346
|
+
delete newPaths[path];
|
|
347
|
+
state.hiddenPaths = newPaths;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (path === props.rootPath) {
|
|
351
|
+
state.height = collapsed ? props.itemHeight : props.height;
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
const handleBracketsClick = (collapsed: boolean, node: NodeDataType) => {
|
|
356
|
+
if (props.collapsedOnClickBrackets) {
|
|
357
|
+
updateCollapsedPaths(collapsed, node.path);
|
|
358
|
+
}
|
|
359
|
+
emits('bracketsClick', collapsed, node);
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
const handleIconClick = (collapsed: boolean, node: NodeDataType) => {
|
|
363
|
+
updateCollapsedPaths(collapsed, node.path);
|
|
364
|
+
emits('iconClick', collapsed, node);
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
const handleValueChange = (value: unknown, path: string) => {
|
|
368
|
+
const newData = cloneDeep(props.data);
|
|
369
|
+
const rootPath = props.rootPath;
|
|
370
|
+
const key = path.slice(rootPath.length);
|
|
371
|
+
setValueByPath(newData, key, value);
|
|
372
|
+
emits('update:data', newData);
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
// 监听和副作用
|
|
376
|
+
watchEffect(() => {
|
|
377
|
+
if (propsErrorMessage.value) {
|
|
378
|
+
emitError(propsErrorMessage.value);
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
// watchEffect(() => {
|
|
383
|
+
// if (flatData.value) {
|
|
384
|
+
// // updateVisibleData();
|
|
385
|
+
// }
|
|
386
|
+
// });
|
|
387
|
+
|
|
388
|
+
watch(
|
|
389
|
+
() => props.deep,
|
|
390
|
+
(val) => {
|
|
391
|
+
if (val)
|
|
392
|
+
state.hiddenPaths = initHiddenPaths(val, props.collapsedNodeLength);
|
|
393
|
+
},
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
watch(
|
|
397
|
+
() => props.collapsedNodeLength,
|
|
398
|
+
(val) => {
|
|
399
|
+
if (val) state.hiddenPaths = initHiddenPaths(props.deep, val);
|
|
400
|
+
},
|
|
401
|
+
);
|
|
402
|
+
|
|
403
|
+
// 监听是否折叠,默认不折叠
|
|
404
|
+
watch(
|
|
405
|
+
() => props.collapsed,
|
|
406
|
+
(val) => {
|
|
407
|
+
if (val) {
|
|
408
|
+
updateCollapsedPaths(true, props.rootPath);
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
immediate: true,
|
|
413
|
+
},
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
// 生命周期钩子
|
|
417
|
+
onMounted(() => {
|
|
418
|
+
// updateVisibleData();
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
onUpdated(() => {
|
|
422
|
+
// 可选的更新后操作
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
onUnmounted(() => {
|
|
426
|
+
// 清理操作
|
|
427
|
+
});
|
|
428
|
+
</script>
|
|
429
|
+
|
|
430
|
+
<style>
|
|
431
|
+
.json-pretty-tree {
|
|
432
|
+
/* theme color */
|
|
433
|
+
--json-pretty-color-primary: #9254de;
|
|
434
|
+
--json-pretty-color-info: #1d8ce0;
|
|
435
|
+
--json-pretty-color-error: #ff4d4f;
|
|
436
|
+
--json-pretty-color-success: #888888;
|
|
437
|
+
--json-pretty-color-nil: #020201;
|
|
438
|
+
|
|
439
|
+
/* field values color */
|
|
440
|
+
--json-pretty-color-string: var(--json-pretty-color-success);
|
|
441
|
+
--json-pretty-color-number: var(--json-pretty-color-info);
|
|
442
|
+
--json-pretty-color-boolean: var(--json-pretty-color-info);
|
|
443
|
+
--json-pretty-color-null: var(--json-pretty-color-nil);
|
|
444
|
+
--json-pretty-color-undefined: var(--json-pretty-color-nil);
|
|
445
|
+
|
|
446
|
+
/* highlight */
|
|
447
|
+
--json-pretty-highlight-bg-color: rgba(146, 84, 222, 0.1);
|
|
448
|
+
--json-pretty-highlight-bg-color-dark: #2e4558;
|
|
449
|
+
|
|
450
|
+
/* comment */
|
|
451
|
+
--json-pretty-comment-color: #bfcbd9;
|
|
452
|
+
|
|
453
|
+
/* common border-color */
|
|
454
|
+
--json-pretty-border-color: #bfcbd9;
|
|
455
|
+
|
|
456
|
+
font-family:
|
|
457
|
+
'Monaco', 'Menlo', 'Consolas', 'Bitstream Vera Sans Mono', monospace;
|
|
458
|
+
font-size: v-bind(fontSize);
|
|
459
|
+
text-align: left;
|
|
460
|
+
overflow: auto;
|
|
461
|
+
position: relative;
|
|
462
|
+
width: 100%;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
.json-pretty-tree.is-virtual {
|
|
466
|
+
overflow: auto;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
.json-pretty-tree-node {
|
|
470
|
+
white-space: nowrap;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
.dark {
|
|
474
|
+
/* 深色主题样式 */
|
|
475
|
+
}
|
|
476
|
+
</style>
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { CSSProperties } from 'vue';
|
|
2
|
+
|
|
3
|
+
export type JsonPrettyNodeProps = {
|
|
4
|
+
data: any;
|
|
5
|
+
rootPath: string;
|
|
6
|
+
indent: number;
|
|
7
|
+
showLength: boolean;
|
|
8
|
+
showDoubleQuotes: boolean;
|
|
9
|
+
renderNodeKey: any;
|
|
10
|
+
renderNodeValue: any;
|
|
11
|
+
};
|
|
12
|
+
export interface NodeDataType extends JSONFlattenReturnType {
|
|
13
|
+
id: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface JSONFlattenOptions {
|
|
17
|
+
key?: string;
|
|
18
|
+
index?: number;
|
|
19
|
+
showComma: boolean;
|
|
20
|
+
length: number;
|
|
21
|
+
type:
|
|
22
|
+
| 'content'
|
|
23
|
+
| 'objectStart'
|
|
24
|
+
| 'objectEnd'
|
|
25
|
+
| 'objectCollapsed'
|
|
26
|
+
| 'arrayStart'
|
|
27
|
+
| 'arrayEnd'
|
|
28
|
+
| 'arrayCollapsed';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type JSONDataType =
|
|
32
|
+
| string
|
|
33
|
+
| number
|
|
34
|
+
| boolean
|
|
35
|
+
| unknown[]
|
|
36
|
+
| Record<string, unknown>
|
|
37
|
+
| null;
|
|
38
|
+
|
|
39
|
+
export interface JSONFlattenReturnType extends JSONFlattenOptions {
|
|
40
|
+
content: string | number | null | boolean;
|
|
41
|
+
level: number;
|
|
42
|
+
path: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type StyleValue =
|
|
46
|
+
| false
|
|
47
|
+
| null
|
|
48
|
+
| undefined
|
|
49
|
+
| string
|
|
50
|
+
| CSSProperties
|
|
51
|
+
| Array<StyleValue>;
|
|
52
|
+
|
|
53
|
+
// 定义 Props 类型
|
|
54
|
+
type SelectableType = 'single' | 'multiple' | null;
|
|
55
|
+
|
|
56
|
+
export type TreeNodeProps = Partial<{
|
|
57
|
+
data: any;
|
|
58
|
+
indent: number;
|
|
59
|
+
showLength: boolean;
|
|
60
|
+
showDoubleQuotes: boolean;
|
|
61
|
+
selectableType: SelectableType;
|
|
62
|
+
showSelectController: boolean;
|
|
63
|
+
showLine: boolean;
|
|
64
|
+
showLineNumber: boolean;
|
|
65
|
+
showNodeActions: boolean;
|
|
66
|
+
selectOnClickNode: boolean;
|
|
67
|
+
highlightSelectedNode: boolean;
|
|
68
|
+
showIcon: boolean;
|
|
69
|
+
theme: string;
|
|
70
|
+
showKeyValueSpace: boolean;
|
|
71
|
+
editable: boolean;
|
|
72
|
+
editableTrigger: string;
|
|
73
|
+
node: NodeDataType;
|
|
74
|
+
checked: boolean;
|
|
75
|
+
collapsed: boolean;
|
|
76
|
+
style: CSSProperties;
|
|
77
|
+
fontSize: string;
|
|
78
|
+
onNodeClick: (node: NodeDataType) => void;
|
|
79
|
+
onNodeMouseover: (node: NodeDataType) => void;
|
|
80
|
+
onBracketsClick: (collapsed: boolean, node: NodeDataType) => void;
|
|
81
|
+
onIconClick: (collapsed: boolean, node: NodeDataType) => void;
|
|
82
|
+
onValueChange: (value: boolean, path: string) => void;
|
|
83
|
+
onSelectedChange: (node: NodeDataType) => void;
|
|
84
|
+
}> &
|
|
85
|
+
TreeNodeRequiredProps;
|
|
86
|
+
|
|
87
|
+
export type TreeNodeRequiredProps = {
|
|
88
|
+
node: NodeDataType;
|
|
89
|
+
rootPath: string;
|
|
90
|
+
nodeSelectable: (node: NodeDataType) => boolean;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export type TreeRequired = TreeNodeRequiredProps & {};
|
|
94
|
+
|
|
95
|
+
export type Tree = Partial<TreeNodeProps> &
|
|
96
|
+
Partial<
|
|
97
|
+
{
|
|
98
|
+
deep: number;
|
|
99
|
+
collapsedNodeLength: number;
|
|
100
|
+
virtual: boolean;
|
|
101
|
+
itemHeight: number;
|
|
102
|
+
height: number;
|
|
103
|
+
selectedValue: string | Array<any>;
|
|
104
|
+
collapsedOnClickBrackets: boolean;
|
|
105
|
+
style: CSSProperties;
|
|
106
|
+
pathCollapsible: (node: NodeDataType) => boolean;
|
|
107
|
+
/** 超过行数将会自动启用虚拟列表 */
|
|
108
|
+
autoVirtualRow: number;
|
|
109
|
+
} & TreeRequired
|
|
110
|
+
>;
|
|
111
|
+
|
|
112
|
+
export interface ScrollEvent {
|
|
113
|
+
detail: {
|
|
114
|
+
scrollLeft: number; // 横向滚动距离
|
|
115
|
+
scrollTop: number; // 纵向滚动距离
|
|
116
|
+
scrollHeight: number; // 可滚动区域的高度
|
|
117
|
+
scrollWidth: number; // 可滚动区域的宽度
|
|
118
|
+
deltaX: number; // 横向滚动增量
|
|
119
|
+
deltaY: number; // 纵向滚动增量
|
|
120
|
+
};
|
|
121
|
+
target: EventTarget; // 事件源组件
|
|
122
|
+
currentTarget: EventTarget; // 当前组件
|
|
123
|
+
timeStamp: number; // 事件触发时间戳
|
|
124
|
+
type: string; // 事件类型,这里是 'scroll'
|
|
125
|
+
}
|