uni-oaview 1.9.14 → 1.9.16

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.
@@ -1,5 +1,4 @@
1
1
  <template>
2
- <oa-vconsole v-if="showLog" />
3
2
  <view class="oa-page" :style="{ height: windowHeight }" @click="clickHandler">
4
3
  <NetworkError />
5
4
  <slot />
@@ -0,0 +1,104 @@
1
+ export interface NativeEventLog {
2
+ key: string;
3
+ params: unknown;
4
+ response: unknown;
5
+ startTime: number;
6
+ endTime: number;
7
+ }
8
+
9
+ export interface NativeEventLogMeta {
10
+ id: string;
11
+ key: string;
12
+ title: string;
13
+ }
14
+
15
+ export interface NativeEventState {
16
+ detailMap: Map<string, NativeEventLog>;
17
+ metas: NativeEventLogMeta[];
18
+ expandedIds: Set<string>;
19
+ }
20
+
21
+ export interface NativeEventIdStore {
22
+ ids: WeakMap<NativeEventLog, string>;
23
+ nextId: number;
24
+ }
25
+
26
+ export const MAX_NATIVE_EVENT_LOGS = 200;
27
+
28
+ export const createNativeEventIdStore = (): NativeEventIdStore => {
29
+ return {
30
+ ids: new WeakMap<NativeEventLog, string>(),
31
+ nextId: 0,
32
+ };
33
+ };
34
+
35
+ export const buildNativeEventLogId = (log: NativeEventLog): string => {
36
+ return `${log.startTime}|${log.endTime}|${log.key}`;
37
+ };
38
+
39
+ const getStableNativeEventLogId = (log: NativeEventLog, idStore?: NativeEventIdStore): string => {
40
+ if (!idStore) {
41
+ return buildNativeEventLogId(log);
42
+ }
43
+
44
+ const cachedId = idStore.ids.get(log);
45
+ if (cachedId) {
46
+ return cachedId;
47
+ }
48
+
49
+ idStore.nextId += 1;
50
+ const nextId = `native-event-${idStore.nextId}`;
51
+ idStore.ids.set(log, nextId);
52
+ return nextId;
53
+ };
54
+
55
+ const formatStartTime = (timestamp: number): string => {
56
+ const date = new Date(timestamp);
57
+ return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}:${String(
58
+ date.getSeconds(),
59
+ ).padStart(2, '0')}`;
60
+ };
61
+
62
+ const getTitle = (log: NativeEventLog): string => {
63
+ const { startTime, endTime, key } = log;
64
+ if (startTime && endTime) {
65
+ return `${formatStartTime(startTime)} ${key};${(endTime - startTime) / 1000}s`;
66
+ }
67
+ return key;
68
+ };
69
+
70
+ const buildMetaFromLog = (log: NativeEventLog, id: string): NativeEventLogMeta => {
71
+ return {
72
+ id,
73
+ key: log.key,
74
+ title: getTitle(log),
75
+ };
76
+ };
77
+
78
+ export const buildNativeEventState = (
79
+ logs: NativeEventLog[],
80
+ expandedIds: Iterable<string>,
81
+ _idStore?: NativeEventIdStore,
82
+ ): NativeEventState => {
83
+ const nextLogs = logs.slice(-MAX_NATIVE_EVENT_LOGS);
84
+ const detailMap = new Map<string, NativeEventLog>();
85
+ const metas = nextLogs.map((log) => {
86
+ const id = getStableNativeEventLogId(log, _idStore);
87
+ detailMap.set(id, log);
88
+ return buildMetaFromLog(log, id);
89
+ });
90
+ const keepIds = new Set(metas.map((meta) => meta.id));
91
+ const nextExpandedIds = new Set<string>();
92
+
93
+ for (const id of expandedIds) {
94
+ if (keepIds.has(id)) {
95
+ nextExpandedIds.add(id);
96
+ }
97
+ }
98
+
99
+ return {
100
+ detailMap,
101
+ metas,
102
+ expandedIds: nextExpandedIds,
103
+ };
104
+ };
@@ -38,24 +38,14 @@
38
38
  <script lang="ts" setup>
39
39
  import { computed, onBeforeUnmount, ref, shallowRef } from 'vue';
40
40
  import awesomeDisplayInfo from './awesome-display-info.vue';
41
+ import {
42
+ buildNativeEventState,
43
+ createNativeEventIdStore,
44
+ type NativeEventLog,
45
+ type NativeEventLogMeta,
46
+ } from './native-event-state';
41
47
  import { stringifyForSearch } from './utils';
42
48
  import { nativeEventSubject, getNativeEventLogs } from 'uniapp-log-sdk';
43
-
44
- interface NativeEventLog {
45
- key: string;
46
- params: unknown;
47
- response: unknown;
48
- startTime: number;
49
- endTime: number;
50
- }
51
-
52
- interface NativeEventLogMeta {
53
- id: string;
54
- key: string;
55
- title: string;
56
- }
57
-
58
- const MAX_NATIVE_EVENT_LOGS = 200;
59
49
  const FLUSH_DELAY_FOREGROUND = 16;
60
50
  const FLUSH_DELAY_BACKGROUND = 100;
61
51
  const MAX_EXPANDED_ITEMS = 20; // 限制最大展开项数
@@ -71,38 +61,12 @@
71
61
 
72
62
  let flushTimer: ReturnType<typeof setTimeout> | null = null;
73
63
  let pendingLogs: NativeEventLog[] | null = null;
64
+ const nativeEventIdStore = createNativeEventIdStore();
74
65
 
75
66
  // 订阅和监听器取消函数
76
67
  let unsubscribeLogs: (() => void) | null = null;
77
68
  const cleanupFunctions: (() => void)[] = [];
78
69
 
79
- const buildNativeEventLogId = (log: NativeEventLog): string => {
80
- return `${log.startTime}|${log.endTime}|${log.key}`;
81
- };
82
-
83
- const formatStartTime = (timestamp: number): string => {
84
- const date = new Date(timestamp);
85
- return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}:${String(
86
- date.getSeconds(),
87
- ).padStart(2, '0')}`;
88
- };
89
-
90
- const getTitle = (log: NativeEventLog): string => {
91
- const { startTime, endTime, key } = log;
92
- if (startTime && endTime) {
93
- return `${formatStartTime(startTime)} ${key};${(endTime - startTime) / 1000}s`;
94
- }
95
- return key;
96
- };
97
-
98
- const buildMetaFromLog = (log: NativeEventLog): NativeEventLogMeta => {
99
- return {
100
- id: buildNativeEventLogId(log),
101
- key: log.key,
102
- title: getTitle(log),
103
- };
104
- };
105
-
106
70
  const isExpanded = (id: string): boolean => expandedIds.value.has(id);
107
71
 
108
72
  const toggleExpand = (id: string): void => {
@@ -188,34 +152,10 @@
188
152
  return;
189
153
  }
190
154
 
191
- const nextLogs = visibleLogs.slice(-MAX_NATIVE_EVENT_LOGS);
192
- const detailMap = nativeEventDetailMap.value;
193
-
194
- const nextMetas: NativeEventLogMeta[] = [];
195
- for (const log of nextLogs) {
196
- const id = buildNativeEventLogId(log);
197
- detailMap.set(id, log);
198
- nextMetas.push(buildMetaFromLog(log));
199
- }
200
-
201
- // 创建新的 Map 触发响应式更新
202
- nativeEventDetailMap.value = new Map(detailMap);
203
- nativeEventLogMetas.value = nextMetas;
204
-
205
- // 清理过期的详情数据
206
- const keepIds = new Set(nextMetas.map((m) => m.id));
207
- for (const key of detailMap.keys()) {
208
- if (!keepIds.has(key)) detailMap.delete(key);
209
- }
210
-
211
- // 清理已不存在的展开项
212
- const newExpandedIds = new Set(expandedIds.value);
213
- for (const id of newExpandedIds) {
214
- if (!keepIds.has(id)) {
215
- newExpandedIds.delete(id);
216
- }
217
- }
218
- expandedIds.value = newExpandedIds;
155
+ const nextState = buildNativeEventState(visibleLogs, expandedIds.value, nativeEventIdStore);
156
+ nativeEventDetailMap.value = nextState.detailMap;
157
+ nativeEventLogMetas.value = nextState.metas;
158
+ expandedIds.value = nextState.expandedIds;
219
159
  };
220
160
 
221
161
  const flushPendingLogs = (): void => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uni-oaview",
3
- "version": "1.9.14",
3
+ "version": "1.9.16",
4
4
  "description": "uniapp小程序组件库",
5
5
  "main": "dist/index.esm.js",
6
6
  "typings": "dist/index.d.ts",