vite-uni-dev-tool 0.0.13 → 0.0.15

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 (130) hide show
  1. package/dist/core.js +1 -1
  2. package/dist/devIntercept/index.d.ts +3 -3
  3. package/dist/devIntercept/index.d.ts.map +1 -1
  4. package/dist/devIntercept/index.js +117 -114
  5. package/dist/plugins/uniDevTool/transform/transformApp.d.ts +32 -0
  6. package/dist/plugins/uniDevTool/transform/transformApp.d.ts.map +1 -0
  7. package/dist/plugins/uniDevTool/transform/transformApp.js +32 -0
  8. package/dist/plugins/uniDevTool/transform/transformMain.d.ts +26 -0
  9. package/dist/plugins/uniDevTool/transform/transformMain.d.ts.map +1 -0
  10. package/dist/plugins/uniDevTool/transform/transformMain.js +3 -0
  11. package/dist/plugins/uniDevTool/transform/transformVue.d.ts +41 -0
  12. package/dist/plugins/uniDevTool/transform/transformVue.d.ts.map +1 -0
  13. package/dist/plugins/uniDevTool/transform/transformVue.js +9 -0
  14. package/dist/plugins/uniDevTool/uniDevTool.d.ts +7 -3
  15. package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +1 -1
  16. package/dist/plugins/uniDevTool/uniDevTool.js +3 -33
  17. package/dist/plugins/utils/index.d.ts +32 -0
  18. package/dist/plugins/utils/index.d.ts.map +1 -1
  19. package/dist/plugins/utils/index.js +1 -1
  20. package/dist/type.d.ts +2 -2
  21. package/dist/type.d.ts.map +1 -1
  22. package/dist/v2/AppInfo/index.vue +41 -0
  23. package/dist/v2/AutoSizer/index.vue +189 -0
  24. package/dist/v2/AutoSizer/index1.vue +193 -0
  25. package/dist/v2/AutoSizer/utils.ts +49 -0
  26. package/dist/v2/CaptureScreen/index.vue +78 -0
  27. package/dist/v2/CloseButton/index.vue +32 -0
  28. package/dist/v2/Connection/index.vue +94 -0
  29. package/dist/v2/ConsoleList/ConsoleItem.vue +235 -0
  30. package/dist/v2/ConsoleList/RunJSInput.vue +243 -0
  31. package/dist/v2/ConsoleList/index.vue +164 -0
  32. package/dist/v2/ConsoleList/staticTips.js +1144 -0
  33. package/dist/v2/DevTool/index.vue +162 -0
  34. package/dist/v2/DevToolButton/index.vue +228 -0
  35. package/dist/v2/DevToolTitle/index.vue +28 -0
  36. package/dist/v2/DevToolWindow/index.vue +1051 -0
  37. package/dist/v2/DeviceInfo/index.vue +48 -0
  38. package/dist/v2/Empty/empty.png +0 -0
  39. package/dist/v2/Empty/index.vue +40 -0
  40. package/dist/v2/FilterInput/index.vue +100 -0
  41. package/dist/v2/JsonPretty/components/Brackets/index.vue +30 -0
  42. package/dist/v2/JsonPretty/components/Carets/index.vue +65 -0
  43. package/dist/v2/JsonPretty/components/CheckController/index.vue +127 -0
  44. package/dist/v2/JsonPretty/components/TreeNode/index.vue +417 -0
  45. package/dist/v2/JsonPretty/hooks/useClipboard.ts +21 -0
  46. package/dist/v2/JsonPretty/hooks/useError.ts +21 -0
  47. package/dist/v2/JsonPretty/index.vue +531 -0
  48. package/dist/v2/JsonPretty/type.ts +125 -0
  49. package/dist/v2/JsonPretty/utils/index.js +211 -0
  50. package/dist/v2/NetworkList/NetworkDetail.vue +215 -0
  51. package/dist/v2/NetworkList/NetworkItem.vue +135 -0
  52. package/dist/v2/NetworkList/index.vue +148 -0
  53. package/dist/v2/PiniaList/index.vue +79 -0
  54. package/dist/v2/RouteList/index.vue +137 -0
  55. package/dist/v2/RunJS/index.vue +128 -0
  56. package/dist/v2/SettingList/index.vue +318 -0
  57. package/dist/v2/SourceCode/index.vue +237 -0
  58. package/dist/v2/StorageList/index.vue +165 -0
  59. package/dist/v2/SystemInfo/index.vue +49 -0
  60. package/dist/v2/Tabs/index.vue +127 -0
  61. package/dist/v2/Tag/index.vue +91 -0
  62. package/dist/v2/UniEvent/UniEventItem.vue +157 -0
  63. package/dist/v2/UniEvent/index.vue +127 -0
  64. package/dist/v2/UploadList/UploadDetail.vue +204 -0
  65. package/dist/v2/UploadList/UploadItem.vue +134 -0
  66. package/dist/v2/UploadList/index.vue +143 -0
  67. package/dist/v2/VirtualList/index.vue +140 -0
  68. package/dist/v2/VirtualListPro/AutoSize.vue +50 -0
  69. package/dist/v2/VirtualListPro/index.vue +255 -0
  70. package/dist/v2/VirtualListPro/readme.md +40 -0
  71. package/dist/v2/VuexList/index.vue +80 -0
  72. package/dist/v2/WebSocket/WebSocketItem.vue +129 -0
  73. package/dist/v2/WebSocket/WebSocketList.vue +183 -0
  74. package/dist/v2/WebSocket/index.vue +155 -0
  75. package/dist/v2/WindowInfo/index.vue +49 -0
  76. package/dist/v3/AppInfo/index.vue +35 -0
  77. package/dist/v3/AutoSizer/index.vue +193 -0
  78. package/dist/v3/AutoSizer/index1.vue +186 -0
  79. package/dist/v3/AutoSizer/utils.ts +49 -0
  80. package/dist/v3/CaptureScreen/index.vue +62 -0
  81. package/dist/v3/CloseButton/index.vue +29 -0
  82. package/dist/v3/Connection/index.vue +88 -0
  83. package/dist/v3/ConsoleList/ConsoleItem.vue +208 -0
  84. package/dist/v3/ConsoleList/RunJSInput.vue +240 -0
  85. package/dist/v3/ConsoleList/index.vue +139 -0
  86. package/dist/v3/ConsoleList/staticTips.ts +1145 -0
  87. package/dist/v3/DevTool/index.vue +217 -0
  88. package/dist/v3/DevToolButton/index.vue +210 -0
  89. package/dist/v3/DevToolTitle/index.vue +21 -0
  90. package/dist/v3/DevToolWindow/index.vue +1116 -0
  91. package/dist/v3/DeviceInfo/index.vue +32 -0
  92. package/dist/v3/Empty/empty.png +0 -0
  93. package/dist/v3/Empty/index.vue +28 -0
  94. package/dist/v3/FilterInput/index.vue +87 -0
  95. package/dist/v3/JsonPretty/components/Brackets/index.vue +23 -0
  96. package/dist/v3/JsonPretty/components/Carets/index.vue +59 -0
  97. package/dist/v3/JsonPretty/components/CheckController/index.vue +125 -0
  98. package/dist/v3/JsonPretty/components/TreeNode/index.vue +349 -0
  99. package/dist/v3/JsonPretty/hooks/useClipboard.ts +21 -0
  100. package/dist/v3/JsonPretty/hooks/useError.ts +21 -0
  101. package/dist/v3/JsonPretty/index.vue +476 -0
  102. package/dist/v3/JsonPretty/type.ts +125 -0
  103. package/dist/v3/JsonPretty/utils/index.ts +172 -0
  104. package/dist/v3/NetworkList/NetworkDetail.vue +194 -0
  105. package/dist/v3/NetworkList/NetworkItem.vue +120 -0
  106. package/dist/v3/NetworkList/index.vue +128 -0
  107. package/dist/v3/PiniaList/index.vue +64 -0
  108. package/dist/v3/RouteList/index.vue +121 -0
  109. package/dist/v3/RunJS/index.vue +128 -0
  110. package/dist/v3/SettingList/index.vue +313 -0
  111. package/dist/v3/SourceCode/index.vue +231 -0
  112. package/dist/v3/StorageList/index.vue +170 -0
  113. package/dist/v3/SystemInfo/index.vue +34 -0
  114. package/dist/v3/Tabs/index.vue +123 -0
  115. package/dist/v3/Tag/index.vue +89 -0
  116. package/dist/v3/UniEvent/UniEventItem.vue +126 -0
  117. package/dist/v3/UniEvent/index.vue +98 -0
  118. package/dist/v3/UploadList/UploadDetail.vue +192 -0
  119. package/dist/v3/UploadList/UploadItem.vue +117 -0
  120. package/dist/v3/UploadList/index.vue +117 -0
  121. package/dist/v3/VirtualList/index.vue +112 -0
  122. package/dist/v3/VirtualListPro/AutoSize.vue +43 -0
  123. package/dist/v3/VirtualListPro/index.vue +238 -0
  124. package/dist/v3/VirtualListPro/readme.md +40 -0
  125. package/dist/v3/VuexList/index.vue +54 -0
  126. package/dist/v3/WebSocket/WebSocketItem.vue +103 -0
  127. package/dist/v3/WebSocket/WebSocketList.vue +161 -0
  128. package/dist/v3/WebSocket/index.vue +124 -0
  129. package/dist/v3/WindowInfo/index.vue +33 -0
  130. package/package.json +1 -1
@@ -0,0 +1,112 @@
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>
@@ -0,0 +1,43 @@
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>
@@ -0,0 +1,238 @@
1
+ <template>
2
+ <scroll-view
3
+ :lower-threshold="preLodeHeight"
4
+ :scroll-with-animation="scrollWithAnimation"
5
+ :class="['virtual-list', className]"
6
+ :style="style"
7
+ :scroll-into-view="innerScrollIntoView"
8
+ scroll-y
9
+ @scroll="onScroll"
10
+ @scrolltolower="onScrollToLower"
11
+ >
12
+ <!-- 阈值判断 -->
13
+ <view
14
+ :id="placeholderId"
15
+ :style="{ height: `${state.currentHeight}px` }"
16
+ ></view>
17
+ <view>
18
+ <!-- 将可视数据传入到slot -->
19
+ <slot
20
+ :list="state.visitableData"
21
+ :current="state.current"
22
+ :start="(state.current - 1) * props.pageSize"
23
+ ></slot>
24
+ </view>
25
+
26
+ <view
27
+ v-if="state.currentHeight > props.height && showBackTop"
28
+ class="virtual-back-top"
29
+ @click="onBackTop"
30
+ >
31
+
32
+ </view>
33
+ </scroll-view>
34
+ </template>
35
+ <script lang="ts" setup>
36
+ import { nextTick } from 'vue';
37
+ import { uniqueId } from '../../utils';
38
+ import { reactive, watch, onBeforeMount, provide, computed, ref } from 'vue';
39
+
40
+ const props = withDefaults(
41
+ defineProps<{
42
+ /** 渲染数据 */
43
+ data: any[];
44
+ /** 虚拟列表高度 */
45
+ height?: number;
46
+ /**
47
+ * 将对传入的data进行分页
48
+ * 如何获取pageSize?
49
+ * 虚拟列表高度 / 预估每条的最小高度 +
50
+ */
51
+ pageSize?: number;
52
+ /** 预加载高度 */
53
+ preLodeHeight?: number;
54
+ /** 类名 */
55
+ className?: string;
56
+ /** 滚动到指定元素 */
57
+ scrollIntoView?: string;
58
+ /** 滚动动画 */
59
+ scrollWithAnimation?: boolean;
60
+ /** 返回顶部 */
61
+ showBackTop?: boolean;
62
+ }>(),
63
+ {
64
+ height: 400,
65
+ pageSize: 10,
66
+ preLodeHeight: 50,
67
+ },
68
+ );
69
+
70
+ const state = reactive<{
71
+ /** 加载次数 */
72
+ current: number;
73
+ visitableData: any[];
74
+ currentHeight: number;
75
+ height: number;
76
+ scrollTop: number;
77
+ }>({
78
+ height: 0,
79
+ current: 1,
80
+ visitableData: [],
81
+ currentHeight: 0,
82
+ scrollTop: 0,
83
+ });
84
+
85
+ const placeholderId = uniqueId('virtual-placeholder-');
86
+
87
+ /**
88
+ * 每一项的高度
89
+ */
90
+ const itemsHeight: number[] = [];
91
+
92
+ provide('itemsHeight', itemsHeight);
93
+
94
+ const style = computed(() => {
95
+ return {
96
+ height:
97
+ typeof props.height === 'string' ? props.height : props.height + 'px',
98
+ };
99
+ });
100
+
101
+ const toView = ref('');
102
+
103
+ const innerScrollIntoView = computed(() => {
104
+ return toView.value || props.scrollIntoView;
105
+ });
106
+
107
+ onBeforeMount(() => {
108
+ // 初始渲染数据
109
+ state.visitableData = props.data.slice(0, props.pageSize * 2);
110
+ });
111
+
112
+ // 数据更新时重置
113
+ watch(
114
+ () => [props.data, props.pageSize],
115
+ () => {
116
+ state.visitableData = props.data.slice(0, props.pageSize * 2);
117
+ },
118
+ );
119
+
120
+ /** 向上滚动和向下滚动 */
121
+ function updateVisitableData(direction: 'up' | 'down') {
122
+ let tempList = [...state.visitableData];
123
+
124
+ if (direction === 'down') {
125
+ // 将最前面的内容进行隐藏
126
+ tempList.splice(0, props.pageSize);
127
+
128
+ // 处理下一页内容
129
+ const start = props.pageSize * state.current;
130
+ let end = props.pageSize * (state.current + 1);
131
+
132
+ if (start >= props.data.length) {
133
+ return;
134
+ }
135
+
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;
166
+ }
167
+
168
+ /** 计算合并的高度 */
169
+ function updateCurrentHeight() {
170
+ const total = itemsHeight
171
+ .slice(0, state.current * props.pageSize)
172
+ ?.reduce((acc, cur) => acc + cur, 0);
173
+
174
+ state.currentHeight = total;
175
+ }
176
+
177
+ /** 滚动到底部 */
178
+ function onScrollToLower() {
179
+ if ((state.current + 1) * props.pageSize < props.data.length) {
180
+ state.current++;
181
+
182
+ updateVisitableData('down');
183
+
184
+ updateCurrentHeight();
185
+ }
186
+ }
187
+
188
+ /** 滚动监听,是否小于合并高度 */
189
+ function onScroll(e: { detail: { scrollTop: number } }) {
190
+ if (
191
+ state.current > 0 &&
192
+ state.currentHeight > 0 &&
193
+ e.detail.scrollTop - props.preLodeHeight < state.currentHeight
194
+ ) {
195
+ state.current--;
196
+
197
+ updateVisitableData('up');
198
+
199
+ updateCurrentHeight();
200
+ }
201
+ }
202
+
203
+ /** 暴露给子组件获取子组件容器的高度 */
204
+ function onSizeChange(index: number, height: number) {
205
+ itemsHeight[index] = height;
206
+ }
207
+ provide('onSizeChange', onSizeChange);
208
+
209
+ /** 返回顶部 */
210
+ function onBackTop() {
211
+ toView.value = placeholderId;
212
+
213
+ nextTick(() => {
214
+ state.current = 1;
215
+ state.currentHeight = 0;
216
+ updateVisitableData('up');
217
+
218
+ toView.value = '';
219
+ });
220
+ }
221
+ </script>
222
+ <style scoped>
223
+ .virtual-list {
224
+ position: relative;
225
+ }
226
+
227
+ .virtual-back-top {
228
+ position: sticky;
229
+ bottom: 20px;
230
+ left: 80%;
231
+ display: flex;
232
+ align-items: center;
233
+ justify-content: center;
234
+ width: 40px;
235
+ height: 40px;
236
+ box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
237
+ }
238
+ </style>
@@ -0,0 +1,40 @@
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]
@@ -0,0 +1,54 @@
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 } 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>
@@ -0,0 +1,103 @@
1
+ <template>
2
+ <view class="websocket-item">
3
+ <view class="websocket-url-row">
4
+ <Tag mode="info" v-if="ws.readyState === 'connection'">con</Tag>
5
+ <Tag mode="success" v-if="ws.readyState === 'open'">open</Tag>
6
+ <Tag
7
+ mode="warn"
8
+ v-if="ws.readyState === 'closing' || ws.readyState === 'closed'"
9
+ >
10
+ close
11
+ </Tag>
12
+
13
+ <Tag mode="error" v-if="ws.readyState === 'error'">error</Tag>
14
+
15
+ <view class="websocket-url" v-html="ws.url" />
16
+
17
+ <Tag
18
+ mode="main"
19
+ class="websocket-detail-icon"
20
+ @click="showDetail = !showDetail"
21
+ >
22
+ 详情
23
+ </Tag>
24
+ </view>
25
+ <view class="websocket-info">
26
+ <view class="websocket-info-last">
27
+ {{ ws?.message?.[ws.message.length - 1]?.data }}
28
+ </view>
29
+
30
+ <view>{{
31
+ ws?.message?.[ws.message.length - 1].time
32
+ ? formatDate(ws?.message?.[ws.message.length - 1].time, 'HH:mm:ss')
33
+ : '-'
34
+ }}</view>
35
+ </view>
36
+
37
+ <WebSocketList
38
+ v-if="showDetail"
39
+ :ws="ws"
40
+ :zIndex="zIndex"
41
+ @close="onClose"
42
+ />
43
+ </view>
44
+ </template>
45
+ <script lang="ts" setup>
46
+ import { ref } from 'vue';
47
+
48
+ import Tag from '../Tag/index.vue';
49
+ import WebSocketList from './WebSocketList.vue';
50
+ import { formatDate } from '../../utils';
51
+ import type { DevTool } from '../../type';
52
+
53
+ defineProps<{ ws: DevTool.WS; zIndex?: number }>();
54
+ const showDetail = ref(false);
55
+
56
+ function onClose() {
57
+ showDetail.value = false;
58
+ }
59
+ </script>
60
+ <style scoped>
61
+ .websocket-item {
62
+ padding: 16px;
63
+
64
+ box-sizing: border-box;
65
+ border-bottom: 1px solid var(--dev-tool-border-color);
66
+ font-size: var(--dev-tool-base-font-size);
67
+ }
68
+ .websocket-item .websocket-url-row {
69
+ display: flex;
70
+ align-items: center;
71
+ word-break: break-all;
72
+ }
73
+
74
+ .websocket-item .websocket-url-row .websocket-url {
75
+ margin-left: 4px;
76
+ flex: 1;
77
+ white-space: nowrap;
78
+ overflow: hidden;
79
+ text-overflow: ellipsis;
80
+ }
81
+
82
+ .websocket-item .websocket-url-row .websocket-detail-icon {
83
+ flex-shrink: 0;
84
+ margin-left: auto;
85
+ }
86
+ .websocket-item .websocket-url-row .websocket-detail-active {
87
+ transform: rotate(135deg);
88
+ }
89
+ .websocket-item .websocket-info {
90
+ display: flex;
91
+ align-items: center;
92
+ justify-content: space-between;
93
+ margin-top: 4px;
94
+ color: var(--dev-tool-info-color);
95
+ }
96
+
97
+ .websocket-item .websocket-info .websocket-info-last {
98
+ white-space: nowrap;
99
+ flex: 1;
100
+ overflow: hidden;
101
+ text-overflow: ellipsis;
102
+ }
103
+ </style>